def test_check_first_fail(check_foobar): with pytest.raises(factory.NoMatchingCallable): factory.get_by_standard_layout(BASE_PKG, 'model', search_list=SEARCH_LIST, search_start_value='four', service=SERVICE, check=check_foobar, first_fail=True)
def test_feature_import_error(): # The newest model in this path tries to import something that doesn't # exist, in order to genrerate an ImportError distinct from # a FactoryLookupError. with pytest.raises(ImportError): factory.get_by_standard_layout(BASE_PKG, 'model', search_list=SEARCH_LIST, feature=FEATURE)
def test_other_error(): # Testing an import error from within the imported file is covered above. # We should also allow other sorts of errors to escape unchanged. # TODO: Is this correct or should we convert them to FactoryLookupError? with pytest.raises(SyntaxError): factory.get_by_standard_layout(BASE_PKG, 'action', search_list=SEARCH_LIST, service=SERVICE)
def test_feature_start_after_error_before_expected(): m = factory.get_by_standard_layout(BASE_PKG, 'model', search_list=SEARCH_LIST, search_start_value='two', feature=FEATURE) assert (os.path.join(BASE_PKG, 'features', FEATURE, 'one', 'model.py') in m.__file__)
def test_service_start_on_expected(): # This test also ensures that we don't do an off-by-one indexing error # and skip the starting point. m = factory.get_by_standard_layout(BASE_PKG, 'model', search_list=SEARCH_LIST, search_start_value='two', service=SERVICE) assert (os.path.join(BASE_PKG, 'services', SERVICE, 'two', 'model.py') in m.__file__)
def test_check(check_foobar): # Test to make sure we skip modules when a check is supplied. # In the ss_fake dir, four/model.py has no class, two/model.py has one. m = factory.get_by_standard_layout(BASE_PKG, 'model', search_list=SEARCH_LIST, search_start_value='four', service=SERVICE, check=check_foobar) assert m.__name__ == 'FooBar' assert m.__module__ == '.'.join((BASE_PKG, 'services', SERVICE, 'two', 'model'))
def test_check(check_foobar): # Test to make sure we skip modules when a check is supplied. # In the ss_fake dir, four/model.py has no class, two/model.py has one. m = factory.get_by_standard_layout(BASE_PKG, 'model', search_list=SEARCH_LIST, search_start_value='four', service=SERVICE, check=check_foobar) assert m.__name__ == 'FooBar' assert m.__module__ == '.'.join( (BASE_PKG, 'services', SERVICE, 'two', 'model'))
def test_monolithic_not_found(): with pytest.raises(factory.NoModuleFound): factory.get_by_standard_layout(BASE_PKG, 'weird', search_list=SEARCH_LIST, search_start_value='one')
def test_monolithic(): m = factory.get_by_standard_layout(BASE_PKG, 'weird', search_list=SEARCH_LIST) assert os.path.join(BASE_PKG, 'two', 'weird.py') in m.__file__
def test_unversioned_fail(): with pytest.raises(factory.NoModuleFound): factory.get_by_standard_layout(BASE_PKG, 'doesnotexist')
def test_unversioned(): # This form is used when a higher layer of factory calculates # the base package. m = factory.get_by_standard_layout(BASE_PKG, 'unversioned') assert 'unversioned' in unicode(m)
def test_not_found(): with pytest.raises(factory.NoModuleFound): factory.get_by_standard_layout(BASE_PKG, 'action', search_list=SEARCH_LIST, feature=FEATURE)