Skip to content
This repository has been archived by the owner on Oct 12, 2024. It is now read-only.

Commit

Permalink
✅ Update tests with improved logs
Browse files Browse the repository at this point in the history
  • Loading branch information
tiangolo committed May 27, 2021
1 parent 2887104 commit 86e0249
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def test_defaults(tmp_path: Path):
result = build_package(testing_dir=testing_dir)

assert (
"Using __init__.py file at test_custom_version/__init__.py for dynamic version"
in result.stdout
"poetry-version-plugin: Using __init__.py file at "
"test_custom_version/__init__.py for dynamic version" in result.stdout
)
assert (
"Setting package dynamic version to __version__ variable from __init__.py: 0.0.1"
in result.stdout
"poetry-version-plugin: Setting package dynamic version to __version__ "
"variable from __init__.py: 0.0.1" in result.stdout
)
assert "Built test_custom_version-0.0.1-py3-none-any.whl" in result.stdout
wheel_path = testing_dir / "dist" / "test_custom_version-0.0.1-py3-none-any.whl"
Expand All @@ -60,12 +60,12 @@ def test_custom_packages(tmp_path: Path):
copy_assets("custom_packages", testing_dir)
result = build_package(testing_dir=testing_dir)
assert (
"Using __init__.py file at custom_package/__init__.py for dynamic version"
in result.stdout
"poetry-version-plugin: Using __init__.py file at custom_package/__init__.py "
"for dynamic version" in result.stdout
)
assert (
"Setting package dynamic version to __version__ variable from __init__.py: 0.0.2"
in result.stdout
"poetry-version-plugin: Setting package dynamic version to __version__ "
"variable from __init__.py: 0.0.2" in result.stdout
)
assert "Built test_custom_version-0.0.2-py3-none-any.whl" in result.stdout
wheel_path = testing_dir / "dist" / "test_custom_version-0.0.2-py3-none-any.whl"
Expand All @@ -78,12 +78,12 @@ def test_variations(tmp_path: Path):
copy_assets("variations", testing_dir)
result = build_package(testing_dir=testing_dir)
assert (
"Using __init__.py file at test_custom_version/__init__.py for dynamic version"
in result.stdout
"poetry-version-plugin: Using __init__.py file at "
"test_custom_version/__init__.py for dynamic version" in result.stdout
)
assert (
"Setting package dynamic version to __version__ variable from __init__.py: 0.0.3"
in result.stdout
"poetry-version-plugin: Setting package dynamic version to __version__ "
"variable from __init__.py: 0.0.3" in result.stdout
)
assert "Built test_custom_version-0.0.3-py3-none-any.whl" in result.stdout
wheel_path = testing_dir / "dist" / "test_custom_version-0.0.3-py3-none-any.whl"
Expand All @@ -96,8 +96,8 @@ def test_no_version_var(tmp_path: Path):
copy_assets("no_version_var", testing_dir)
result = build_package(testing_dir=testing_dir)
assert (
"No valid __version__ variable found in __init__.py, cannot extract dynamic version"
in result.stderr
"poetry-version-plugin: No valid __version__ variable found in __init__.py, "
"cannot extract dynamic version" in result.stderr
)
assert result.returncode != 0

Expand All @@ -106,15 +106,18 @@ def test_no_standard_dir(tmp_path: Path):
testing_dir = tmp_path / "testing_package"
copy_assets("no_standard_dir", testing_dir)
result = build_package(testing_dir=testing_dir)
assert "__init__.py file not found at" in result.stderr
assert "poetry-version-plugin: __init__.py file not found at" in result.stderr
assert result.returncode != 0


def test_multiple_packages(tmp_path: Path):
testing_dir = tmp_path / "testing_package"
copy_assets("multiple_packages", testing_dir)
result = build_package(testing_dir=testing_dir)
assert "More than one package set, cannot extract dynamic version" in result.stderr
assert (
"poetry-version-plugin: More than one package set, cannot extract "
"dynamic version" in result.stderr
)
assert result.returncode != 0


Expand All @@ -131,8 +134,8 @@ def test_no_config_source(tmp_path: Path):
copy_assets("no_config_source", testing_dir)
result = build_package(testing_dir=testing_dir)
assert (
"No source configuration found in [tool.poetry-version-plugin] "
"in pyproject.toml, not extracting dynamic version"
"poetry-version-plugin: No source configuration found in "
"[tool.poetry-version-plugin] in pyproject.toml, not extracting dynamic version"
) in result.stderr
assert result.returncode != 0

Expand Down Expand Up @@ -199,7 +202,10 @@ def test_git_tag(tmp_path: Path):
)
assert result.returncode == 0
result = build_package(testing_dir=testing_dir)
assert "Git tag found, setting dynamic version to: 0.0.9" in result.stdout
assert (
"poetry-version-plugin: Git tag found, setting dynamic version to: 0.0.9"
in result.stdout
)
assert "Built test_custom_version-0.0.9-py3-none-any.whl" in result.stdout
wheel_path = testing_dir / "dist" / "test_custom_version-0.0.9-py3-none-any.whl"
info = pkginfo.get_metadata(str(wheel_path))
Expand Down

0 comments on commit 86e0249

Please sign in to comment.