Пример #1
0
def test_add_git_constraint_with_poetry(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("pendulum", "1.4.4"))

    tester.execute([
        ("command", command.get_name()),
        ("name", ["demo"]),
        ("--git", "https://github.com/demo/pyproject-demo.git"),
    ])

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 2 installs, 0 updates, 0 removals

Writing lock file

  - Installing pendulum (1.4.4)
  - Installing demo (0.1.2 9cf87a2)
"""

    assert tester.get_display(True) == expected

    assert len(installer.installs) == 2
Пример #2
0
def test_add_no_constraint(app, repo, installer):
    command = app.find('add')
    tester = CommandTester(command)

    repo.add_package(get_package('cachy', '0.1.0'))
    repo.add_package(get_package('cachy', '0.2.0'))

    tester.execute([('command', command.get_name()), ('name', ['cachy'])])

    expected = """\
Using version ^0.2.0 for cachy

Updating dependencies
Resolving dependencies...


Package operations: 1 install, 0 updates, 0 removals

Writing lock file

  - Installing cachy (0.2.0)
"""

    assert tester.get_display() == expected

    assert len(installer.installs) == 1

    content = app.poetry.file.read(raw=True)['tool']['poetry']

    assert 'cachy' in content['dependencies']
    assert content['dependencies']['cachy'] == '^0.2.0'
Пример #3
0
def test_add_constraint(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("cachy", "0.1.0"))
    repo.add_package(get_package("cachy", "0.2.0"))

    tester.execute([("command", command.get_name()),
                    ("name", ["cachy=0.1.0"])])

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 1 install, 0 updates, 0 removals

Writing lock file

  - Installing cachy (0.1.0)
"""

    assert tester.get_display(True) == expected

    assert len(installer.installs) == 1
Пример #4
0
def test_add_constraint(app, repo, installer):
    command = app.find('add')
    tester = CommandTester(command)

    repo.add_package(get_package('cachy', '0.1.0'))
    repo.add_package(get_package('cachy', '0.2.0'))

    tester.execute([('command', command.get_name()),
                    ('name', ['cachy=0.1.0'])])

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 1 install, 0 updates, 0 removals

Writing lock file

  - Installing cachy (0.1.0)
"""

    assert tester.get_display() == expected

    assert len(installer.installs) == 1
Пример #5
0
def test_add_constraint_dependencies(app, repo, installer):
    command = app.find('add')
    tester = CommandTester(command)

    cachy2 = get_package('cachy', '0.2.0')
    msgpack_dep = get_dependency('msgpack-python', '>=0.5 <0.6')
    cachy2.requires = [
        msgpack_dep,
    ]

    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()),
                    ('name', ['cachy=0.2.0'])])

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 2 installs, 0 updates, 0 removals

Writing lock file

  - Installing msgpack-python (0.5.3)
  - Installing cachy (0.2.0)
"""

    assert tester.get_display() == expected

    assert len(installer.installs) == 2
Пример #6
0
def test_add_git_constraint_with_poetry(app, repo, installer):
    command = app.find('add')
    tester = CommandTester(command)

    repo.add_package(get_package('pendulum', '1.4.4'))

    tester.execute([('command', command.get_name()), ('name', ['demo']),
                    ('--git', 'https://github.com/demo/pyproject-demo.git')])

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 2 installs, 0 updates, 0 removals

Writing lock file

  - Installing pendulum (1.4.4)
  - Installing demo (0.1.2 9cf87a2)
"""

    assert tester.get_display() == expected

    assert len(installer.installs) == 2
Пример #7
0
def test_add_file_constraint_sdist(app, repo, installer):
    command = app.find('add')
    tester = CommandTester(command)

    repo.add_package(get_package('pendulum', '1.4.4'))

    tester.execute([('command', command.get_name()), ('name', ['demo']),
                    ('--path', '../distributions/demo-0.1.0.tar.gz')])

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 2 installs, 0 updates, 0 removals

Writing lock file

  - Installing pendulum (1.4.4)
  - Installing demo (0.1.0)
"""

    assert tester.get_display() == expected

    assert len(installer.installs) == 2

    content = app.poetry.file.read(raw=True)['tool']['poetry']

    assert 'demo' in content['dependencies']
    assert content['dependencies']['demo'] == {
        'path': '../distributions/demo-0.1.0.tar.gz'
    }
