コード例 #1
0
    def test_find(self):
        """
        Application.find() should return a command
        """
        application = Application()
        application.add(FooCommand())

        self.assertTrue(
            isinstance(application.find('foo:bar'), FooCommand),
            msg='.find() returns a command if its name exists'
        )
        self.assertTrue(
            isinstance(application.find('h'), HelpCommand),
            msg='.find() returns a command if its name exists'
        )
        self.assertTrue(
            isinstance(application.find('f:bar'), FooCommand),
            msg='.find() returns a command if the abbreviation for the namespace exists'
        )
        self.assertTrue(
            isinstance(application.find('f:b'), FooCommand),
            msg='.find() returns a command if the abbreviation for the namespace and the command name exist'
        )
        self.assertTrue(
            isinstance(application.find('a'), FooCommand),
            msg='.find() returns a command if the abbreviation exists for an alias'
        )
コード例 #2
0
ファイル: test_application.py プロジェクト: onema/cleo
    def test_find(self):
        """
        Application.find() should return a command
        """
        application = Application()
        application.add(FooCommand())

        self.assertTrue(
            isinstance(application.find("foo:bar"), FooCommand), msg=".find() returns a command if its name exists"
        )
        self.assertTrue(
            isinstance(application.find("h"), HelpCommand), msg=".find() returns a command if its name exists"
        )
        self.assertTrue(
            isinstance(application.find("f:bar"), FooCommand),
            msg=".find() returns a command if the abbreviation for the namespace exists",
        )
        self.assertTrue(
            isinstance(application.find("f:b"), FooCommand),
            msg=".find() returns a command if the abbreviation for the namespace and the command name exist",
        )
        self.assertTrue(
            isinstance(application.find("a"), FooCommand),
            msg=".find() returns a command if the abbreviation exists for an alias",
        )
コード例 #3
0
    def test_find_alternative_commands(self):
        application = Application()
        application.add(FooCommand())
        application.add(Foo1Command())
        application.add(Foo2Command())

        command_name = 'Unknown command'
        try:
            application.find(command_name)
            self.fail('.find() raises an Exception if command does not exist')
        except Exception as e:
            self.assertEqual('Command "%s" is not defined.' % command_name,
                             str(e))

        command_name = 'bar1'
        try:
            application.find(command_name)
            self.fail('.find() raises an Exception if command does not exist')
        except Exception as e:
            self.assertRegexpMatches(
                str(e), 'Command "%s" is not defined.' % command_name)
            self.assertRegexpMatches(
                str(e),
                'afoobar1',
            )
            self.assertRegexpMatches(
                str(e),
                'foo:bar1',
            )
            self.assertNotRegex(str(e), 'foo:bar$')
コード例 #4
0
ファイル: test_application.py プロジェクト: onema/cleo
    def test_find_alternative_namespace(self):
        application = Application()

        application.add(FooCommand())
        application.add(Foo1Command())
        application.add(Foo2Command())
        application.add(Foo3Command())

        try:
            application.find("Unknown-namespace:Unknown-command")
            self.fail(".find() raises an Exception if namespace does not exist")
        except Exception as e:
            self.assertRegex(str(e), 'There are no commands defined in the "Unknown-namespace" namespace.')

        try:
            application.find("foo2:command")
            self.fail(".find() raises an tException if namespace does not exist")
        except Exception as e:
            self.assertRegex(str(e), 'There are no commands defined in the "foo2" namespace.')
            self.assertRegex(
                str(e), "foo", msg='.find() raises an tException if namespace does not exist, with alternative "foo"'
            )
            self.assertRegex(
                str(e), "foo1", msg='.find() raises an tException if namespace does not exist, with alternative "foo1"'
            )
            self.assertRegex(
                str(e), "foo3", msg='.find() raises an Exception if namespace does not exist, with alternative "foo2"'
            )
コード例 #5
0
ファイル: test_application.py プロジェクト: meschac38700/cleo
def test_find_ambiguous_command(app: Application):
    app.add(FooCommand())

    with pytest.raises(
        CommandNotFoundException,
        match=r'The command "foo b" does not exist\.\n\nDid you mean this\?\n    foo bar',
    ):
        app.find("foo b")
コード例 #6
0
ファイル: test_application.py プロジェクト: meschac38700/cleo
def test_find_unique_name_but_namespace_name(app: Application):
    app.add(FooCommand())
    app.add(Foo1Command())
    app.add(Foo2Command())

    with pytest.raises(
        CommandNotFoundException,
        match=r'The command "foo1" does not exist\.',
    ):
        app.find("foo1")
