~vila/ubuntu-test-cases/retry-apt-get-update

« back to all changes in this revision

Viewing changes to tests/memevent/ubuntu_test_cases/memory_usage_measurement/matchers.py

  • Committer: Leo Arias
  • Date: 2014-11-10 19:28:56 UTC
  • mfrom: (345 touch)
  • mto: This revision was merged to the branch mainline in revision 352.
  • Revision ID: leo.arias@canonical.com-20141110192856-rgpksx9n9j0b39yl
Merged with the touch branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Custom matchers used by the tests."""
 
2
 
 
3
from autopilot.matchers import Eventually as EventuallyMatcher
 
4
from testtools.matchers import Mismatch
 
5
 
 
6
 
 
7
def Eventually(matcher):
 
8
    """Wrapper around autopilot.matchers.Eventually.
 
9
 
 
10
    The aim of the wrapper is just use a different timeout default
 
11
 
 
12
    :param matcher: A testools-like matcher that tests the desired condition
 
13
    :type matcher: object
 
14
    :returns: A value depending on the matcher protocol
 
15
    :rtype: None | a mismatch object with information about the mismatch
 
16
 
 
17
    """
 
18
    return EventuallyMatcher(matcher, timeout=40)
 
19
 
 
20
 
 
21
class DoesNotChange(object):
 
22
    """Match if two consecutive values are equal."""
 
23
    def __init__(self):
 
24
        self.old_value = None
 
25
        self.value = None
 
26
 
 
27
    def __str__(self):
 
28
        return 'DoesNotChange()'
 
29
 
 
30
    def match(self, value):
 
31
        self.old_value = self.value
 
32
        self.value = value
 
33
        if self.value != self.old_value:
 
34
            return Mismatch('Current value ({}) does not match old value ({})'
 
35
                            .format(self.value, self.old_value))
 
36
 
 
37
        return None