Пример #8
0
def test_add_git_constraint(app, repo, installer):
    command = app.find('add')
    tester = CommandTester(command)

    repo.add_package(get_package('pendulum', '1.4.4'))

    tester.execute([('command', command.get_name()), ('name', ['demo']),
                    ('--git', 'https://github.com/demo/demo.git')])

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 2 installs, 0 updates, 0 removals

Writing lock file

  - Installing pendulum (1.4.4)
  - Installing demo (0.1.2 9cf87a2)
"""

    assert tester.get_display() == expected

    assert len(installer.installs) == 2

    content = app.poetry.file.read(raw=True)['tool']['poetry']

    assert 'demo' in content['dependencies']
    assert content['dependencies']['demo'] == {
        'git': 'https://github.com/demo/demo.git'
    }
Пример #9
0
def test_activated(app, tmp_dir, config):
    app.poetry._config = config

    config.add_property("settings.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()

    envs_file = TomlFile(Path(tmp_dir) / "envs.toml")
    doc = tomlkit.document()
    doc[venv_name] = {"minor": "3.7", "patch": "3.7.0"}
    envs_file.write(doc)

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

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

    assert expected == tester.io.fetch_output()
Пример #10
0
def test_add_constraint_dependencies(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    cachy2 = get_package("cachy", "0.2.0")
    msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6")
    cachy2.requires = [msgpack_dep]

    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()),
                    ("name", ["cachy=0.2.0"])])

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 2 installs, 0 updates, 0 removals

Writing lock file

  - Installing msgpack-python (0.5.3)
  - Installing cachy (0.2.0)
"""

    assert tester.get_display(True) == expected

    assert len(installer.installs) == 2
Пример #11
0
def test_explicit_multiple_argument():
    command = MySecondCommand()

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

    assert "1,2,3\n" == tester.io.fetch_output()
Пример #12
0
def test_add_chooses_prerelease_if_only_prereleases_are_available(
        app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("foo", "1.2.3b0"))
    repo.add_package(get_package("foo", "1.2.3b1"))

    tester.execute("foo")

    expected = """\
Using version ^1.2.3-beta.1 for foo

Updating dependencies
Resolving dependencies...

Writing lock file


Package operations: 1 install, 0 updates, 0 removals

  - Installing foo (1.2.3b1)
"""

    assert expected in tester.io.fetch_output()
Пример #13
0
def test_add_file_constraint_sdist(app, repo, installer, mocker):
    p = mocker.patch("poetry.utils._compat.Path.cwd")
    p.return_value = Path(__file__) / ".."

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

    repo.add_package(get_package("pendulum", "1.4.4"))

    tester.execute("../distributions/demo-0.1.0.tar.gz")

    expected = """\

Updating dependencies
Resolving dependencies...

Writing lock file


Package operations: 2 installs, 0 updates, 0 removals

  - Installing pendulum (1.4.4)
  - Installing demo (0.1.0 ../distributions/demo-0.1.0.tar.gz)
"""

    assert expected == tester.io.fetch_output()

    assert len(installer.installs) == 2

    content = app.poetry.file.read()["tool"]["poetry"]

    assert "demo" in content["dependencies"]
    assert content["dependencies"]["demo"] == {
        "path": "../distributions/demo-0.1.0.tar.gz"
    }
