def test_all_subclasses_known(self): """ Test that all the subclasses of UpdatingMetadataWrapperBase are known to this test suite. Basically, this will slap us on the wrist in the future if we write more subclasses without writing tests for them. """ self.assertEqual( set(UpdatingMetadataWrapperBase.__subclasses__()), {UpdatingTableMetadataWrapper, UpdatingKeyspaceMetadataWrapper, UpdatingClusterMetadataWrapper} )
def _each_subclass_instantiated_with_mock_args(self): """ This returns an instantiated copy of each subclass of UpdatingMetadataWrapperBase, passing a MagicMock for each argument on initialization. This lets us test properties that should hold for all subclasses. I don't like having tests depend on this weird metaprogramming, but I'd rather have this, which generates tests for any future subclasses, than miss tests for them. """ for klaus in UpdatingMetadataWrapperBase.__subclasses__(): # get length of argument list for class init init_arg_len = len(inspect.getargspec(klaus.__init__)[0]) # args list is one shorter -- argspec includes self init_args = [MagicMock() for _ in range(init_arg_len - 1)] yield klaus(*init_args)