Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add load_all_tests #31

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]