1if __name__ == "__main__": 2 import sys 3 4 sys.path.insert(0, "..") 5 6import unittest 7 8from hamcrest.core.base_matcher import * 9from hamcrest_unit_test.matcher_test import * 10 11__author__ = "Jon Reid" 12__copyright__ = "Copyright 2011 hamcrest.org" 13__license__ = "BSD, see License.txt" 14 15 16class FailingBaseMatcher(BaseMatcher): 17 def describe_to(self, description): 18 description.append_text("SOME DESCRIPTION") 19 20 def _matches(self, item): 21 return False 22 23 24class PassingBaseMatcher(BaseMatcher): 25 def _matches(self, item): 26 return True 27 28 29class BaseMatcherTest(unittest.TestCase): 30 def testStrFunctionShouldDescribeMatcher(self): 31 matcher = FailingBaseMatcher() 32 self.assertEqual("SOME DESCRIPTION", str(matcher)) 33 34 def testMismatchDescriptionShouldDescribeItem(self): 35 assert_mismatch_description("was <99>", FailingBaseMatcher(), 99) 36 37 def testMatchDescriptionShouldDescribeItem(self): 38 assert_match_description("was <99>", PassingBaseMatcher(), 99) 39 40 41if __name__ == "__main__": 42 unittest.main() 43