예제 #1
0
    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'
        )
예제 #2
0
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")
예제 #3
0
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")
예제 #4
0
    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')
        )
예제 #5
0
    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"
        )
예제 #6
0
def test_find_namespace_with_sub_namespaces(app: Application):
    app.add(FooSubNamespaced1Command())
    app.add(FooSubNamespaced2Command())

    assert app.find_namespace("foo") == "foo"
예제 #7
0
def test_find_namespace(app: Application):
    app.add(FooCommand())

    assert app.find_namespace("foo") == "foo"
예제 #8
0
    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"))