1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2012 Canonical
3
# Author: Thomi Richards
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.
9
"Autopilot-specific matchers."
11
from testtools.matchers import Matcher
14
class Eventually(Matcher):
15
"""Asserts that a value will eventually equal a given Matcher object."""
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
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)
31
return "Eventually " + str(self.matcher)