Пример #14
0
def test_add_constraint_with_python(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    cachy2 = get_package("cachy", "0.2.0")

    repo.add_package(get_package("cachy", "0.1.0"))
    repo.add_package(cachy2)

    tester.execute("cachy=0.2.0 --python >=2.7")

    expected = """\

Updating dependencies
Resolving dependencies...

Writing lock file


Package operations: 1 install, 0 updates, 0 removals

  - Installing cachy (0.2.0)
"""

    assert expected == tester.io.fetch_output()

    assert len(installer.installs) == 1

    content = app.poetry.file.read()["tool"]["poetry"]

    assert "cachy" in content["dependencies"]
    assert content["dependencies"]["cachy"] == {"version": "0.2.0", "python": ">=2.7"}
Пример #15
0
def test_check_invalid(app, mocker):
    mocker.patch(
        "poetry.factory.Factory.locate",
        return_value=Path(__file__).parent.parent.parent / "fixtures" /
        "invalid_pyproject" / "pyproject.toml",
    )

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

    tester.execute()

    if PY2:
        expected = """\
Error: u'description' is a required property
Error: INVALID is not a valid license
Warning: A wildcard Python dependency is ambiguous. Consider specifying a more explicit one.
Warning: The "pendulum" dependency specifies the "allows-prereleases" property, which is deprecated. Use "allow-prereleases" instead.
"""
    else:
        expected = """\
Error: 'description' is a required property
Error: INVALID is not a valid license
Warning: A wildcard Python dependency is ambiguous. Consider specifying a more explicit one.
Warning: The "pendulum" dependency specifies the "allows-prereleases" property, which is deprecated. Use "allow-prereleases" instead.
"""

    assert expected == tester.io.fetch_output()
Пример #16
0
def test_add_should_not_select_prereleases(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("pyyaml", "3.13"))
    repo.add_package(get_package("pyyaml", "4.2b2"))

    tester.execute([("command", command.get_name()), ("name", ["pyyaml"])])

    expected = """\
Using version ^3.13 for pyyaml

Updating dependencies
Resolving dependencies...


Package operations: 1 install, 0 updates, 0 removals

Writing lock file

  - Installing pyyaml (3.13)
"""

    assert tester.get_display(True) == expected

    assert len(installer.installs) == 1

    content = app.poetry.file.read()["tool"]["poetry"]

    assert "pyyaml" in content["dependencies"]
    assert content["dependencies"]["pyyaml"] == "^3.13"
Пример #17
0
 def test_execute_for_command_alias(self):
     command = HelpCommand()
     command.set_application(Application())
     tester = CommandTester(command)
     tester.execute([('command_name', 'li')], {'decorated': False})
     self.assertIn('list [options] [--] [<namespace>]',
                   tester.get_display())
Пример #18
0
def test_show_outdated(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"

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

    repo.add_package(cachy_010)
    repo.add_package(cachy_020)
    repo.add_package(pendulum_200)

    poetry.locker.mock_lock_data({
        "package": [
            {
                "name": "cachy",
                "version": "0.1.0",
                "description": "Cachy package",
                "category": "main",
                "optional": False,
                "platform": "*",
                "python-versions": "*",
                "checksum": [],
            },
            {
                "name": "pendulum",
                "version": "2.0.0",
                "description": "Pendulum package",
                "category": "main",
                "optional": False,
                "platform": "*",
                "python-versions": "*",
                "checksum": [],
            },
        ],
        "metadata": {
            "python-versions": "*",
            "platform": "*",
            "content-hash": "123456789",
            "hashes": {
                "cachy": [],
                "pendulum": []
            },
        },
    })

    tester.execute("--outdated")

    expected = """\
cachy 0.1.0 0.2.0 Cachy package
"""

    assert expected == tester.io.fetch_output()
Пример #19
0
def test_add_git_constraint_with_poetry(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("pendulum", "1.4.4"))

    tester.execute(
        [
            ("command", command.get_name()),
            ("name", ["demo"]),
            ("--git", "https://github.com/demo/pyproject-demo.git"),
        ]
    )

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 2 installs, 0 updates, 0 removals

Writing lock file

  - Installing pendulum (1.4.4)
  - Installing demo (0.1.2 9cf87a2)
"""

    assert tester.get_display(True) == expected

    assert len(installer.installs) == 2
Пример #20
0
def test_add_no_constraint(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("cachy", "0.1.0"))
    repo.add_package(get_package("cachy", "0.2.0"))

    tester.execute([("command", command.get_name()), ("name", ["cachy"])])

    expected = """\
Using version ^0.2.0 for cachy

Updating dependencies
Resolving dependencies...


Package operations: 1 install, 0 updates, 0 removals

Writing lock file

  - Installing cachy (0.2.0)
"""

    assert tester.get_display(True) == expected

    assert len(installer.installs) == 1

    content = app.poetry.file.read()["tool"]["poetry"]

    assert "cachy" in content["dependencies"]
    assert content["dependencies"]["cachy"] == "^0.2.0"
Пример #21
0
def test_add_git_constraint(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("pendulum", "1.4.4"))
    repo.add_package(get_package("cleo", "0.6.5"))

    tester.execute("git+https://github.com/demo/demo.git")

    expected = """\

Updating dependencies
Resolving dependencies...

Writing lock file


Package operations: 2 installs, 0 updates, 0 removals

  - Installing pendulum (1.4.4)
  - Installing demo (0.1.2 9cf87a2)
"""

    assert expected == tester.io.fetch_output()

    assert len(installer.installs) == 2

    content = app.poetry.file.read()["tool"]["poetry"]

    assert "demo" in content["dependencies"]
    assert content["dependencies"]["demo"] == {
        "git": "https://github.com/demo/demo.git"
    }
Пример #22
0
def test_add_git_constraint_with_poetry(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("pendulum", "1.4.4"))

    tester.execute("git+https://github.com/demo/pyproject-demo.git")

    expected = """\

Updating dependencies
Resolving dependencies...

Writing lock file


Package operations: 2 installs, 0 updates, 0 removals

  - Installing pendulum (1.4.4)
  - Installing demo (0.1.2 9cf87a2)
"""

    assert expected == tester.io.fetch_output()

    assert len(installer.installs) == 2
Пример #23
0
def test_add_no_constraint(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("cachy", "0.1.0"))
    repo.add_package(get_package("cachy", "0.2.0"))

    tester.execute([("command", command.get_name()), ("name", ["cachy"])])

    expected = """\
Using version ^0.2.0 for cachy

Updating dependencies
Resolving dependencies...


Package operations: 1 install, 0 updates, 0 removals

Writing lock file

  - Installing cachy (0.2.0)
"""

    assert tester.get_display(True) == expected

    assert len(installer.installs) == 1

    content = app.poetry.file.read()["tool"]["poetry"]

    assert "cachy" in content["dependencies"]
    assert content["dependencies"]["cachy"] == "^0.2.0"
Пример #24
0
    def test_code_5(self):
        table = [["A", "B", "C"], [1, 2, 3], [4, 5, 6]]
        dialect = SimpleDialect(delimiter="\t", quotechar="", escapechar="")

        tmpfname = self._build_file(table, dialect)

        application = build_application()
        command = application.find("code")
        tester = CommandTester(command)
        tester.execute(tmpfname)

        exp = f"""\

# Code generated with CleverCSV version {__version__}

import clevercsv

with open("{tmpfname}", "r", newline="", encoding="ascii") as fp:
    reader = clevercsv.reader(fp, delimiter="\\t", quotechar="", escapechar="")
    rows = list(reader)

"""
        try:
            output = tester.io.fetch_output()
            self.assertEqual(exp, output)
        finally:
            os.unlink(tmpfname)
Пример #25
0
def test_add_constraint(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("cachy", "0.1.0"))
    repo.add_package(get_package("cachy", "0.2.0"))

    tester.execute([("command", command.get_name()), ("name", ["cachy=0.1.0"])])

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 1 install, 0 updates, 0 removals

Writing lock file

  - Installing cachy (0.1.0)
"""

    assert tester.get_display(True) == expected

    assert len(installer.installs) == 1
Пример #26
0
def test_add_constraint_dependencies(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    cachy2 = get_package("cachy", "0.2.0")
    msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6")
    cachy2.requires = [msgpack_dep]

    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()), ("name", ["cachy=0.2.0"])])

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 2 installs, 0 updates, 0 removals

