Skip to content

Commit

Permalink
Adds unit tests for the partial save feature for bump recipe. Warning…
Browse files Browse the repository at this point in the history
…: the new test takes an incredibly long time due to the issue tracked by #265
  • Loading branch information
schuylermartin45 committed Dec 16, 2024
1 parent a529602 commit 66674de
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
38 changes: 38 additions & 0 deletions tests/commands/test_bump_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,41 @@ def test_bump_recipe_increment_no_build_key_found(fs: FakeFilesystem) -> None:
recipe_file_path: Final[Path] = get_test_path() / "bump_recipe/no_build_key.yaml"
result = runner.invoke(bump_recipe.bump_recipe, ["--build-num", str(recipe_file_path)])
assert result.exit_code == ExitCode.ILLEGAL_OPERATION


@pytest.mark.parametrize(
"recipe_file,version,expected_recipe_file",
[
("bump_recipe/types-toml_bad_url.yaml", "0.10.8.20240310", "bump_recipe/types-toml_bad_url_partial_save.yaml"),
# Build number is the first thing attempted, so no changes will be made to the file. Instead will check the
# modification time.
("bump_recipe/no_build_key.yaml", "0.10.8.20240310", "bump_recipe/no_build_key.yaml"),
],
)
def test_bump_recipe_save_on_failure(
fs: FakeFilesystem, recipe_file: str, version: str, expected_recipe_file: str
) -> None:
"""
Ensures that recipes that encounter a problem can be partially saved with the `--save-on-failure` option.
:param fs: `pyfakefs` Fixture used to replace the file system
:param recipe_file: Target recipe file to update
:param version: Version to bump to
:param expected_recipe_file: Expected resulting recipe file
"""
runner = CliRunner()
fs.add_real_directory(get_test_path(), read_only=False)

recipe_file_path: Final[Path] = get_test_path() / recipe_file
expected_recipe_file_path: Final[Path] = get_test_path() / expected_recipe_file
start_mod_time: Final[float] = recipe_file_path.stat().st_mtime

with patch("requests.get", new=mock_requests_get):
result = runner.invoke(bump_recipe.bump_recipe, ["--save-on-failure", "-t", version, str(recipe_file_path)])

# Ensure the file was written by checking the modification timestamp. Some tests may not have any changes if the
# error occurred too soon.
assert recipe_file_path.stat().st_mtime > start_mod_time
# Read the edited file and check it against the expected file. We don't parse the recipe file as it isn't necessary.
assert load_file(recipe_file_path) == load_file(expected_recipe_file_path)
assert result.exit_code != ExitCode.SUCCESS
2 changes: 1 addition & 1 deletion tests/test_aux_files/bump_recipe/types-toml_bad_url.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ source:
sha256: 6d3ac79e36c9ee593c5d4fb33a50cca0e3adceb6ef5cff8b8e5aef67b4c4aaf2

build:
number: 0
number: 1
skip: true # [py<37]
script: {{ PYTHON }} -m pip install . -vv --no-deps --no-build-isolation

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% set name = "types-toml" %}
{% set version = "0.10.8.20240310" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
url: https://fake.website.total.bullshit/artifact.tar.gz
sha256: 6d3ac79e36c9ee593c5d4fb33a50cca0e3adceb6ef5cff8b8e5aef67b4c4aaf2

build:
number: 0
skip: true # [py<37]
script: {{ PYTHON }} -m pip install . -vv --no-deps --no-build-isolation

requirements:
host:
- setuptools
- wheel
- pip
- python
run:
- python

test:
imports:
- types
requires:
- pip
commands:
- pip check
- test -f $SP_DIR/toml-stubs/__init__.pyi # [unix]

about:
home: https://github.com/python/typeshed
summary: Typing stubs for toml
description: |
This is a PEP 561 type stub package for the toml package.
It can be used by type-checking tools like mypy, pyright,
pytype, PyCharm, etc. to check code that uses toml.
license: Apache-2.0 AND MIT
license_file: LICENSE
license_family: OTHER
dev_url: https://github.com/python/typeshed
doc_url: https://pypi.org/project/types-toml/

extra:
recipe-maintainers:
- fhoehle
- conda-forge/mypy

0 comments on commit 66674de

Please sign in to comment.