diff --git a/.github/workflows/ci_pytest.yaml b/.github/workflows/ci_pytest.yaml index 661f69e63..de5dc0a24 100644 --- a/.github/workflows/ci_pytest.yaml +++ b/.github/workflows/ci_pytest.yaml @@ -60,7 +60,7 @@ jobs: - name: Set up Homebrew if: matrix.os == 'macos-latest' - uses: Homebrew/actions/setup-homebrew@master + uses: Homebrew/actions/setup-homebrew@main - name: Install PyICU dependencies if: matrix.os == 'macos-latest' diff --git a/tests/cli/convert/test_cli_convert_wrapper.py b/tests/cli/convert/test_cli_convert_wrapper.py index aba1b7cde..3d5141a57 100644 --- a/tests/cli/convert/test_cli_convert_wrapper.py +++ b/tests/cli/convert/test_cli_convert_wrapper.py @@ -131,6 +131,121 @@ def test_convert_wrapper_wiktionary_no_input_path_uses_wiktionary_default( overwrite=False, ) + @patch("scribe_data.cli.convert.wrapper.Path", autospec=True) + @patch("scribe_data.cli.convert.wrapper.convert_to_json", autospec=True) + def test_convert_wrapper_to_json( + self, + mock_convert_to_json: MagicMock, + mock_path: MagicMock, + ) -> None: + mock_path.return_value.exists.return_value = True + + convert_wrapper( + languages=["english", "german", "spanish"], + data_types=["nouns"], + input_path=Path("file"), + output_dir=Path("/output"), + output_type="json", + overwrite=True, + identifier_case="camel", + ) + + mock_convert_to_json.assert_called_with( + language="english", + data_types=["nouns"], + input_file=Path("file"), + output_dir=Path("/output"), + output_type="json", + overwrite=True, + identifier_case="camel", + ) + + # testing convert json with output dir = None + @patch( + "scribe_data.cli.convert.wrapper.DEFAULT_JSON_EXPORT_DIR", + new=Path("/mock_json_export"), + ) + @patch("scribe_data.cli.convert.wrapper.Path", autospec=True) + @patch("scribe_data.cli.convert.wrapper.convert_to_json", autospec=True) + def test_convert_wrapper_to_json_no_output_dir( + self, mock_convert_to_json: MagicMock, mock_path: MagicMock + ) -> None: + convert_wrapper( + languages=["spanish"], + data_types=["nouns"], + input_path=Path("file"), + output_dir=None, + output_type="json", + overwrite=True, + identifier_case="camel", + ) + + mock_convert_to_json.assert_called_with( + language="spanish", + data_types=["nouns"], + input_file=Path("file"), + output_dir=Path("/mock_json_export"), + output_type="json", + overwrite=True, + identifier_case="camel", + ) + + @patch( + "scribe_data.cli.convert.wrapper.DEFAULT_WIKTIONARY_JSON_EXPORT_DIR", + new=Path("/mock_wiktionary_dir"), + ) + @patch("scribe_data.cli.convert.wrapper.convert_to_json", autospec=True) + def test_convert_wrapper_wiktionary_no_input_path_uses_wiktionary_default_json( + self, mock_convert_to_json: MagicMock + ) -> None: + convert_wrapper( + languages=["german"], + data_types=["wiktionary_translations"], + input_path=None, + output_dir=Path("/output"), + output_type="json", + overwrite=False, + identifier_case="camel", + ) + + mock_convert_to_json.assert_called_once_with( + language="german", + data_types=["wiktionary_translations"], + input_file=Path("/mock_wiktionary_dir"), + output_dir=Path("/output"), + output_type="json", + overwrite=False, + identifier_case="camel", + ) + + @patch( + "scribe_data.cli.convert.wrapper.DEFAULT_JSON_EXPORT_DIR", + new=Path("/mock_json_dir"), + ) + @patch("scribe_data.cli.convert.wrapper.convert_to_json", autospec=True) + def test_convert_wrapper_no_input_path_uses_json_default( + self, mock_convert_to_json: MagicMock + ) -> None: + convert_wrapper( + languages=["german"], + data_types=["nouns"], + input_path=None, + output_dir=Path("/output"), + output_type="json", + overwrite=False, + identifier_case="camel", + ) + + mock_convert_to_json.assert_called_once_with( + language="german", + data_types=["nouns"], + input_file=Path("/mock_json_dir"), + output_dir=Path("/output"), + output_type="json", + overwrite=False, + identifier_case="camel", + ) + def test_convert_wrapper(self) -> None: with self.assertRaises(ValueError) as context: convert_wrapper(