Writing lock file

  - Installing msgpack-python (0.5.3)
  - Installing cachy (0.2.0)
"""

    assert tester.get_display(True) == expected

    assert len(installer.installs) == 2
Пример #27
0
def test_add_should_not_select_prereleases(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("pyyaml", "3.13"))
    repo.add_package(get_package("pyyaml", "4.2b2"))

    tester.execute("pyyaml")

    expected = """\
Using version ^3.13 for pyyaml

Updating dependencies
Resolving dependencies...

Writing lock file


Package operations: 1 install, 0 updates, 0 removals

  - Installing pyyaml (3.13)
"""

    assert expected == tester.io.fetch_output()

    assert len(installer.installs) == 1

    content = app.poetry.file.read()["tool"]["poetry"]

    assert "pyyaml" in content["dependencies"]
    assert content["dependencies"]["pyyaml"] == "^3.13"
Пример #28
0
def test_export_exports_requirements_txt_uses_lock_file(app, repo):
    repo.add_package(get_package("foo", "1.0.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")

    requirements = app.poetry.file.parent / "requirements.txt"
    assert requirements.exists()

    with requirements.open(encoding="utf-8") as f:
        content = f.read()

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

    expected = """\
foo==1.0.0
"""

    assert expected == content
    assert "The lock file does not exist. Locking." not in tester.io.fetch_output(
    )
Пример #29
0
 def test_execute_for_command(self):
     command = HelpCommand()
     tester = CommandTester(command)
     command.set_command(ListCommand())
     tester.execute([])
     self.assertIn('list [options] [--] [<namespace>]',
                   tester.get_display())
Пример #30
0
def test_explicit_multiple_argument():
    command = MySecondCommand()

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

    assert "1,2,3\n" == tester.io.fetch_output()
Пример #31
0
def test_add_should_work_when_adding_existing_package_with_latest_constraint(
    app, repo, installer
):
    content = app.poetry.file.read()
    content["tool"]["poetry"]["dependencies"]["foo"] = "^1.0"
    app.poetry.file.write(content)
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("foo", "1.1.2"))

    tester.execute("foo@latest")

    expected = """\
