Example #1
0
    def __init__(self, command):  # type: (BaseCommand) -> None
        """
        Constructor
        """
        self._command = command
        self._io = BufferedIO()
        self._inputs = []
        self._status_code = None

        if self._command.application:
            for style in self._command.application.config.style_set.styles.values(
            ):
                self._io.output.formatter.add_style(style)
                self._io.error_output.formatter.add_style(style)
Example #2
0
class CommandTester(object):
    """
    Eases the testing of console commands.
    """
    def __init__(self, command):  # type: (BaseCommand) -> None
        """
        Constructor
        """
        self._command = command
        self._io = BufferedIO()
        self._inputs = []
        self._status_code = None

        if self._command.application:
            for style in self._command.application.config.style_set.styles.values(
            ):
                self._io.output.formatter.add_style(style)
                self._io.error_output.formatter.add_style(style)

    @property
    def io(self):  # type: () -> BufferedIO
        return self._io

    @property
    def status_code(self):  # type: () -> int
        return self._status_code

    def execute(self, args="", **options):  # type: (str, ...) -> int
        """
        Executes the command

        Available options:
            * interactive: Sets the input interactive flag
            * decorated: Sets the output decorated flag
            * verbosity: Sets the output verbosity flag
        """
        args = StringArgs(args)

        if "inputs" in options:
            self._io.set_input(options["inputs"])

        if "interactive" in options:
            self._io.set_interactive(options["interactive"])

        if "verbosity" in options:
            self._io.set_verbosity(options["verbosity"])

        if "decorated" in options and options["decorated"]:
            self._io.set_formatter(AnsiFormatter())

        command = Command(self._command.config, self._command.application)

        self._status_code = command.run(args, self._io)

        return self._status_code
Example #3
0
def test_publish_can_publish_to_given_repository(fixture_dir, mocker, config):
    uploader_auth = mocker.patch("poetry.publishing.uploader.Uploader.auth")
    uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload")
    poetry = Factory().create_poetry(fixture_dir("sample_project"))
    poetry._config = config
    poetry.config.merge(
        {
            "repositories": {"my-repo": {"url": "http://foo.bar"}},
            "http-basic": {"my-repo": {"username": "******", "password": "******"}},
        }
    )
    io = BufferedIO()
    publisher = Publisher(poetry, io)

    publisher.publish("my-repo", None, None)

    assert [("foo", "bar")] == uploader_auth.call_args
    assert [
        ("http://foo.bar",),
        {"cert": None, "client_cert": None, "dry_run": False},
    ] == uploader_upload.call_args
    assert "Publishing my-package (1.2.3) to my-repo" in io.fetch_output()
Example #4
0
class ApplicationTester(object):
    """
    Eases the testing of console applications.
    """

    def __init__(self, application):  # type: (Application) -> None
        self._application = application
        self._application.config.set_terminate_after_run(False)
        self._io = BufferedIO()
        self._status_code = 0

    @property
    def io(self):  # type: () -> BufferedIO
        return self._io

    @property
    def status_code(self):  # type: () -> int
        return self._status_code

    def execute(self, args, **options):  # type: (str, ...) -> int
        """
        Executes the command

        Available options:
            * interactive: Sets the input interactive flag
            * verbosity: Sets the output verbosity flag
        """
        args = StringArgs(args)

        if "inputs" in options:
            self._io.set_input(options["inputs"])

        if "interactive" in options:
            self._io.set_interactive(options["interactive"])

        if "verbosity" in options:
            self._io.set_verbosity(options["verbosity"])

        self._status_code = self._application.run(
            args,
            self._io.input.stream,
            self._io.output.stream,
            self._io.error_output.stream,
        )

        return self._status_code
Example #5
0
class ApplicationTester(object):
    """
    Eases the testing of console applications.
    """
    def __init__(self, application):  # type: (Application) -> None
        self._application = application
        self._application.config.set_terminate_after_run(False)
        self._io = BufferedIO()
        self._status_code = 0

    @property
    def io(self):  # type: () -> BufferedIO
        return self._io

    @property
    def status_code(self):  # type: () -> int
        return self._status_code

    def execute(self, args, **options):  # type: (str, ...) -> int
        """
        Executes the command

        Available options:
            * interactive: Sets the input interactive flag
            * verbosity: Sets the output verbosity flag
        """
        args = StringArgs(args)

        if "inputs" in options:
            self._io.set_input(options["inputs"])

        if "interactive" in options:
            self._io.set_interactive(options["interactive"])

        if "verbosity" in options:
            self._io.set_verbosity(options["verbosity"])

        self._status_code = self._application.run(
            args,
            self._io.input.stream,
            self._io.output.stream,
            self._io.error_output.stream,
        )

        return self._status_code
Example #6
0
 def __init__(self, application):  # type: (Application) -> None
     self._application = application
     self._application.config.set_terminate_after_run(False)
     self._io = BufferedIO()
     self._status_code = 0
Example #7
0
 def __init__(self, application):  # type: (Application) -> None
     self._application = application
     self._application.config.set_terminate_after_run(False)
     self._io = BufferedIO()
     self._status_code = 0
Example #8
0
 def __init__(self, application):  # type: (Application) -> None
     self._application = application
     self._io = BufferedIO()
     self._status_code = 0