Skip to content

Commit

Permalink
Add tests for invalid TOML files
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzymadness committed Jan 12, 2022
1 parent 0a6e8b3 commit 1eb49a9
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ repos:
rev: v3.3.0
hooks:
- id: check-toml
exclude: 'tests/data/install/invalid_*'
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
Expand Down
1 change: 1 addition & 0 deletions tests/data/install/invalid_pipfile/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
completely invalid pipfile
35 changes: 35 additions & 0 deletions tests/data/install/invalid_pipfile/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/data/install/invalid_poetry_lock/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions tests/data/install/invalid_poetry_lock/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
name = "test-micropipenv"
version = "0.1.0"
description = ""
authors = ["Fridolin Pokorny <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.7"
micropipenv = {version = "0.0.1", optional = true}
selinon = {version = "1.0.0", extras = ["s3", "postgres"]}
daiquiri = {git = "https://github.com/jd/daiquiri", rev = "2.1.0"}

[tool.poetry.dev-dependencies]
hexsticker = "^1.2.0"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
23 changes: 23 additions & 0 deletions tests/data/install/invalid_pyproject_toml/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/data/install/invalid_pyproject_toml/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
completely invalid pyproject.toml file
20 changes: 20 additions & 0 deletions tests/test_micropipenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,26 @@ def test_install_pipenv_iter_index(venv):
assert str(venv.get_version("requests")) == "2.22.0"


@pytest.mark.parametrize(
"directory, filename, method",
[
["invalid_pipfile", "Pipfile", "pipenv"],
["invalid_poetry_lock", "poetry.lock", "poetry"],
["invalid_pyproject_toml", "pyproject.toml", "poetry"],
],
)
def test_install_invalid_toml_file(venv, directory, filename, method):
"""Test exception when a Pipfile is not a valid TOML."""
venv.install(MICROPIPENV_TEST_TOML_MODULE)
cmd = [os.path.join(venv.path, BIN_DIR, "python"), micropipenv.__file__, "install", "--deploy", "--method", method]
work_dir = os.path.join(_DATA_DIR, "install", directory)
with cwd(work_dir):
with pytest.raises(subprocess.CalledProcessError) as exception:
subprocess.check_output(cmd, env=get_updated_env(venv), stderr=subprocess.PIPE, universal_newlines=True)

assert f"FileReadError: Failed to parse {filename}: " in exception.value.stderr


def test_parse_requirements2pipfile_lock():
"""Test parsing of requirements.txt into their Pipfile.lock representation."""
work_dir = os.path.join(_DATA_DIR, "parse", "pip-tools")
Expand Down

0 comments on commit 1eb49a9

Please sign in to comment.