From 2ecb230485704ec4d2274183146cd10fab70247a Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 19 Nov 2024 09:48:26 +0100 Subject: [PATCH] fix: extension-template tests #1291 --- .../openfisca-extension-template/recipe.yaml | 6 ++-- .github/workflows/_test-pip.yaml | 11 ++++---- openfisca_tasks/test_code.mk | 19 ++++++------- tests/core/test_yaml.py | 28 +++++++++---------- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/.conda/openfisca-extension-template/recipe.yaml b/.conda/openfisca-extension-template/recipe.yaml index c30e28cde..d207be774 100644 --- a/.conda/openfisca-extension-template/recipe.yaml +++ b/.conda/openfisca-extension-template/recipe.yaml @@ -2,7 +2,7 @@ schema_version: 1 context: name: openfisca-extension-template - version: 1.3.15 + version: 2.0.6 package: name: ${{ name|lower }} @@ -10,7 +10,7 @@ package: source: url: https://pypi.org/packages/source/${{ name[0] }}/${{ name }}/openfisca_extension_template-${{ version }}.tar.gz - sha256: e16ee9cbefdd5e9ddc1c2c0e12bcd74307c8cb1be55353b3b2788d64a90a5df9 + sha256: e6ee405e9710e5e07f498173bad1a41531527b8e423fca7d045332cbdb10082f build: number: 2 @@ -21,8 +21,8 @@ requirements: host: - numpy - pip + - poetry >=1.7 - python - - setuptools >=61.0 run: - numpy - python diff --git a/.github/workflows/_test-pip.yaml b/.github/workflows/_test-pip.yaml index 9e0cc4318..e2db77ac3 100644 --- a/.github/workflows/_test-pip.yaml +++ b/.github/workflows/_test-pip.yaml @@ -64,9 +64,8 @@ jobs: ${{ inputs.activate_command }} make test-country - ## There are no tests in extension template anymore - # - name: Run Extension Template tests - # if: ${{ startsWith(inputs.os, 'ubuntu') }} - # run: | - # ${{ inputs.activate_command }} - # make test-extension + - name: Run Extension Template tests + if: ${{ startsWith(inputs.os, 'ubuntu') }} + run: | + ${{ inputs.activate_command }} + make test-extension diff --git a/openfisca_tasks/test_code.mk b/openfisca_tasks/test_code.mk index 273dd4106..2c00c375b 100644 --- a/openfisca_tasks/test_code.mk +++ b/openfisca_tasks/test_code.mk @@ -1,12 +1,11 @@ ## The openfisca command module. openfisca = openfisca_core.scripts.openfisca_command -## The path to the templates' tests. -ifeq ($(OS),Windows_NT) - tests = $(shell python -c "import os, $(1); print(repr(os.path.join($(1).__path__[0], 'tests')))") -else - tests = $(shell python -c "import $(1); print($(1).__path__[0])")/tests -endif +## The path to the country template tests. +country = $(shell python -c "import pathlib, $(1); print(pathlib.Path($(1).__path__[0]) / 'tests')") + +## The path to the extension template tests. +extension = $(shell python -c "import pathlib, $(1); print(pathlib.Path($(1).__path__[0]) / '..' / 'tests' / '$(1)')") ## Run all tasks required for testing. install: install-deps install-edit install-test @@ -14,8 +13,8 @@ install: install-deps install-edit install-test ## Enable regression testing with template repositories. install-test: @$(call print_help,$@:) - @python -m pip install --upgrade --no-deps openfisca-country-template - @python -m pip install --upgrade --no-deps openfisca-extension-template + @python -m pip install --no-deps --upgrade --no-binary :all: \ + openfisca-country-template openfisca-extension-template ## Run openfisca-core & country/extension template tests. test-code: test-core test-country test-extension @@ -53,7 +52,7 @@ test-country: @$(call print_help,$@:) @PYTEST_ADDOPTS="$${PYTEST_ADDOPTS} ${pytest_args}" \ python -m ${openfisca} test \ - $(call tests,"openfisca_country_template") \ + $(call country,"openfisca_country_template") \ --country-package openfisca_country_template \ ${openfisca_args} @$(call print_pass,$@:) @@ -63,7 +62,7 @@ test-extension: @$(call print_help,$@:) @PYTEST_ADDOPTS="$${PYTEST_ADDOPTS} ${pytest_args}" \ python -m ${openfisca} test \ - $(call tests,"openfisca_extension_template") \ + $(call extension,"openfisca_extension_template") \ --country-package openfisca_country_template \ --extensions openfisca_extension_template \ ${openfisca_args} diff --git a/tests/core/test_yaml.py b/tests/core/test_yaml.py index 7b374e5a9..1bafb7c07 100644 --- a/tests/core/test_yaml.py +++ b/tests/core/test_yaml.py @@ -1,6 +1,6 @@ import os +import pathlib import subprocess -import sys import pytest @@ -92,8 +92,8 @@ def test_name_filter(tax_benefit_system) -> None: def test_shell_script() -> None: yaml_path = os.path.join(yaml_tests_dir, "test_success.yml") command = ["openfisca", "test", yaml_path, "-c", "openfisca_country_template"] - with open(os.devnull, "wb") as devnull: - subprocess.check_call(command, stdout=devnull, stderr=devnull) + result = subprocess.run(command, capture_output=True) + assert result.returncode == 0, result.stderr.decode("utf-8") def test_failing_shell_script() -> None: @@ -115,26 +115,24 @@ def test_shell_script_with_reform() -> None: "-r", "openfisca_country_template.reforms.removal_basic_income.removal_basic_income", ] - with open(os.devnull, "wb") as devnull: - subprocess.check_call(command, stdout=devnull, stderr=devnull) + result = subprocess.run(command, capture_output=True) + assert result.returncode == 0, result.stderr.decode("utf-8") -# TODO(Mauko Quiroga-Alvarado): Fix this test -# https://github.com/openfisca/openfisca-core/issues/962 -@pytest.mark.skip( - reason="Does not work because tests are not in openfisca_extension_template anymore." -) -@pytest.mark.skipif(sys.platform == "win32", reason="Does not work on Windows.") def test_shell_script_with_extension() -> None: - tests_dir = os.path.join(openfisca_extension_template.__path__[0], "tests") + base_path = next(iter(openfisca_extension_template.__path__)) + test_path = ( + pathlib.Path(base_path) / ".." / "tests" / "openfisca_extension_template" + ) + path = str(test_path.resolve()) command = [ "openfisca", "test", - tests_dir, + path, "-c", "openfisca_country_template", "-e", "openfisca_extension_template", ] - with open(os.devnull, "wb") as devnull: - subprocess.check_call(command, stdout=devnull, stderr=devnull) + result = subprocess.run(command, capture_output=True) + assert not result.stderr, result.stderr.decode("utf-8")