-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from MITLibraries/TIMX-404-establish-feature-…
…flagging-pathways TIMX 404 - Establish feature flag branching for parquet work
- Loading branch information
Showing
10 changed files
with
745 additions
and
329 deletions.
There are no files selected for viewing
This file contains 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 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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,92 @@ | ||
# ruff: noqa: PLR2004 | ||
|
||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from transmogrifier.cli import main | ||
from transmogrifier.config import get_etl_version | ||
|
||
# NOTE: FEATURE FLAG: this test file can be removed completely after v2 parquet work. | ||
|
||
|
||
@pytest.fixture | ||
def mocked_v1_write_method(): | ||
with patch( | ||
"transmogrifier.cli.Transformer.transform_and_write_output_files" | ||
) as mocked_method: | ||
yield mocked_method | ||
|
||
|
||
@pytest.fixture | ||
def mocked_v2_write_method(): | ||
with patch( | ||
"transmogrifier.cli.Transformer.write_to_parquet_dataset" | ||
) as mocked_method: | ||
yield mocked_method | ||
|
||
|
||
def test_etl_version_helper_function_no_env_var_is_v1(monkeypatch): | ||
monkeypatch.delenv("ETL_VERSION") | ||
assert get_etl_version() == 1 | ||
|
||
|
||
def test_etl_version_helper_function_env_var_is_1_is_v1(monkeypatch): | ||
monkeypatch.setenv("ETL_VERSION", "1") | ||
assert get_etl_version() == 1 | ||
|
||
|
||
def test_etl_version_helper_function_env_var_is_2_is_v2(monkeypatch): | ||
monkeypatch.setenv("ETL_VERSION", "2") | ||
assert get_etl_version() == 2 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"env_value", | ||
[ | ||
"pumpkin_pie", # throws ValueError because not integer | ||
"3", # throws ValueError because not 1 or 2 | ||
], | ||
) | ||
def test_etl_version_helper_function_env_var_value_is_unsupported(env_value, monkeypatch): | ||
monkeypatch.setenv("ETL_VERSION", env_value) | ||
with pytest.raises(ValueError): # noqa: PT011 | ||
get_etl_version() | ||
|
||
|
||
def test_cli_etl_version_v1_invokes_v1_code( | ||
mocked_v1_write_method, monkeypatch, runner, tmp_path | ||
): | ||
monkeypatch.setenv("ETL_VERSION", "1") | ||
mocked_v1_write_method.side_effect = Exception("Do not proceed") | ||
runner.invoke( | ||
main, | ||
[ | ||
"-i", | ||
"/does/not/exist/alma-2023-01-13-full-extracted-records-to-index_01.xml", | ||
"-o", | ||
"/does/not/exist/libguides.json", | ||
"-s", | ||
"libguides", | ||
], | ||
) | ||
mocked_v1_write_method.assert_called() | ||
|
||
|
||
def test_cli_etl_version_v2_invokes_v2_code( | ||
mocked_v2_write_method, monkeypatch, runner, tmp_path | ||
): | ||
monkeypatch.setenv("ETL_VERSION", "2") | ||
mocked_v2_write_method.side_effect = Exception("Do not proceed") | ||
runner.invoke( | ||
main, | ||
[ | ||
"-i", | ||
"/does/not/exist/alma-2023-01-13-full-extracted-records-to-index_01.xml", | ||
"-o", | ||
"/does/not/exist/dataset", | ||
"-s", | ||
"libguides", | ||
], | ||
) | ||
mocked_v2_write_method.assert_called() |
This file contains 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 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
Oops, something went wrong.