Using version ^1.1.2 for foo

Updating dependencies
Resolving dependencies...

Writing lock file


Package operations: 1 install, 0 updates, 0 removals

  - Installing foo (1.1.2)
"""

    assert expected in tester.io.fetch_output()

    content = app.poetry.file.read()["tool"]["poetry"]

    assert "foo" in content["dependencies"]
    assert content["dependencies"]["foo"] == "^1.1.2"
Пример #32
0
def test_add_greater_constraint(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("cachy", "0.1.0"))
    repo.add_package(get_package("cachy", "0.2.0"))

    tester.execute("cachy>=0.1.0")

    expected = """\

Updating dependencies
Resolving dependencies...

Writing lock file


Package operations: 1 install, 0 updates, 0 removals

  - Installing cachy (0.2.0)
"""

    assert expected == tester.io.fetch_output()

    assert len(installer.installs) == 1
Пример #33
0
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")

    expected = """\

Updating dependencies
Resolving dependencies...

Writing lock file


Package operations: 2 installs, 0 updates, 0 removals

  - Installing msgpack-python (0.5.3)
  - Installing cachy (0.1.0)
"""

    assert expected == tester.io.fetch_output()

    assert len(installer.installs) == 2
Пример #34
0
def test_add_directory_with_poetry(app, repo, installer, mocker):
    p = mocker.patch("poetry.utils._compat.Path.cwd")
    p.return_value = Path(__file__) / ".."

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

    repo.add_package(get_package("pendulum", "1.4.4"))

    tester.execute("../git/github.com/demo/pyproject-demo")

    expected = """\

