From fc4ae2d53c7ffc877ad50028a6ec132951dfda58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Tue, 14 Apr 2020 16:14:58 +0200 Subject: [PATCH] Allow the develop property for git dependencies Co-authored-by: Fantix King --- poetry/core/json/schemas/poetry-schema.json | 4 + poetry/core/packages/package.py | 1 + poetry/core/packages/vcs_dependency.py | 6 + tests/fixtures/complete.toml | 45 ++++ .../demo-0.1.0-py2.py3-none-any.whl | Bin 0 -> 1116 bytes .../fixtures/distributions/demo-0.1.0.tar.gz | Bin 0 -> 961 bytes .../fixtures/invalid_pyproject/pyproject.toml | 11 + .../project_with_setup/my_package/__init__.py | 0 tests/fixtures/project_with_setup/setup.py | 19 ++ tests/fixtures/sample_project/README.rst | 2 + tests/fixtures/sample_project/pyproject.toml | 59 ++++++ tests/fixtures/simple_project/README.rst | 2 + .../dist/simple-project-1.2.3.tar.gz | Bin 0 -> 1106 bytes .../simple_project-1.2.3-py2.py3-none-any.whl | Bin 0 -> 1320 bytes tests/fixtures/simple_project/pyproject.toml | 25 +++ .../simple_project/simple_project/__init__.py | 0 tests/test_factory.py | 197 ++++++++++++++++++ 17 files changed, 371 insertions(+) create mode 100644 tests/fixtures/complete.toml create mode 100644 tests/fixtures/distributions/demo-0.1.0-py2.py3-none-any.whl create mode 100644 tests/fixtures/distributions/demo-0.1.0.tar.gz create mode 100644 tests/fixtures/invalid_pyproject/pyproject.toml create mode 100644 tests/fixtures/project_with_setup/my_package/__init__.py create mode 100644 tests/fixtures/project_with_setup/setup.py create mode 100644 tests/fixtures/sample_project/README.rst create mode 100644 tests/fixtures/sample_project/pyproject.toml create mode 100644 tests/fixtures/simple_project/README.rst create mode 100644 tests/fixtures/simple_project/dist/simple-project-1.2.3.tar.gz create mode 100644 tests/fixtures/simple_project/dist/simple_project-1.2.3-py2.py3-none-any.whl create mode 100644 tests/fixtures/simple_project/pyproject.toml create mode 100644 tests/fixtures/simple_project/simple_project/__init__.py create mode 100644 tests/test_factory.py diff --git a/poetry/core/json/schemas/poetry-schema.json b/poetry/core/json/schemas/poetry-schema.json index 10aff39e5..8397ba8ab 100644 --- a/poetry/core/json/schemas/poetry-schema.json +++ b/poetry/core/json/schemas/poetry-schema.json @@ -326,6 +326,10 @@ "items": { "type": "string" } + }, + "develop": { + "type": "boolean", + "description": "Whether to install the dependency in development mode." } } }, diff --git a/poetry/core/packages/package.py b/poetry/core/packages/package.py index d5c822d25..28488ff69 100644 --- a/poetry/core/packages/package.py +++ b/poetry/core/packages/package.py @@ -299,6 +299,7 @@ def add_dependency( rev=constraint.get("rev", None), category=category, optional=optional, + develop=constraint.get("develop", True), ) elif "file" in constraint: file_path = Path(constraint["file"]) diff --git a/poetry/core/packages/vcs_dependency.py b/poetry/core/packages/vcs_dependency.py index 119afb64a..fd1ea14a8 100644 --- a/poetry/core/packages/vcs_dependency.py +++ b/poetry/core/packages/vcs_dependency.py @@ -18,6 +18,7 @@ def __init__( rev=None, category="main", optional=False, + develop=False, ): self._vcs = vcs self._source = source @@ -29,6 +30,7 @@ def __init__( self._branch = branch self._tag = tag self._rev = rev + self._develop = develop super(VCSDependency, self).__init__( name, "*", category=category, optional=optional, allows_prereleases=True @@ -54,6 +56,10 @@ def tag(self): def rev(self): return self._rev + @property + def develop(self): # type: () -> bool + return self._develop + @property def reference(self): # type: () -> str return self._branch or self._tag or self._rev diff --git a/tests/fixtures/complete.toml b/tests/fixtures/complete.toml new file mode 100644 index 000000000..a894a89c6 --- /dev/null +++ b/tests/fixtures/complete.toml @@ -0,0 +1,45 @@ +[tool.poetry] +name = "poetry" +version = "0.5.0" +description = "Python dependency management and packaging made easy." +authors = [ + "Sébastien Eustace " +] +license = "MIT" + +readme = "README.rst" + +homepage = "https://python-poetry.org/" +repository = "https://github.com/python-poetry/poetry" +documentation = "https://python-poetry.org/docs" + +keywords = ["packaging", "dependency", "poetry"] + +# Requirements +[tool.poetry.dependencies] +python = "~2.7 || ^3.2" # Compatible python versions must be declared here +toml = "^0.9" +# Dependencies with extras +requests = { version = "^2.13", extras = [ "security" ] } +# Python specific dependencies with prereleases allowed +pathlib2 = { version = "^2.2", python = "~2.7", allows-prereleases = true } +# Git dependencies +cleo = { git = "https://github.com/sdispater/cleo.git", branch = "master" } + +# Optional dependencies (extras) +pendulum = { version = "^1.4", optional = true } + +[tool.poetry.extras] +time = [ "pendulum" ] + +[tool.poetry.dev-dependencies] +pytest = "^3.0" +pytest-cov = "^2.4" + +[tool.poetry.scripts] +my-script = 'my_package:main' + + +[[tool.poetry.source]] +name = "foo" +url = "https://bar.com" diff --git a/tests/fixtures/distributions/demo-0.1.0-py2.py3-none-any.whl b/tests/fixtures/distributions/demo-0.1.0-py2.py3-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..9e0805593b652818425370fb6973486b80c689ba GIT binary patch literal 1116 zcmWIWW@Zs#fB;2?Ca%JlVn7ZE3jlFSYHq%Me0*kJW=VX!UO{Did|7Hyab|vAe7u6K zg1Uj8p`L*{R{+!u4xkQ24~MBd?BPIG1Q1I>&Cms_)Jw@MF44`*OUu^}_i%Of;XUQZ z)u152dSUPK4@}Bw7Y=c|?Cw~x_2BZB8J(Wu_x9cU^;W##GF$EDf-Q4Dr?EH(3-*2! z6v@4|TW`lf9i`S~)1R%{@mVnUBG=|+pZj%pEdP4s(1IgpYfzoTp?0=Fijjfg7!w17 zEH3Bxx`sHqIEFY*op{&lu!BJB`|p~^;xY}rC%JKJYj%mTWb251t-9s&ILR#fyZamE zpECPqMBnyW5x&!U&gZ!^8+WR=t6KHUI~lQ3no-j~qOpr*$`X^`pOfc(m~nPbP{uW; z8*9Tv)^6Z>5L_5;vqvOHN&L!*qz%?eFx1YRk zJ&Vcu=J7sGYSYCM*&79iH2i;l5b68G*k4(%J!!AU_oM^A-|TYBei{@MVQ0F_XvLHq ztr-cyKMRaI9{l&ayJCy>`F2_9=5;pbt<28>k+pf7PJsL-9)HPtt7fKW8UHH1?^fOG z-Qss(kyEPp@<8Uo~0L;%gRjE z+Pb~5clO8^JbgWT9{0j?r#KS#{%^{>VZHAA4!{28CWoI@pZI_5{HiMl&+QJF|E*x- zSMjE`leWyY@Sf+#TQFzlpL~T)Ioy#!zHFg6S-39y>E~IgG0h4)%9v2b8sN>yB*Kh4w*UhI43;#4DD=F8(2YHxK=d*& zG%&hAbz{#p=;oj&aD+LRahU^4?&wCLM=Qc84Pfp8c?iQvkVp>jW@Q5@W&uJ_X47E? F@c^7EgWUiC literal 0 HcmV?d00001 diff --git a/tests/fixtures/distributions/demo-0.1.0.tar.gz b/tests/fixtures/distributions/demo-0.1.0.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..133b64421f86ad26448e0b0f27be33df6808c14c GIT binary patch literal 961 zcmV;y13vs8iwFpsLE~Ej|72xtZ!It`F)lDJbYXG;?N{Ay+cp^WHJ^ghF4P(kBhj*) zXmik^>(*gg8ni%fGEZP_#^WN18bxI>((Qfr9DA{Tq~yeQ(jgvF@25OBCJ#UUisyVZ z*(du?PT1vh&SqToJ_y1V@B0nIL3~p-d=$k)+QXN<9iXW-Q!xEQZ}L9^dVmWp3OLwZOCG)j_$qMpP59y4CZAS4k9_f2s>%S0)3mXT`lp!!eZ`2G5)$%g(1NtE<( z==A@=k!2TL)k2n8hR4{qH^Fzx|7bv5{&)Gm&Hr(f&@iGQIT(gA2Ca7cuhi8CiZiR=smw_Sd4e`*7 z*Ha}b-LW2Gjs8ih8Y-vWt3UsE!)h&fiJzHMopStn%{%G|Zz&?=kvBnTbzU;#6)$JJ zoC;n~P_=+D?fAb_GQw});vWYj_K=Bb@}@8?N8^aZhMeYH0&%sn*1orgrClS-p{`ZK ze?#UP$+zOEV#C;0;r@+Kqe1mM(%@+v2rZfCt-wv;5cTzvjBB z9`fCPPyI)fh8y~)bQC)M?*gCVpda9=oQZOt;zpkZ2ZljsN)~t~YTam&*JLUc$D*jD z(%9Y;geo>YXLD|}{{uSp%|-Gj*K{^xn%Sl+-%s(W-}fgVEm6X8=Xs|1FO5*wotM(? zWNpT2b+-)cMgrB@!8+CXlRfN%FfC_1m4sq+maz^XXtHb$6V{q#|{K**Hjr7|>v@FnNVLmJG0 zJw^zkE(9dJ;F-w*DTefWi-Yug^YOlf2SbWYCjP9=8+Z)wT?p|uW3C_bkGh=ycr&8Q j@v8&D{GQ7Y4h{|u4h{|u4h{|ue+%yb(`BL(04M+eDE0Bh literal 0 HcmV?d00001 diff --git a/tests/fixtures/invalid_pyproject/pyproject.toml b/tests/fixtures/invalid_pyproject/pyproject.toml new file mode 100644 index 000000000..06a8e27da --- /dev/null +++ b/tests/fixtures/invalid_pyproject/pyproject.toml @@ -0,0 +1,11 @@ +[tool.poetry] +name = "invalid" +version = "1.0.0" +authors = [ + "Foo " +] +license = "INVALID" + +[tool.poetry.dependencies] +python = "*" +pendulum = {"version" = "^2.0.5", allows-prereleases = true} diff --git a/tests/fixtures/project_with_setup/my_package/__init__.py b/tests/fixtures/project_with_setup/my_package/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/fixtures/project_with_setup/setup.py b/tests/fixtures/project_with_setup/setup.py new file mode 100644 index 000000000..71b3074d8 --- /dev/null +++ b/tests/fixtures/project_with_setup/setup.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +from setuptools import setup + + +kwargs = dict( + name="my-package", + license="MIT", + version="0.1.2", + description="Demo project.", + author="Sébastien Eustace", + author_email="sebastien@eustace.io", + url="https://github.com/demo/demo", + packages=["my_package"], + install_requires=["pendulum>=1.4.4", "cachy[msgpack]>=0.2.0"], +) + + +setup(**kwargs) diff --git a/tests/fixtures/sample_project/README.rst b/tests/fixtures/sample_project/README.rst new file mode 100644 index 000000000..f7fe15470 --- /dev/null +++ b/tests/fixtures/sample_project/README.rst @@ -0,0 +1,2 @@ +My Package +========== diff --git a/tests/fixtures/sample_project/pyproject.toml b/tests/fixtures/sample_project/pyproject.toml new file mode 100644 index 000000000..a26d33087 --- /dev/null +++ b/tests/fixtures/sample_project/pyproject.toml @@ -0,0 +1,59 @@ +[tool.poetry] +name = "my-package" +version = "1.2.3" +description = "Some description." +authors = [ + "Sébastien Eustace " +] +license = "MIT" + +readme = "README.rst" + +homepage = "https://python-poetry.org" +repository = "https://github.com/python-poetry/poetry" +documentation = "https://python-poetry.org/docs" + +keywords = ["packaging", "dependency", "poetry"] + +classifiers = [ + "Topic :: Software Development :: Build Tools", + "Topic :: Software Development :: Libraries :: Python Modules" +] + +# Requirements +[tool.poetry.dependencies] +python = "~2.7 || ^3.6" +cleo = "^0.6" +pendulum = { git = "https://github.com/sdispater/pendulum.git", branch = "2.0" } +tomlkit = { git = "https://github.com/sdispater/tomlkit.git", rev = "3bff550", develop = false } +requests = { version = "^2.18", optional = true, extras=[ "security" ] } +pathlib2 = { version = "^2.2", python = "~2.7" } + +orator = { version = "^0.9", optional = true } + +# File dependency +demo = { path = "../distributions/demo-0.1.0-py2.py3-none-any.whl" } + +# Dir dependency with setup.py +my-package = { path = "../project_with_setup/" } + +# Dir dependency with pyproject.toml +simple-project = { path = "../simple_project/" } + +# Dependency with markers +functools32 = { version = "^3.2.3", markers = "python_version ~= '2.7' and sys_platform == 'win32' or python_version in '3.4 3.5'" } + + +[tool.poetry.extras] +db = [ "orator" ] + +[tool.poetry.dev-dependencies] +pytest = "~3.4" + + +[tool.poetry.scripts] +my-script = "my_package:main" + + +[tool.poetry.plugins."blogtool.parsers"] +".rst" = "some_module::SomeClass" diff --git a/tests/fixtures/simple_project/README.rst b/tests/fixtures/simple_project/README.rst new file mode 100644 index 000000000..f7fe15470 --- /dev/null +++ b/tests/fixtures/simple_project/README.rst @@ -0,0 +1,2 @@ +My Package +========== diff --git a/tests/fixtures/simple_project/dist/simple-project-1.2.3.tar.gz b/tests/fixtures/simple_project/dist/simple-project-1.2.3.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..149aa9527c577a1828a5a3114377960fd1e41a88 GIT binary patch literal 1106 zcmV-Y1g-lYiwFpPU6EV@|8r?=aBO8QaB^>IWn*+LF)lJLGcI&tascgF+j84B5cM;@ z0%ac9YD9<^QSxxAOx)UOJh2ju<@Uu^IW!5&s7ZnaKqs1{{hxkEf2;s6x;gSxX{=6c z?u&rME{N;y!4c}9&Wlm-{uK@)%=R8c%u+V}nx@lTl$GAHx~{zk-|y`}axMZUKmVmC z`IU&h4--KWJg{8b?OS%&>7m}fZS}2vu-C|=7fzBa#zw~IZ#Wc&g>2+>PLB=_hewEU z@x|_cuiM>x|Lxw|{qNen-X1iY`~ToFoWW5L-UL$&26Jg{{*w{ZPpUtW|5;Tb)I{#aiWv|_T*R{+h|L;Q11*I{{C>Crs0cnt6IDp#f zsnEbJW}MJeH5DgB0}VkiFL0?sgg)261jHo7DK7>yJU-I^U@}3KgIl0eslJvU&LnzK4c9_s-0O78*`P&_ zn)J>nCxWusvf-47>--XhH0kh&@GKCRRo-%jG|Us6ilCn3#_l`Pl*_T);MqIMqGHNg zR-h`9PPI1FBAnqg!f7~DwdxBK0Kz!noLmvSyiR8{BO&xWIHp(PUBECr#J4!6nHr7K z|B#b7f@gB$xYqucJ}2ao1&m;>Dx;a)niLLcl*gE>>`Ahv9$L z%T~W{^&9;6|Ls2(dG@)x{TcZG&i;4hQ?%LtUC1+NvRf|b-_g~IU>1V<%WIRYAtWvcMV2(jQM}``X}S~ z&C9ntivO;){{N5DH?1cA??Q%H1S)bEzm&1ngEq3j8ySW@xOz6g+@d%nV4NpOz-Eea zSPQq{mDCuDmGR)lI0p`jpefz&gw?9aDB`Ic#wVgFcwKQVb^Md*tG!@Z+U4g!#c6P( zWIR0hAHpE`aZc7KI;EtiJP*DdAH#!8F48TIRDF1SRyVJ>j2NA=AW7s%;YpBAbH!RM z$QW6&x3x$8Ej^rV?NM)QkJT}4LuPH~cn_lmMpZcb`Siqths#7>8{SXjt-7AhX~Tuz YJ)~ii4I62sk*`Sp0Yvm`6-N>XJOp~G}oyk*lXPObG5#*WWk@{`yV1s9qYzEQ?elykxsK41Y&2W}A^T~6C!g167 z-2T=U|EnbV`-0v7x7-e>Q;lR_)3n9x?aAqvLVb6w>AN5OI>2z6{y8_TwB(}*Z(W==luI(_)Q!&nz;>Z%q|0?*9aKZs)VCC$ko|D$ffn% z-l8T028IWB(>(=}7aEj2Q1@DSfk}{WnvBPUB~6x0wy!Uj7rl7GUGrVj?gaPZqFr2N zv#wA1H1YhDtWV-A_PMqF{PyY9V;3&%g3VGvpX@{~aM*5B(fKRaV=*Z)@a^{6ZEyM< z;#bzo-O2E{ouwOY{3N+NR-Exzdwb7wySHxP5`Hn;uGXHK-nC<=#2e^+p@?tBR)>y!lzn9LWgCBBW%jf$D$`EwD8_v2D|n5o-6X;SpSZ5 z!^O*$U3<@8VNdu9O#F;YBFwmRG%#quU`Zp0!kxd-%)!Xt5K|Z!8W^oG%)y@9(M?3p ymusw3=9CGeCVeD literal 0 HcmV?d00001 diff --git a/tests/fixtures/simple_project/pyproject.toml b/tests/fixtures/simple_project/pyproject.toml new file mode 100644 index 000000000..72d0c0bee --- /dev/null +++ b/tests/fixtures/simple_project/pyproject.toml @@ -0,0 +1,25 @@ +[tool.poetry] +name = "simple-project" +version = "1.2.3" +description = "Some description." +authors = [ + "Sébastien Eustace " +] +license = "MIT" + +readme = "README.rst" + +homepage = "https://python-poetry.org" +repository = "https://github.com/python-poetry/poetry" +documentation = "https://python-poetry.org/docs" + +keywords = ["packaging", "dependency", "poetry"] + +classifiers = [ + "Topic :: Software Development :: Build Tools", + "Topic :: Software Development :: Libraries :: Python Modules" +] + +# Requirements +[tool.poetry.dependencies] +python = "~2.7 || ^3.4" diff --git a/tests/fixtures/simple_project/simple_project/__init__.py b/tests/fixtures/simple_project/simple_project/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_factory.py b/tests/test_factory.py new file mode 100644 index 000000000..af15b627f --- /dev/null +++ b/tests/test_factory.py @@ -0,0 +1,197 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import +from __future__ import unicode_literals + +import pytest + +from poetry.core.factory import Factory +from poetry.core.utils._compat import PY2 +from poetry.core.utils._compat import Path +from poetry.core.utils.toml_file import TomlFile + + +fixtures_dir = Path(__file__).parent / "fixtures" + + +def test_create_poetry(): + poetry = Factory().create_poetry(fixtures_dir / "sample_project") + + package = poetry.package + + assert package.name == "my-package" + assert package.version.text == "1.2.3" + assert package.description == "Some description." + assert package.authors == ["Sébastien Eustace "] + assert package.license.id == "MIT" + assert ( + package.readme.relative_to(fixtures_dir).as_posix() + == "sample_project/README.rst" + ) + assert package.homepage == "https://python-poetry.org" + assert package.repository_url == "https://github.com/python-poetry/poetry" + assert package.keywords == ["packaging", "dependency", "poetry"] + + assert package.python_versions == "~2.7 || ^3.6" + assert str(package.python_constraint) == ">=2.7,<2.8 || >=3.6,<4.0" + + dependencies = {} + for dep in package.requires: + dependencies[dep.name] = dep + + cleo = dependencies["cleo"] + assert cleo.pretty_constraint == "^0.6" + assert not cleo.is_optional() + + pendulum = dependencies["pendulum"] + assert pendulum.pretty_constraint == "branch 2.0" + assert pendulum.is_vcs() + assert pendulum.vcs == "git" + assert pendulum.branch == "2.0" + assert pendulum.source == "https://github.com/sdispater/pendulum.git" + assert pendulum.allows_prereleases() + assert pendulum.develop + + tomlkit = dependencies["tomlkit"] + assert tomlkit.pretty_constraint == "rev 3bff550" + assert tomlkit.is_vcs() + assert tomlkit.vcs == "git" + assert tomlkit.rev == "3bff550" + assert tomlkit.source == "https://github.com/sdispater/tomlkit.git" + assert tomlkit.allows_prereleases() + assert not tomlkit.develop + + requests = dependencies["requests"] + assert requests.pretty_constraint == "^2.18" + assert not requests.is_vcs() + assert not requests.allows_prereleases() + assert requests.is_optional() + assert requests.extras == ["security"] + + pathlib2 = dependencies["pathlib2"] + assert pathlib2.pretty_constraint == "^2.2" + assert pathlib2.python_versions == "~2.7" + assert not pathlib2.is_optional() + + demo = dependencies["demo"] + assert demo.is_file() + assert not demo.is_vcs() + assert demo.name == "demo" + assert demo.pretty_constraint == "*" + + demo = dependencies["my-package"] + assert not demo.is_file() + assert demo.is_directory() + assert not demo.is_vcs() + assert demo.name == "my-package" + assert demo.pretty_constraint == "*" + + simple_project = dependencies["simple-project"] + assert not simple_project.is_file() + assert simple_project.is_directory() + assert not simple_project.is_vcs() + assert simple_project.name == "simple-project" + assert simple_project.pretty_constraint == "*" + + functools32 = dependencies["functools32"] + assert functools32.name == "functools32" + assert functools32.pretty_constraint == "^3.2.3" + assert ( + str(functools32.marker) + == 'python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5"' + ) + + assert "db" in package.extras + + classifiers = package.classifiers + + assert classifiers == [ + "Topic :: Software Development :: Build Tools", + "Topic :: Software Development :: Libraries :: Python Modules", + ] + + assert package.all_classifiers == [ + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Topic :: Software Development :: Build Tools", + "Topic :: Software Development :: Libraries :: Python Modules", + ] + + +def test_create_poetry_with_packages_and_includes(): + poetry = Factory().create_poetry( + fixtures_dir.parent / "masonry" / "builders" / "fixtures" / "with-include" + ) + + package = poetry.package + + assert package.packages == [ + {"include": "extra_dir/**/*.py"}, + {"include": "extra_dir/**/*.py"}, + {"include": "my_module.py"}, + {"include": "package_with_include"}, + {"include": "tests", "format": "sdist"}, + {"include": "for_wheel_only", "format": ["wheel"]}, + {"include": "src_package", "from": "src"}, + ] + + assert package.include == ["extra_dir/vcs_excluded.txt", "notes.txt"] + + +def test_create_poetry_with_multi_constraints_dependency(): + poetry = Factory().create_poetry( + fixtures_dir / "project_with_multi_constraints_dependency" + ) + + package = poetry.package + + assert len(package.requires) == 2 + + +def test_validate(): + complete = TomlFile(fixtures_dir / "complete.toml") + content = complete.read()["tool"]["poetry"] + + assert Factory.validate(content) == {"errors": [], "warnings": []} + + +def test_validate_fails(): + complete = TomlFile(fixtures_dir / "complete.toml") + content = complete.read()["tool"]["poetry"] + content["this key is not in the schema"] = "" + + if PY2: + expected = ( + "Additional properties are not allowed " + "(u'this key is not in the schema' was unexpected)" + ) + else: + expected = ( + "Additional properties are not allowed " + "('this key is not in the schema' was unexpected)" + ) + + assert Factory.validate(content) == {"errors": [expected], "warnings": []} + + +def test_create_poetry_fails_on_invalid_configuration(): + with pytest.raises(RuntimeError) as e: + Factory().create_poetry( + Path(__file__).parent / "fixtures" / "invalid_pyproject" / "pyproject.toml" + ) + + if PY2: + expected = """\ +The Poetry configuration is invalid: + - u'description' is a required property +""" + else: + expected = """\ +The Poetry configuration is invalid: + - 'description' is a required property +""" + assert expected == str(e.value)