コード例 #7
0
ファイル: test_application.py プロジェクト: meschac38700/cleo
def test_find_ambiguous_command_hidden(app: Application):
    foo = FooCommand()
    foo.hidden = True
    app.add(foo)

    with pytest.raises(
        CommandNotFoundException,
        match=r'The command "foo b" does not exist\.$',
    ):
        app.find("foo b")
コード例 #8
0
    def test_find_command_equal_namesapce(self):
        """
        Application.find() returns a command if it has a namespace with the same name
        """
        application = Application()
        application.add(Foo3Command())
        application.add(Foo4Command())

        self.assertTrue(
            isinstance(application.find('foo3:bar'), Foo3Command),
            msg='.find() returns the good command even if a namespace has same name'
        )
        self.assertTrue(
            isinstance(application.find('foo3:bar:toh'), Foo4Command),
            msg='.find() returns a command even if its namespace equals another command name'
        )
コード例 #9
0
ファイル: test_application.py プロジェクト: onema/cleo
    def test_find_command_equal_namesapce(self):
        """
        Application.find() returns a command if it has a namespace with the same name
        """
        application = Application()
        application.add(Foo3Command())
        application.add(Foo4Command())

        self.assertTrue(
            isinstance(application.find("foo3:bar"), Foo3Command),
            msg=".find() returns the good command even if a namespace has same name",
        )
        self.assertTrue(
            isinstance(application.find("foo3:bar:toh"), Foo4Command),
            msg=".find() returns a command even if its namespace equals another command name",
        )
コード例 #10
0
def test_execute_hello_world_command_no_params():
    application = Application()
    application.add(HelloWorldCommand())
    command = application.find('greet')
    command_tester = CommandTester(command)
    command_tester.execute()
    assert "Hello" == command_tester.io.fetch_output().rstrip()
コード例 #11
0
ファイル: test_application.py プロジェクト: onema/cleo
    def test_find_command_with_missing_namespace(self):
        """
        Application.find() returns a command with missing namespace
        """
        application = Application()
        application.add(Foo4Command())

        self.assertTrue(isinstance(application.find("f::t"), Foo4Command))
コード例 #12
0
    def test_find_command_with_missing_namespace(self):
        """
        Application.find() returns a command with missing namespace
        """
        application = Application()
        application.add(Foo4Command())

        self.assertTrue(isinstance(application.find('f::t'), Foo4Command))
コード例 #13
0
def test_execute_namespace_command():
    app = Application()
    app.add(FooBarCommand())
    tester = CommandTester(app.find("foo bar"))

    assert 0 == tester.execute()
    assert 0 == tester.status_code
    assert "foo bar called\n" == tester.io.fetch_output()
コード例 #14
0
ファイル: test_application.py プロジェクト: onema/cleo
    def test_find_command_with_ambiguous_namespace_but_unique_name(self):
        """
        Application.find() returns a command with ambiguous namespace
        """
        application = Application()
        application.add(FooCommand())
        application.add(FoobarCommand())

        self.assertTrue(isinstance(application.find("f:f"), FoobarCommand))
コード例 #15
0
    def test_find_command_with_ambiguous_namespace_but_unique_name(self):
        """
        Application.find() returns a command with ambiguous namespace
        """
        application = Application()
        application.add(FooCommand())
        application.add(FoobarCommand())

        self.assertTrue(isinstance(application.find('f:f'), FoobarCommand))
コード例 #16
0
    def test_find_alternative_namespace(self):
        application = Application()

        application.add(FooCommand())
        application.add(Foo1Command())
        application.add(Foo2Command())
        application.add(Foo3Command())

        try:
            application.find('Unknown-namespace:Unknown-command')
            self.fail(
                '.find() raises an Exception if namespace does not exist')
        except Exception as e:
            self.assertRegex(
                str(e),
                'There are no commands defined in the "Unknown-namespace" namespace.'
            )

        try:
            application.find('foo2:command')
            self.fail(
                '.find() raises an tException if namespace does not exist')
        except Exception as e:
            self.assertRegex(
                str(e),
                'There are no commands defined in the "foo2" namespace.')
            self.assertRegex(
                str(e),
                'foo',
                msg=
                '.find() raises an tException if namespace does not exist, with alternative "foo"'
            )
            self.assertRegex(
                str(e),
                'foo1',
                msg=
                '.find() raises an tException if namespace does not exist, with alternative "foo1"'
            )
            self.assertRegex(
                str(e),
                'foo3',
                msg=
                '.find() raises an Exception if namespace does not exist, with alternative "foo2"'
            )
コード例 #17
0
    def find_alternative_commands_with_an_alias(self):
        foo_command = FooCommand()
        foo_command.set_aliases(['foo2'])

        application = Application()
        application.add(foo_command)

        result = application.find('foo')

        self.assertEqual(foo_command, result)
コード例 #18
0
ファイル: test_application.py プロジェクト: onema/cleo
    def find_alternative_commands_with_an_alias(self):
        foo_command = FooCommand()
        foo_command.set_aliases(["foo2"])

        application = Application()
        application.add(foo_command)

        result = application.find("foo")

        self.assertEqual(foo_command, result)
コード例 #19
0
def test_execute():
    config = {
        "scripts": {
            "e": ["python", "-c", "print(1)"],
        }
    }

    application = Application()
    application.add(CustomCommand(config))
    command = application.find("do")
    command_tester = CommandTester(command)
    command_tester.execute("e")
コード例 #20
0
ファイル: test_application.py プロジェクト: onema/cleo
    def test_find_alternative_exception_message_multiple(self):
        """
        Application.find() raises an exception when alternatives have been found
        """
        application = Application()
        application.add(FooCommand())
        application.add(Foo1Command())
        application.add(Foo2Command())

        try:
            application.find("foo:baR")
            self.fail(".find() raises an Exception if command does not exist, with alternatives")
        except Exception as e:
            self.assertRegexpMatches(str(e), "Did you mean one of these")
            self.assertRegexpMatches(str(e), "foo1:bar")
            self.assertRegexpMatches(str(e), "foo:bar")

        try:
            application.find("foo2:baR")
            self.fail(".find() raises an Exception if command does not exist, with alternatives")
        except Exception as e:
            self.assertRegexpMatches(str(e), "Did you mean one of these")
            self.assertRegexpMatches(str(e), "foo1")

        application.add(Foo3Command())
        application.add(Foo4Command())

        try:
            application.find("foo3:")
            self.fail(".find() raises an Exception if command does not exist, with alternatives")
        except Exception as e:
            self.assertRegexpMatches(str(e), "foo3:bar")
            self.assertRegexpMatches(str(e), "foo3:bar:toh")
コード例 #21
0
ファイル: test_application.py プロジェクト: onema/cleo
    def test_find_alternative_commands(self):
        application = Application()
        application.add(FooCommand())
        application.add(Foo1Command())
        application.add(Foo2Command())

        command_name = "Unknown command"
        try:
            application.find(command_name)
            self.fail(".find() raises an Exception if command does not exist")
        except Exception as e:
            self.assertEqual('Command "%s" is not defined.' % command_name, str(e))

        command_name = "bar1"
        try:
            application.find(command_name)
            self.fail(".find() raises an Exception if command does not exist")
        except Exception as e:
            self.assertRegexpMatches(str(e), 'Command "%s" is not defined.' % command_name)
            self.assertRegexpMatches(str(e), "afoobar1")
            self.assertRegexpMatches(str(e), "foo:bar1")
            self.assertNotRegex(str(e), "foo:bar$")
コード例 #22
0
    def test_find_alternative_exception_message_multiple(self):
        """
        Application.find() raises an exception when alternatives have been found
        """
        application = Application()
        application.add(FooCommand())
        application.add(Foo1Command())
        application.add(Foo2Command())

        try:
            application.find('foo:baR')
            self.fail('.find() raises an Exception if command does not exist, with alternatives')
        except Exception as e:
            self.assertRegexpMatches(
                str(e),
                'Did you mean one of these'
            )
            self.assertRegexpMatches(
                str(e),
                'foo1:bar'
            )
            self.assertRegexpMatches(
                str(e),
                'foo:bar'
            )

        try:
            application.find('foo2:baR')
            self.fail('.find() raises an Exception if command does not exist, with alternatives')
        except Exception as e:
            self.assertRegexpMatches(
                str(e),
                'Did you mean one of these'
            )
            self.assertRegexpMatches(
                str(e),
                'foo1'
            )

        application.add(Foo3Command())
        application.add(Foo4Command())

        try:
            application.find('foo3:')
            self.fail('.find() raises an Exception if command does not exist, with alternatives')
        except Exception as e:
            self.assertRegexpMatches(
                str(e),
                'foo3:bar'
            )
            self.assertRegexpMatches(
                str(e),
                'foo3:bar:toh'
            )
コード例 #23
0
ファイル: test_application.py プロジェクト: meschac38700/cleo
def test_find(app: Application):
    app.add(FooCommand())

    assert isinstance(app.find("foo bar"), FooCommand)
    assert isinstance(app.find("afoobar"), FooCommand)