Skip to content

Commit

Permalink
test(version): set version file as ignored file
Browse files Browse the repository at this point in the history
Tweaks tests to use one committed change file and the version file
as an ignored change file. This allows us to verify that our commit
mechanism does not crash if a file that is changed is ignored by user
  • Loading branch information
codejedi365 committed Dec 7, 2023
1 parent 35a7bd4 commit 814a20e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
10 changes: 5 additions & 5 deletions tests/command_line/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def test_version_no_push_force_level(
expected_new_version,
example_project,
example_pyproject_toml,
tmp_path_factory,
tmp_path_factory: "pytest.TempPathFactory",
cli_runner,
):
tempdir = tmp_path_factory.mktemp("test_version")
Expand All @@ -415,7 +415,7 @@ def test_version_no_push_force_level(
# Changelog already reflects changes this should introduce
assert differing_files == [
"pyproject.toml",
f"src/{EXAMPLE_PROJECT_NAME}/__init__.py",
f"src/{EXAMPLE_PROJECT_NAME}/_version.py",
]

# Compare pyproject.toml
Expand All @@ -434,14 +434,14 @@ def test_version_no_push_force_level(
assert old_pyproject_toml == new_pyproject_toml
assert new_version == expected_new_version

# Compare __init__.py
# Compare _version.py
new_init_py = (
(example_project / "src" / EXAMPLE_PROJECT_NAME / "__init__.py")
(example_project / "src" / EXAMPLE_PROJECT_NAME / "_version.py")
.read_text(encoding="utf-8")
.splitlines(keepends=True)
)
old_init_py = (
(tempdir / "src" / EXAMPLE_PROJECT_NAME / "__init__.py")
(tempdir / "src" / EXAMPLE_PROJECT_NAME / "_version.py")
.read_text(encoding="utf-8")
.splitlines(keepends=True)
)
Expand Down
2 changes: 1 addition & 1 deletion tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
[tool.semantic_release]
version_variables = [
"src/{EXAMPLE_PROJECT_NAME}/__init__.py:__version__",
"src/{EXAMPLE_PROJECT_NAME}/_version.py:__version__",
]
version_toml = ["pyproject.toml:tool.poetry.version"]
build_command = "bash -c \"echo 'Hello World'\""
Expand Down
23 changes: 20 additions & 3 deletions tests/fixtures/example_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def cd(path: Path) -> Generator[Path, None, None]:


@pytest.fixture
def example_project(tmp_path):
def example_project(tmp_path: "Path") -> "Generator[Path, None, None]":
with cd(tmp_path):
src_dir = tmp_path / "src"
src_dir.mkdir()
Expand All @@ -35,18 +35,35 @@ def example_project(tmp_path):
init_py = example_dir / "__init__.py"
init_py.write_text(
dedent(
f'''
'''
"""
An example package with a very informative docstring
"""
__version__ = "{EXAMPLE_PROJECT_VERSION}"
from ._version import __version__
def hello_world() -> None:
print("Hello World")
'''
)
)
version_py = example_dir / "_version.py"
version_py.write_text(
dedent(
f'''
__version__ = "{EXAMPLE_PROJECT_VERSION}"
'''
)
)
gitignore = tmp_path / ".gitignore"
gitignore.write_text(
dedent(
f"""
*.pyc
/src/**/{version_py.name}
"""
)
)
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(EXAMPLE_PYPROJECT_TOML_CONTENT)
setup_cfg = tmp_path / "setup.cfg"
Expand Down

0 comments on commit 814a20e

Please sign in to comment.