Updating dependencies
Resolving dependencies...

Writing lock file


Package operations: 2 installs, 0 updates, 0 removals

  - Installing pendulum (1.4.4)
  - Installing demo (0.1.2 ../git/github.com/demo/pyproject-demo)
"""

    assert expected == tester.io.fetch_output()

    assert len(installer.installs) == 2
Пример #35
0
def test_add_to_section_that_does_no_exist_yet(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("cachy", "0.1.0"))
    repo.add_package(get_package("cachy", "0.2.0"))

    tester.execute("cachy --dev")

    expected = """\
Using version ^0.2.0 for cachy

Updating dependencies
Resolving dependencies...

Writing lock file


Package operations: 1 install, 0 updates, 0 removals

  - Installing cachy (0.2.0)
"""

    assert expected == tester.io.fetch_output()

    assert len(installer.installs) == 1

    content = app.poetry.file.read()["tool"]["poetry"]

    assert "cachy" in content["dev-dependencies"]
    assert content["dev-dependencies"]["cachy"] == "^0.2.0"
Пример #36
0
def test_show_outdated(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"

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

    repo.add_package(cachy_010)
    repo.add_package(cachy_020)
    repo.add_package(pendulum_200)

    poetry.locker.mock_lock_data(
        {
            "package": [
                {
                    "name": "cachy",
                    "version": "0.1.0",
                    "description": "Cachy package",
                    "category": "main",
                    "optional": False,
                    "platform": "*",
                    "python-versions": "*",
                    "checksum": [],
                },
                {
                    "name": "pendulum",
                    "version": "2.0.0",
                    "description": "Pendulum package",
                    "category": "main",
                    "optional": False,
                    "platform": "*",
                    "python-versions": "*",
                    "checksum": [],
                },
            ],
            "metadata": {
                "python-versions": "*",
                "platform": "*",
                "content-hash": "123456789",
                "hashes": {"cachy": [], "pendulum": []},
            },
        }
    )

    tester.execute([("command", command.get_name()), ("--outdated", True)])

    expected = """\
cachy    0.1.0 0.2.0 Cachy package
"""

    assert tester.get_display(True) == expected
Пример #37
0
 def test_execute_for_application_command(self):
     application = Application()
     tester = CommandTester(application.get('help'))
     tester.execute([('command_name', 'list')])
     self.assertRegex(
         tester.get_display(),
         'list \[--raw\] \[namespace\]'
     )
Пример #38
0
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()
Пример #39
0
 def test_execute_for_command_alias(self):
     command = HelpCommand()
     command.set_application(Application())
     tester = CommandTester(command)
     tester.execute([('command_name', 'li')])
     self.assertRegex(
         tester.get_display(),
         'list \[--raw\] \[namespace\]'
     )
Пример #40
0
    def test_run_non_interactive(self):
        tester = CommandTester(TestCommand())

        tester.execute([], {'interactive': False})

        self.assertEqual(
            'execute called\n',
            tester.get_display()
        )
Пример #41
0
 def test_execute_for_command(self):
     command = HelpCommand()
     tester = CommandTester(command)
     command.set_command(ListCommand())
     tester.execute([])
     self.assertRegex(
         tester.get_display(),
         'list \[--raw\] \[namespace\]'
     )
Пример #42
0
    def test_as_text(self):
        command = TestCommand()
        command.set_application(Application())
        tester = CommandTester(command)
        tester.execute([('command', command.get_name())])

        self.assertEqual(
            self.open_fixture('command_astext.txt'),
            command.as_text()
        )
Пример #43
0
def test_about(app):
    command = app.find("check")
    tester = CommandTester(command)

    tester.execute([("command", command.get_name())])

    expected = """\
