Skip to content

Commit

Permalink
Merge pull request #31 from nichmor/feat/add-tests-evaluation
Browse files Browse the repository at this point in the history
feat: add load_all_tests
  • Loading branch information
wolfv authored Jul 26, 2024
2 parents 381833c + b8d5283 commit c5f30bc
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/rattler_build_conda_compat/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,16 @@ def load_all_requirements(content: dict[str, Any]) -> dict[str, Any]:
requirements_section[section] = list(visit_conditional_list(section_reqs))

return requirements_section


def load_all_tests(content: dict[str, Any]) -> list[dict]:
tests_section = content.get("tests", [])
if not tests_section:
return []

evaluated_tests = []

for section in tests_section:
evaluated_tests.extend(list(visit_conditional_list(section)))

return evaluated_tests
33 changes: 33 additions & 0 deletions tests/__snapshots__/test_rattler_loader.ambr
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
# serializer version: 1
# name: test_load_all_tests
list([
dict({
'files': dict({
'recipe': list([
'more_tests/*.py',
]),
'source': list([
'tests/',
'test.py',
'*.sh',
]),
}),
'requirements': dict({
'run': list([
'pytest',
]),
}),
'script': list([
'echo "Hello world"',
'pytest ./tests',
]),
}),
dict({
'python': dict({
'imports': list([
'mypkg',
'mypkg.subpkg',
]),
}),
}),
])
# ---
# name: test_load_recipe_with_missing_selectors
dict({
'package': dict({
Expand Down
28 changes: 28 additions & 0 deletions tests/data/recipe_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package:
name: for-test
version: 1.0.0

tests:
- script:
- echo "Hello world"
- pytest ./tests

requirements:
run:
- pytest

files:
source:
- tests/
- test.py
- "*.sh"

recipe:
- more_tests/*.py

- if: unix
then:
- python:
imports:
- mypkg
- mypkg.subpkg
21 changes: 21 additions & 0 deletions tests/test_rattler_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from rattler_build_conda_compat.loader import (
load_all_requirements,
load_all_tests,
load_yaml,
parse_recipe_config_file,
)
Expand Down Expand Up @@ -37,3 +38,23 @@ def test_load_recipe_with_missing_selectors(snapshot) -> None:
)

assert loaded_variants == snapshot


def test_load_all_tests(snapshot) -> None:
recipe_content = Path("tests/data/recipe_tests.yaml").read_text()

recipe_content = load_yaml(recipe_content)

loaded_tests = load_all_tests(recipe_content)
assert loaded_tests == snapshot

# validate that tests section is a list of dictionaries
# and also verify that dictionary preserver the right inner dict
# let's find script test
script_test = next(test for test in loaded_tests if "script" in test)
# validate that it has run requirements as dictionary
assert script_test["requirements"]["run"][0] == "pytest"

# let's find python test
python_test = next(test for test in loaded_tests if "python" in test)
assert "mypkg" in python_test["python"]["imports"]

0 comments on commit c5f30bc

Please sign in to comment.