~sil2100/unity/ubuntu_5.14

« back to all changes in this revision

Viewing changes to tests/autopilot/autopilot/matchers/__init__.py

  • Committer: Didier Roche
  • Date: 2012-04-27 11:42:56 UTC
  • mfrom: (55.813.22)
  • Revision ID: didier.roche@canonical.com-20120427114256-26mtuce24s904wo0
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
# Copyright 2012 Canonical
 
3
# Author: Thomi Richards
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify it
 
6
# under the terms of the GNU General Public License version 3, as published
 
7
# by the Free Software Foundation.
 
8
 
 
9
"Autopilot-specific matchers."
 
10
 
 
11
from testtools.matchers import Matcher
 
12
 
 
13
 
 
14
class Eventually(Matcher):
 
15
    """Asserts that a value will eventually equal a given Matcher object."""
 
16
 
 
17
    def __init__(self, matcher):
 
18
        super(Eventually, self).__init__()
 
19
        match_fun = getattr(matcher, 'match', None)
 
20
        if match_fun is None or not callable(match_fun):
 
21
            raise TypeError("Eventually must be called with a testtools matcher argument.")
 
22
        self.matcher = matcher
 
23
 
 
24
    def match(self, value):
 
25
        wait_fun = getattr(value, 'wait_for', None)
 
26
        if wait_fun is None or not callable(wait_fun):
 
27
            raise TypeError("Eventually can only be used against autopilot attributes that have a wait_for funtion.")
 
28
        wait_fun(self.matcher)
 
29
 
 
30
    def __str__(self):
 
31
        return "Eventually " + str(self.matcher)