-
Notifications
You must be signed in to change notification settings - Fork 8
Add country package version to economy comparisons #126
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ef591ff
feat: Add API version to economy comparisons
anth-volk ad6ac1a
fix: Fix typo in EconomyComparison schema
anth-volk d8e3165
fix: Reformat package name constants
anth-volk 9f2ee8b
fix: Update versioning function and tests
anth-volk 642952b
fix: Redo package version management
anth-volk 17b7ad8
fix: Fix import
anth-volk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from importlib.metadata import version | ||
|
|
||
|
|
||
| def get_country_package_name(country_id: str) -> str: | ||
| if country_id in NON_STANDARD_COUNTRY_CODES: | ||
| return f"policyengine_{NON_STANDARD_COUNTRY_CODES[country_id]}" | ||
| if country_id in COUNTRY_IDS: | ||
| return f"policyengine_{country_id}" | ||
| raise ValueError( | ||
| f"Unsupported country ID: {country_id}. Supported IDs are: {COUNTRY_IDS}" | ||
| ) | ||
|
|
||
|
|
||
| def get_country_package_version(country_id: str) -> str: | ||
|
|
||
| package_name = get_country_package_name(country_id) | ||
| return version(package_name) | ||
|
|
||
|
|
||
| COUNTRY_IDS = ["us", "uk", "ca", "il", "ng"] | ||
|
|
||
| NON_STANDARD_COUNTRY_CODES = { | ||
| "ca": "canada", | ||
| } | ||
|
|
||
| COUNTRY_PACKAGES = [ | ||
| get_country_package_name(country) for country in COUNTRY_IDS | ||
| ] |
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| from policyengine.utils.packages import COUNTRY_PACKAGES | ||
| import pytest | ||
| from unittest.mock import patch | ||
|
|
||
| MOCK_VERSION = "MOCK_VERSION" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def patch_importlib_version(): | ||
| def mock_version(package_name): | ||
| if package_name in COUNTRY_PACKAGES: | ||
| return MOCK_VERSION | ||
| else: | ||
| raise Exception(f"Package {package_name} not found") | ||
|
|
||
| with patch( | ||
| "policyengine.utils.packages.version", side_effect=mock_version | ||
| ) as mock: | ||
| yield mock |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import pytest | ||
| from policyengine.utils.packages import ( | ||
| get_country_package_name, | ||
| get_country_package_version, | ||
| ) | ||
| from tests.fixtures.utils.packages import ( | ||
| patch_importlib_version, | ||
| MOCK_VERSION, | ||
| ) | ||
|
|
||
|
|
||
| class TestGetCountryPackageName: | ||
| def test__given_country_id__then_return_package_name(self): | ||
| test_country = "us" | ||
|
|
||
| test_package_name = get_country_package_name(test_country) | ||
|
|
||
| assert test_package_name == "policyengine_us" | ||
|
|
||
| def test__given_non_standard_country_id__then_return_package_name(self): | ||
| test_country = "ca" | ||
|
|
||
| test_package_name = get_country_package_name(test_country) | ||
|
|
||
| assert test_package_name == "policyengine_canada" | ||
|
|
||
| def test__given_unsupported_country_id__then_return_package_name(self): | ||
| test_country = "zz" | ||
|
|
||
| with pytest.raises(Exception, match="Unsupported country ID: zz"): | ||
| get_country_package_name(test_country) | ||
|
|
||
|
|
||
| class TestGetCountryPackageVersion: | ||
| def test__given_package_exists__then_return_version( | ||
| self, patch_importlib_version | ||
| ): | ||
| test_country = "us" | ||
|
|
||
| test_version = get_country_package_version(test_country) | ||
|
|
||
| # Version number defined by mock | ||
| assert test_version == MOCK_VERSION | ||
|
|
||
| def test__given_package_does_not_exist__then_raise_exception( | ||
| self, patch_importlib_version | ||
| ): | ||
| test_country = "zz" | ||
|
|
||
| with pytest.raises( | ||
| Exception, | ||
| match=f"Unsupported country ID: {test_country}. Supported IDs are: ", | ||
| ): | ||
| get_country_package_version(test_country) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.