def test_weird_class(self): """Meets interface as class, but not as instance. This is strange - not something that would normally ever happen.""" self.assertTrue(meets(WeirdClass, MyInterface)) self.assertFalse(meets(weird, MyInterface)) self.assertFalse(isinstance(weird, MyInterface)) self.assertTrue(issubclass(WeirdClass, MyInterface))
def test_also_class(self): """ AlsoClass does not meet the interface as a class, but does once instantiated. """ self.assertFalse(meets(AlsoClass, MyInterface)) self.assertTrue(meets(also, MyInterface)) self.assertTrue(isinstance(also, MyInterface)) self.assertFalse(issubclass(AlsoClass, MyInterface))
def test_commutative(self): """ AlsoClass does not meet the interface as a class, but does once instantiated. """ self.assertFalse(meets(CommutativeFirst, MyInterface)) self.assertTrue(meets(CommutativeSecond, MyInterface)) self.assertTrue(meets(commutative, MyInterface)) self.assertTrue(isinstance(commutative, MyInterface)) self.assertFalse(issubclass(CommutativeFirst, MyInterface)) self.assertTrue(issubclass(CommutativeSecond, MyInterface)) self.assertRaises(TypeError, CommutativeFails)
def test_meets(self): self.assertTrue(meets(MyValidator, ValidatorInterface)) self.assertTrue(not meets(NotAValidator, ValidatorInterface))
def test_second_child_class(self): """Meets the interface inherited from its parent.""" self.assertTrue(meets(SecondChild, MyInterface)) self.assertTrue(meets(second_child, MyInterface)) self.assertTrue(isinstance(second_child, MyInterface)) self.assertTrue(issubclass(SecondChild, MyInterface))
def test_first_child_class(self): """First child inherits MyInterface, but does not implement it at all - so it can't be implemented.""" self.assertFalse(meets(FirstChild, MyInterface)) self.assertFalse(issubclass(FirstChild, MyInterface)) self.assertRaises(TypeError, FirstChild)
def test_no_class(self): """Does not meet interface.""" self.assertFalse(meets(NoClass, MyInterface)) self.assertFalse(meets(no, MyInterface)) self.assertFalse(isinstance(no, MyInterface)) self.assertFalse(issubclass(NoClass, MyInterface))
def test_yes_class(self): """Meets interface""" self.assertTrue(meets(YesClass, MyInterface)) self.assertTrue(meets(yes, MyInterface)) self.assertTrue(isinstance(yes, MyInterface)) self.assertTrue(issubclass(YesClass, MyInterface))
def test_myinterface_itself(self): self.assertFalse(meets(MyInterface, MyInterface)) self.assertFalse(issubclass(MyInterface, MyInterface)) self.assertRaises(TypeError, MyInterface)