All set!
"""

    assert tester.get_display(True) == expected
Пример #44
0
def test_interactive_with_dependencies(app, repo, mocker, poetry):
    repo.add_package(get_package("pendulum", "2.0.0"))
    repo.add_package(get_package("pytest", "3.6.0"))

    command = app.find("init")
    command._pool = poetry.pool

    mocker.patch("poetry.utils._compat.Path.open")
    p = mocker.patch("poetry.utils._compat.Path.cwd")
    p.return_value = Path(__file__).parent

    tester = CommandTester(command)
    tester.set_inputs(
        [
            "my-package",  # Package name
            "1.2.3",  # Version
            "This is a description",  # Description
            "n",  # Author
            "MIT",  # License
            "~2.7 || ^3.6",  # Python
            "",  # Interactive packages
            "pendulum",  # Search for package
            "0",  # First option
            "",  # Do not set constraint
            "",  # Stop searching for packages
            "",  # Interactive dev packages
            "pytest",  # Search for package
            "0",
            "",
            "",
            "\n",  # Generate
        ]
    )
    tester.execute([("command", command.name)])

    output = tester.get_display(True)
    expected = """\
[tool.poetry]
name = "my-package"
version = "1.2.3"
description = "This is a description"
authors = ["Your Name <*****@*****.**>"]
license = "MIT"

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
pendulum = "^2.0"

[tool.poetry.dev-dependencies]
pytest = "^3.6"
"""

    assert expected in output
Пример #45
0
def test_show_basic_with_not_installed_packages_decorated(app, poetry, installed):
    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(cachy_010)
    poetry.locker.mock_lock_data(
        {
            "package": [
                {
                    "name": "cachy",
                    "version": "0.1.0",
                    "description": "Cachy package",
                    "category": "main",
                    "optional": False,
                    "platform": "*",
                    "python-versions": "*",
                    "checksum": [],
                },
                {
                    "name": "pendulum",
                    "version": "2.0.0",
                    "description": "Pendulum package",
                    "category": "main",
                    "optional": False,
                    "platform": "*",
                    "python-versions": "*",
                    "checksum": [],
                },
            ],
            "metadata": {
                "python-versions": "*",
                "platform": "*",
                "content-hash": "123456789",
                "hashes": {"cachy": [], "pendulum": []},
            },
        }
    )

    tester.execute([("command", command.get_name())], {"decorated": True})

    expected = """\
