Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci_pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
115 changes: 115 additions & 0 deletions tests/cli/convert/test_cli_convert_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading