Skip to content

Commit

Permalink
Adds more unit testing for V1 support
Browse files Browse the repository at this point in the history
- Upgrades more existing unit tests to use a V1 example. This is done with
  parameterization
- Adds missing logic to recipe conversion work. Converted recipes now
  re-initizialize their variable tables
- Re-enables skipped test
  • Loading branch information
schuylermartin45 committed Jul 17, 2024
1 parent 75dc025 commit 418b0ea
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 10 deletions.
2 changes: 2 additions & 0 deletions conda_recipe_manager/parser/recipe_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ def __eq__(self, other: object) -> bool:
"""
if not isinstance(other, RecipeParser):
raise TypeError
if self._schema_version != other._schema_version:
return False
return self.render() == other.render()

def is_modified(self) -> bool:
Expand Down
3 changes: 3 additions & 0 deletions conda_recipe_manager/parser/recipe_parser_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,5 +810,8 @@ def render_to_v1_recipe_format(self) -> tuple[str, MessageTable, str]:

# Override the schema value as the recipe conversion is now complete.
self._v1_recipe._schema_version = SchemaVersion.V1 # pylint: disable=protected-access
# Update the variable table
self._v1_recipe._init_vars_tbl() # pylint: disable=protected-access
# TODO update selector table when V1 selectors are supported!

return self._v1_recipe.render(), self._msg_tbl, str(self._v1_recipe)
40 changes: 30 additions & 10 deletions tests/parser/test_recipe_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
def test_construction(file: str, schema_version: SchemaVersion) -> None:
"""
Tests the construction of a recipe parser instance with a simple, common example file.
:param file: Recipe file to test with
:param schema_version: Schema version to match
"""
types_toml = load_file(f"{TEST_FILES_PATH}/{file}")
parser = RecipeParser(types_toml)
Expand All @@ -67,33 +69,51 @@ def test_construction(file: str, schema_version: SchemaVersion) -> None:
# assert parser._root == TODO


def test_str() -> None:
@pytest.mark.parametrize(
"file,out_file",
[
("simple-recipe.yaml", "simple-recipe_to_str.out"),
("v1_format/v1_simple-recipe.yaml", "v1_format/v1_simple-recipe_to_str.out"),
],
)
def test_str(file: str, out_file: str) -> None:
"""
Tests string casting
Tests rendering to a debug string
:param file: Recipe file to test with
:param out_file: Output string to match
"""
parser = load_recipe("simple-recipe.yaml")
assert str(parser) == load_file(f"{TEST_FILES_PATH}/simple-recipe_to_str.out")
parser = load_recipe(file)
assert str(parser) == load_file(f"{TEST_FILES_PATH}/{out_file}")
# Regression test: Run a function a second time to ensure that `SelectorInfo::__str__()` doesn't accidentally purge
# the underlying stack when the string is being rendered.
assert str(parser) == load_file(f"{TEST_FILES_PATH}/simple-recipe_to_str.out")
assert str(parser) == load_file(f"{TEST_FILES_PATH}/{out_file}")
assert not parser.is_modified()


def test_eq() -> None:
@pytest.mark.parametrize(
"file,other_file",
[
("simple-recipe.yaml", "types-toml.yaml"),
("v1_format/v1_simple-recipe.yaml", "v1_format/v1_types-toml.yaml"),
("v1_format/v1_simple-recipe.yaml", "simple-recipe.yaml"),
],
)
def test_eq(file: str, other_file: str) -> None:
"""
Tests equivalency function
:param file: Recipe file to test with
:param other_file: "Other" recipe file to check against
"""
parser0 = load_recipe("simple-recipe.yaml")
parser1 = load_recipe("simple-recipe.yaml")
parser2 = load_recipe("types-toml.yaml")
parser0 = load_recipe(file)
parser1 = load_recipe(file)
parser2 = load_recipe(other_file)
assert parser0 == parser1
assert parser0 != parser2
assert not parser0.is_modified()
assert not parser1.is_modified()
assert not parser2.is_modified()


@pytest.mark.skip(reason="To be re-enable when PAT-46 is fixed")
def test_loading_obj_in_list() -> None:
"""
Regression test: at one point, the parser would crash loading this file, containing an object in a list.
Expand Down
82 changes: 82 additions & 0 deletions tests/test_aux_files/v1_format/v1_simple-recipe_to_str.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
--------------------
RecipeParser Instance
- Schema Version: 1
- Variables Table:
{
"zz_non_alpha_first": 42,
"name": "types-toml",
"version": "0.10.8.6"
}
- Selectors Table:
[unix and win]
- empty_field2 -> /requirements/empty_field2
- is_modified?: False
- Tree:
/
|- <Comment: # Comment above a top-level structure>
|- schema_version
|- 1
|- context
|- zz_non_alpha_first
|- 42
|- name
|- types-toml
|- version
|- 0.10.8.6
|- package
|- name
|- ${{ name|lower }}
|- build
|- number
|- 0
|- skip
|- match(python, "<3.7")
|- is_true
|- True
|- requirements
|- empty_field1
|- host
|- <Collection Node>
|- if
|- unix
|- then
|- setuptools
|- <Collection Node>
|- if
|- unix
|- then
|- fakereq
|- empty_field2
|- run
|- python
|- empty_field3
|- about
|- summary
|- This is a small recipe for testing
|- 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
|- multi_level
|- list_1
|- foo
|- <Comment: # Ensure a comment in a list is supported>
|- bar
|- list_2
|- cat
|- bat
|- mat
|- list_3
|- ls
|- sl
|- cowsay
|- test_var_usage
|- foo
|- ${{ version }}
|- bar
|- baz
|- ${{ zz_non_alpha_first }}
|- blah
|- This ${{ name }} is silly
|- last
--------------------

0 comments on commit 418b0ea

Please sign in to comment.