-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add 2 type stubs * add typing to poetry * fix test * add another unit test
- Loading branch information
1 parent
2882bfc
commit 084a94a
Showing
4 changed files
with
304 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,10 @@ | |
|
||
from codemodder.codetf import DiffSide | ||
from codemodder.dependency import DefusedXML, Security | ||
from codemodder.dependency_management.pyproject_writer import PyprojectWriter | ||
from codemodder.dependency_management.pyproject_writer import ( | ||
TYPE_CHECKER_LIBRARIES, | ||
PyprojectWriter, | ||
) | ||
from codemodder.project_analysis.file_parsers.package_store import ( | ||
FileType, | ||
PackageStore, | ||
|
@@ -408,3 +411,195 @@ def test_pyproject_poetry_no_declared_deps(tmpdir): | |
""" | ||
|
||
assert pyproject_toml.read() == dedent(updated_pyproject) | ||
|
||
|
||
@pytest.mark.parametrize("type_checker", TYPE_CHECKER_LIBRARIES) | ||
def test_pyproject_poetry_with_type_checker_tool(tmpdir, type_checker): | ||
orig_pyproject = f"""\ | ||
[tool.poetry] | ||
name = "example-project" | ||
version = "0.1.0" | ||
description = "An example project to demonstrate Poetry configuration." | ||
authors = ["Your Name <[email protected]>"] | ||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
[tool.poetry.dependencies] | ||
python = "~=3.11.0" | ||
requests = ">=2.25.1,<3.0.0" | ||
pandas = "^1.2.3" | ||
libcst = ">1.0" | ||
{type_checker} = "==1.0" | ||
""" | ||
|
||
pyproject_toml = tmpdir.join("pyproject.toml") | ||
pyproject_toml.write(dedent(orig_pyproject)) | ||
|
||
store = PackageStore( | ||
type=FileType.TOML, | ||
file=pyproject_toml, | ||
dependencies=set(), | ||
py_versions=["~=3.11.0"], | ||
) | ||
|
||
writer = PyprojectWriter(store, tmpdir) | ||
dependencies = [Security, DefusedXML] | ||
writer.write(dependencies) | ||
|
||
defusedxml_type_stub = DefusedXML.type_stubs[0] | ||
updated_pyproject = f"""\ | ||
[tool.poetry] | ||
name = "example-project" | ||
version = "0.1.0" | ||
description = "An example project to demonstrate Poetry configuration." | ||
authors = ["Your Name <[email protected]>"] | ||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
[tool.poetry.dependencies] | ||
python = "~=3.11.0" | ||
requests = ">=2.25.1,<3.0.0" | ||
pandas = "^1.2.3" | ||
libcst = ">1.0" | ||
{type_checker} = "==1.0" | ||
{Security.requirement.name} = "{str(Security.requirement.specifier)}" | ||
{DefusedXML.requirement.name} = "{str(DefusedXML.requirement.specifier)}" | ||
{defusedxml_type_stub.requirement.name} = "{str(defusedxml_type_stub.requirement.specifier)}" | ||
""" | ||
|
||
assert pyproject_toml.read() == dedent(updated_pyproject) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"dependency_section", | ||
[ | ||
"[tool.poetry.test.dependencies]", | ||
"[tool.poetry.dev-dependencies]", | ||
"[tool.poetry.dev.dependencies]", | ||
"[tool.poetry.group.test.dependencies]", | ||
], | ||
) | ||
@pytest.mark.parametrize("type_checker", TYPE_CHECKER_LIBRARIES) | ||
def test_pyproject_poetry_with_type_checker_tool_without_poetry_deps_section( | ||
tmpdir, type_checker, dependency_section | ||
): | ||
orig_pyproject = f"""\ | ||
[tool.poetry] | ||
name = "example-project" | ||
version = "0.1.0" | ||
description = "An example project to demonstrate Poetry configuration." | ||
authors = ["Your Name <[email protected]>"] | ||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
{dependency_section} | ||
{type_checker} = "==1.0" | ||
""" | ||
|
||
pyproject_toml = tmpdir.join("pyproject.toml") | ||
pyproject_toml.write(dedent(orig_pyproject)) | ||
|
||
store = PackageStore( | ||
type=FileType.TOML, | ||
file=pyproject_toml, | ||
dependencies=set(), | ||
py_versions=["~=3.11.0"], | ||
) | ||
|
||
writer = PyprojectWriter(store, tmpdir) | ||
dependencies = [Security, DefusedXML] | ||
writer.write(dependencies) | ||
|
||
defusedxml_type_stub = DefusedXML.type_stubs[0] | ||
updated_pyproject = f"""\ | ||
[tool.poetry] | ||
name = "example-project" | ||
version = "0.1.0" | ||
description = "An example project to demonstrate Poetry configuration." | ||
authors = ["Your Name <[email protected]>"] | ||
[tool.poetry.dependencies] | ||
{Security.requirement.name} = "{str(Security.requirement.specifier)}" | ||
{DefusedXML.requirement.name} = "{str(DefusedXML.requirement.specifier)}" | ||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
{dependency_section} | ||
{type_checker} = "==1.0" | ||
{defusedxml_type_stub.requirement.name} = "{str(defusedxml_type_stub.requirement.specifier)}" | ||
""" | ||
|
||
assert pyproject_toml.read() == dedent(updated_pyproject) | ||
|
||
|
||
@pytest.mark.parametrize("type_checker", TYPE_CHECKER_LIBRARIES) | ||
def test_pyproject_poetry_with_type_checker_tool_multiple(tmpdir, type_checker): | ||
orig_pyproject = f"""\ | ||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
[tool.poetry] | ||
name = "example-project" | ||
version = "0.1.0" | ||
description = "An example project to demonstrate Poetry configuration." | ||
authors = ["Your Name <[email protected]>"] | ||
[tool.poetry.dependencies] | ||
python = "~=3.11.0" | ||
requests = ">=2.25.1,<3.0.0" | ||
pandas = "^1.2.3" | ||
libcst = ">1.0" | ||
[tool.poetry.group.test.dependencies] | ||
{type_checker} = "==1.0" | ||
""" | ||
|
||
pyproject_toml = tmpdir.join("pyproject.toml") | ||
pyproject_toml.write(dedent(orig_pyproject)) | ||
|
||
store = PackageStore( | ||
type=FileType.TOML, | ||
file=pyproject_toml, | ||
dependencies=set(), | ||
py_versions=["~=3.11.0"], | ||
) | ||
|
||
writer = PyprojectWriter(store, tmpdir) | ||
dependencies = [Security, DefusedXML] | ||
writer.write(dependencies) | ||
|
||
defusedxml_type_stub = DefusedXML.type_stubs[0] | ||
updated_pyproject = f"""\ | ||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
[tool.poetry] | ||
name = "example-project" | ||
version = "0.1.0" | ||
description = "An example project to demonstrate Poetry configuration." | ||
authors = ["Your Name <[email protected]>"] | ||
[tool.poetry.dependencies] | ||
python = "~=3.11.0" | ||
requests = ">=2.25.1,<3.0.0" | ||
pandas = "^1.2.3" | ||
libcst = ">1.0" | ||
{Security.requirement.name} = "{str(Security.requirement.specifier)}" | ||
{DefusedXML.requirement.name} = "{str(DefusedXML.requirement.specifier)}" | ||
[tool.poetry.group.test.dependencies] | ||
{type_checker} = "==1.0" | ||
{defusedxml_type_stub.requirement.name} = "{str(defusedxml_type_stub.requirement.specifier)}" | ||
""" | ||
|
||
assert pyproject_toml.read() == dedent(updated_pyproject) |