\033[32mcachy   \033[0m \033[36m0.1.0\033[0m Cachy package
\033[31mpendulum\033[0m \033[36m2.0.0\033[0m Pendulum package
"""

    assert tester.get_display(True) == expected
Пример #46
0
def test_display_single_setting(app, config):
    command = app.find("config")
    command._config = Config(config.file)
    tester = CommandTester(command)

    tester.execute(
        [("command", command.get_name()), ("key", "settings.virtualenvs.create")]
    )

    expected = """true
"""

    assert tester.get_display(True) == expected
Пример #47
0
def test_list_displays_default_value_if_not_set(app, config):
    command = app.find("config")
    command._config = Config(config.file)
    tester = CommandTester(command)

    tester.execute([("command", command.get_name()), ("--list", True)])

    expected = """settings.virtualenvs.create = true
settings.virtualenvs.in-project = false
settings.virtualenvs.path = "."
repositories = {}
"""

    assert tester.get_display(True) == expected
Пример #48
0
def test_about(app):
    command = app.find("about")
    tester = CommandTester(command)

    tester.execute([("command", command.get_name())])

    expected = """\
Poetry - Package Management for Python

Poetry is a dependency manager tracking local dependencies of your projects and libraries.
See https://github.com/sdispater/poetry for more information.

"""

    assert tester.get_display(True) == expected
Пример #49
0
def test_add_constraint_with_extras(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

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

    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()),
            ("name", ["cachy=0.2.0"]),
            ("--extras", ["msgpack"]),
        ]
    )

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 2 installs, 0 updates, 0 removals

Writing lock file

  - Installing msgpack-python (0.5.3)
  - Installing cachy (0.2.0)
"""

    assert tester.get_display(True) == expected

    assert len(installer.installs) == 2

    content = app.poetry.file.read()["tool"]["poetry"]

    assert "cachy" in content["dependencies"]
    assert content["dependencies"]["cachy"] == {
        "version": "0.2.0",
        "extras": ["msgpack"],
    }
Пример #50
0
def test_add_constraint_with_platform(app, repo, installer):
    platform = sys.platform
    command = app.find("add")
    tester = CommandTester(command)

    cachy2 = get_package("cachy", "0.2.0")

    repo.add_package(get_package("cachy", "0.1.0"))
    repo.add_package(cachy2)

    tester.execute(
        [
            ("command", command.get_name()),
            ("name", ["cachy=0.2.0"]),
            ("--platform", platform),
        ]
    )

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 1 install, 0 updates, 0 removals

Writing lock file

  - Installing cachy (0.2.0)
"""

    assert tester.get_display(True) == expected

    assert len(installer.installs) == 1

    content = app.poetry.file.read()["tool"]["poetry"]

    assert "cachy" in content["dependencies"]
    assert content["dependencies"]["cachy"] == {
        "version": "0.2.0",
        "platform": platform,
    }
Пример #51
0
    def test_set_code(self):
        command = TestCommand()
        ret = command.set_code(lambda in_, out_: out_.writeln('from the code...'))
        self.assertEqual(ret, command)

        tester = CommandTester(command)
        tester.execute([])
        self.assertEqual(
            'interact called\nfrom the code...\n',
            tester.get_display()
        )

        command = TestCommand()
        command.set_code(self.callable_method)
        tester = CommandTester(command)
        tester.execute([])
        self.assertEqual(
            'interact called\nfrom the code...\n',
            tester.get_display()
        )
Пример #52
0
def test_basic_interactive(app, mocker, poetry):
    command = app.find("init")
    command._pool = poetry.pool

    mocker.patch("poetry.utils._compat.Path.open")
    p = mocker.patch("poetry.utils._compat.Path.cwd")
    p.return_value = Path(__file__)

    tester = CommandTester(command)
    tester.set_inputs(
        [
            "my-package",  # Package name
            "1.2.3",  # Version
            "This is a description",  # Description
            "n",  # Author
            "MIT",  # License
            "~2.7 || ^3.6",  # Python
            "n",  # Interactive packages
            "n",  # Interactive dev packages
            "\n",  # Generate
        ]
    )
    tester.execute([("command", command.name)])

    output = tester.get_display(True)
    expected = """\
[tool.poetry]
name = "my-package"
version = "1.2.3"
description = "This is a description"
authors = ["Your Name <*****@*****.**>"]
license = "MIT"

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"

[tool.poetry.dev-dependencies]
"""

    assert expected in output
Пример #53
0
def test_add_file_constraint_sdist(app, repo, installer):
    command = app.find("add")
    tester = CommandTester(command)

    repo.add_package(get_package("pendulum", "1.4.4"))

    tester.execute(
        [
            ("command", command.get_name()),
            ("name", ["demo"]),
            ("--path", "../distributions/demo-0.1.0.tar.gz"),
        ]
    )

    expected = """\

Updating dependencies
Resolving dependencies...


Package operations: 2 installs, 0 updates, 0 removals

Writing lock file

  - Installing pendulum (1.4.4)
  - Installing demo (0.1.0)
"""

    assert tester.get_display(True) == expected

    assert len(installer.installs) == 2

    content = app.poetry.file.read()["tool"]["poetry"]

    assert "demo" in content["dependencies"]
    assert content["dependencies"]["demo"] == {
        "path": "../distributions/demo-0.1.0.tar.gz"
    }