def test_find_namespace(self): """ Application.find_namespace() should return a namespace """ application = Application() application.add(FooCommand()) self.assertEqual( 'foo', application.find_namespace('foo'), msg='.find_namespace() returns the given namespace if it exists' ) self.assertEqual( 'foo', application.find_namespace('f'), msg='.find_namespace() finds a namespace given an abbreviation' ) application.add(Foo2Command()) self.assertEqual( 'foo', application.find_namespace('foo'), msg='.find_namespace() returns the given namespace if it exists' )
def test_find_invalid_namespace(app: Application): app.add(FooCommand()) app.add(Foo2Command()) with pytest.raises( NamespaceNotFoundException, match=r'There are no commands in the "bar" namespace\.', ): app.find_namespace("bar")
def test_find_ambiguous_namespace(app: Application): app.add(FooCommand()) app.add(Foo2Command()) with pytest.raises( NamespaceNotFoundException, match=r'There are no commands in the "f" namespace\.\n\nDid you mean one of these\?\n foo\n foo1', ): app.find_namespace("f")
def test_find_namespace_does_not_fail_on_deep_similar_namespaces(self): applicaton = Application() applicaton.get_namespaces = self.mock().MagicMock(return_value=['foo:sublong', 'bar:sub']) self.assertEqual( 'foo:sublong', applicaton.find_namespace('f:sub') )
def test_find_namespace(self): """ Application.find_namespace() should return a namespace """ application = Application() application.add(FooCommand()) self.assertEqual( "foo", application.find_namespace("foo"), msg=".find_namespace() returns the given namespace if it exists" ) self.assertEqual( "foo", application.find_namespace("f"), msg=".find_namespace() finds a namespace given an abbreviation" ) application.add(Foo2Command()) self.assertEqual( "foo", application.find_namespace("foo"), msg=".find_namespace() returns the given namespace if it exists" )
def test_find_namespace_with_sub_namespaces(app: Application): app.add(FooSubNamespaced1Command()) app.add(FooSubNamespaced2Command()) assert app.find_namespace("foo") == "foo"
def test_find_namespace(app: Application): app.add(FooCommand()) assert app.find_namespace("foo") == "foo"
def test_find_namespace_does_not_fail_on_deep_similar_namespaces(self): applicaton = Application() applicaton.get_namespaces = self.mock().MagicMock(return_value=["foo:sublong", "bar:sub"]) self.assertEqual("foo:sublong", applicaton.find_namespace("f:sub"))