Commit 434e5409 by Sébastien Eustace Committed by Sébastien Eustace

Fix adding dependency to missing section

Issue #61
parent ad834e29
......@@ -54,6 +54,9 @@ If you do not specify a version constraint, poetry will choose a suitable one ba
content = self.poetry.file.read()
poetry_content = content["tool"]["poetry"]
if section not in poetry_content:
poetry_content[section] = {}
for name in packages:
for key in poetry_content[section]:
if key.lower() == name.lower():
......
......@@ -382,3 +382,38 @@ Writing lock file
"version": "0.2.0",
"platform": platform,
}
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(
[("command", command.get_name()), ("name", ["cachy"]), ("--dev", True)]
)
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["dev-dependencies"]
assert content["dev-dependencies"]["cachy"] == "^0.2.0"
......@@ -23,5 +23,3 @@ classifiers = [
# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
[tool.poetry.dev-dependencies]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment