How to use the cleo.testers.CommandTester function in cleo

To help you get started, we’ve selected a few cleo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-poetry / poetry / tests / console / commands / env / test_list.py View on Github external
def test_none_activated(app, tmp_dir):
    app.poetry.config.merge({"virtualenvs": {"path": str(tmp_dir)}})

    venv_name = EnvManager.generate_env_name(
        "simple-project", str(app.poetry.file.parent)
    )
    (Path(tmp_dir) / "{}-py3.7".format(venv_name)).mkdir()
    (Path(tmp_dir) / "{}-py3.6".format(venv_name)).mkdir()

    command = app.find("env list")
    tester = CommandTester(command)
    tester.execute()

    expected = """\
{}-py3.6
{}-py3.7
""".format(
        venv_name, venv_name
    )

    assert expected == tester.io.fetch_output()
github python-poetry / poetry / tests / console / commands / env / test_remove.py View on Github external
def test_remove_by_python_version(app, tmp_dir, mocker):
    app.poetry.config.merge({"virtualenvs": {"path": str(tmp_dir)}})

    venv_name = EnvManager.generate_env_name(
        "simple-project", str(app.poetry.file.parent)
    )
    (Path(tmp_dir) / "{}-py3.7".format(venv_name)).mkdir()
    (Path(tmp_dir) / "{}-py3.6".format(venv_name)).mkdir()

    check_output = mocker.patch(
        "poetry.utils._compat.subprocess.check_output",
        side_effect=check_output_wrapper(Version.parse("3.6.6")),
    )

    command = app.find("env remove")
    tester = CommandTester(command)
    tester.execute("3.6")

    assert check_output.called
    assert not (Path(tmp_dir) / "{}-py3.6".format(venv_name)).exists()

    expected = "Deleted virtualenv: {}\n".format(
        (Path(tmp_dir) / "{}-py3.6".format(venv_name))
    )

    assert expected == tester.io.fetch_output()
github sdispater / cleo / tests / commands / test_command.py View on Github external
def test_explicit_multiple_argument():
    command = MySecondCommand()

    tester = CommandTester(command)
    tester.execute("1 2 3")

    assert "1,2,3\n" == tester.io.fetch_output()
github python-poetry / poetry / tests / console / commands / test_export.py View on Github external
def test_export_includes_extras_by_flag(app, repo):
    repo.add_package(get_package("foo", "1.0.0"))
    repo.add_package(get_package("bar", "1.1.0"))

    command = app.find("lock")
    tester = CommandTester(command)
    tester.execute()

    assert app.poetry.locker.lock.exists()

    command = app.find("export")
    tester = CommandTester(command)

    tester.execute("--format requirements.txt --extras feature_bar")

    expected = """\
bar==1.1.0
foo==1.0.0
"""

    assert expected == tester.io.fetch_output()
github alan-turing-institute / CleverCSV / tests / test_unit / test_console.py View on Github external
def test_standardize_2(self):
        table = [["A", "B", "C"], [1, 2, 3], [4, 5, 6]]
        dialect = SimpleDialect(delimiter=";", quotechar="", escapechar="")
        tmpfname = self._build_file(table, dialect)

        tmpfd, tmpoutname = tempfile.mkstemp(prefix="ccsv_", suffix=".csv")
        os.close(tmpfd)

        application = build_application()
        command = application.find("standardize")
        tester = CommandTester(command)
        tester.execute(f"-o {tmpoutname} {tmpfname}")

        # Excel format (i.e. RFC4180) *requires* CRLF
        crlf = "\r\n"
        exp = crlf.join(["A,B,C", "1,2,3", "4,5,6", ""])
        with open(tmpoutname, "r", newline="") as fp:
            output = fp.read()

        try:
            self.assertEqual(exp, output)
        finally:
            os.unlink(tmpfname)
            os.unlink(tmpoutname)
github python-poetry / poetry / tests / console / commands / test_add.py View on Github external
def test_add_constraint_with_extras(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    cachy1 = get_package("cachy", "0.1.0")
    cachy1.extras = {"msgpack": [get_dependency("msgpack-python")]}
    msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6", optional=True)
    cachy1.requires = [msgpack_dep]

    repo.add_package(get_package("cachy", "0.2.0"))
    repo.add_package(cachy1)
    repo.add_package(get_package("msgpack-python", "0.5.3"))

    tester.execute("cachy[msgpack]>=0.1.0,<0.2.0")

    expected = """\

Updating dependencies
Resolving dependencies...
github python-poetry / poetry / tests / console / commands / test_show.py View on Github external
def test_show_latest_non_decorated(app, poetry, installed, repo):
    command = app.find("show")
    tester = CommandTester(command)

    cachy_010 = get_package("cachy", "0.1.0")
    cachy_010.description = "Cachy package"
    cachy_020 = get_package("cachy", "0.2.0")
    cachy_020.description = "Cachy package"

    pendulum_200 = get_package("pendulum", "2.0.0")
    pendulum_200.description = "Pendulum package"
    pendulum_201 = get_package("pendulum", "2.0.1")
    pendulum_201.description = "Pendulum package"

    installed.add_package(cachy_010)
    installed.add_package(pendulum_200)

    repo.add_package(cachy_010)
    repo.add_package(cachy_020)
github sdispater / cleo / tests / commands / test_command.py View on Github external
def test_overwrite():
    command = MyCommand()

    tester = CommandTester(command)
    tester.execute("overwrite", decorated=True)

    expected = "Processing...{}Done!        {}".format("\x08" * 13, "\x08" * 8)
    assert expected == tester.io.fetch_output()
github python-poetry / poetry / tests / console / commands / test_show.py View on Github external
def test_show_hides_incompatible_package(app, poetry, installed, repo):
    command = app.find("show")
    tester = CommandTester(command)

    cachy_010 = get_package("cachy", "0.1.0")
    cachy_010.description = "Cachy package"

    pendulum_200 = get_package("pendulum", "2.0.0")
    pendulum_200.description = "Pendulum package"

    installed.add_package(pendulum_200)

    poetry.locker.mock_lock_data(
        {
            "package": [
                {
                    "name": "cachy",
                    "version": "0.1.0",
                    "description": "Cachy package",
github python-poetry / poetry / tests / console / commands / debug / test_resolve.py View on Github external
def test_debug_resolve_tree_option_gives_the_dependency_tree(app, repo):
    command = app.find("debug:resolve")
    tester = CommandTester(command)

    cachy2 = get_package("cachy", "0.2.0")
    cachy2.add_dependency("msgpack-python", ">=0.5 <0.6")

    repo.add_package(get_package("cachy", "0.1.0"))
    repo.add_package(cachy2)
    repo.add_package(get_package("msgpack-python", "0.5.3"))

    tester.execute(
        [("command", command.get_name()), ("package", ["cachy"]), ("--tree", True)]
    )

    expected = """\
Resolving dependencies...

Resolution results: