From 19035d273a614d5834f29b6f4fd9fcfb1e01c8a9 Mon Sep 17 00:00:00 2001 From: beckermr Date: Mon, 25 Nov 2024 16:50:15 -0600 Subject: [PATCH] test: add test --- ...555-skip-bad-specs-while-still-parsing.rst | 19 +++++++ tests/test_metadata.py | 53 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 news/5555-skip-bad-specs-while-still-parsing.rst diff --git a/news/5555-skip-bad-specs-while-still-parsing.rst b/news/5555-skip-bad-specs-while-still-parsing.rst new file mode 100644 index 0000000000..1454fb9bad --- /dev/null +++ b/news/5555-skip-bad-specs-while-still-parsing.rst @@ -0,0 +1,19 @@ +### Enhancements + +* + +### Bug fixes + +* Fixed a bug where bad match specs from intermediate parsing results would cause parsing to fail. (#5555) + +### Deprecations + +* + +### Docs + +* + +### Other + +* diff --git a/tests/test_metadata.py b/tests/test_metadata.py index d5feecf53c..3985bdc1df 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -655,3 +655,56 @@ def test_parse_until_resolved_skip_avoids_undefined_jinja( pytest.fail( "Undefined variable caused error, even though this build is skipped" ) + + +@pytest.mark.parametrize("have_variant", [True, False]) +def test_parse_until_resolved_missing_jinja_in_spec( + testing_metadata: MetaData, + tmp_path: Path, + have_variant: bool, +) -> None: + (recipe := tmp_path / (name := "meta.yaml")).write_text( + """ +package: + name: dummy + version: 1.0.0 + +build: + noarch: python + number: 0 + +requirements: + host: + - python ={{ python_min }} + run: + - python >={{ python_min }} +""" + ) + (tmp_path / "conda_build_config.yaml").write_text( + """ +python_min: + - 3.6 +""" + ) + testing_metadata._meta_path = recipe + testing_metadata._meta_name = name + if have_variant: + testing_metadata.config.variant = {"python_min": "3.6"} + else: + delattr(testing_metadata.config, "variant") + delattr(testing_metadata.config, "variant_config_files") + delattr(testing_metadata.config, "variants") + + try: + testing_metadata.parse_until_resolved() + if not have_variant: + pytest.fail("Undefined variable did NOT cause spec parsing error!") + else: + print("parsed OK!") + except (Exception, SystemExit): + if have_variant: + pytest.fail( + "Undefined variable caused spec parsing error even if we have the variant!" + ) + else: + print("did not parse OK!")