Skip to content

Commit

Permalink
fix: extension-template tests (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko authored Nov 19, 2024
2 parents 4aec9de + 3ca06c3 commit 95bb6f6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .conda/openfisca-extension-template/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ schema_version: 1

context:
name: openfisca-extension-template
version: 1.3.15
version: 2.0.6

package:
name: ${{ name|lower }}
version: ${{ version }}

source:
url: https://pypi.org/packages/source/${{ name[0] }}/${{ name }}/openfisca_extension_template-${{ version }}.tar.gz
sha256: e16ee9cbefdd5e9ddc1c2c0e12bcd74307c8cb1be55353b3b2788d64a90a5df9
sha256: e6ee405e9710e5e07f498173bad1a41531527b8e423fca7d045332cbdb10082f

build:
number: 2
Expand All @@ -21,8 +21,8 @@ requirements:
host:
- numpy
- pip
- poetry >=1.7
- python
- setuptools >=61.0
run:
- numpy
- python
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/_test-pip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### 43.2.5 [#1296](https://github.com/openfisca/openfisca-core/pull/1296)

#### Bugfix

- Use new `extension-template` tests' path

### 43.2.4 [#1294](https://github.com/openfisca/openfisca-core/pull/1294)

#### Technical changes
Expand Down
19 changes: 9 additions & 10 deletions openfisca_tasks/test_code.mk
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
## 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

## 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
Expand Down Expand Up @@ -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,$@:)
Expand All @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

setup(
name="OpenFisca-Core",
version="43.2.4",
version="43.2.5",
author="OpenFisca Team",
author_email="[email protected]",
classifiers=[
Expand Down
28 changes: 13 additions & 15 deletions tests/core/test_yaml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pathlib
import subprocess
import sys

import pytest

Expand Down Expand Up @@ -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:
Expand All @@ -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")

0 comments on commit 95bb6f6

Please sign in to comment.