Skip to content
Open
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
120 changes: 120 additions & 0 deletions tests/cli/convert/test_cli_convert_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,126 @@ def test_convert_wrapper_wiktionary_no_input_path_uses_wiktionary_default(
output_file=Path("/output"),
overwrite=False,
)
# testing convert_to_json
@patch("scribe_data.cli.convert.wrapper.Path", autospec=True)
@patch("scribe_data.cli.convert.wrapper.convert_to_json", autospec=True)

# testing language
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"
)

# testing json with input = None and is_wiktionary
@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"
)

# testing json with input = None and is_wiktionary = false
@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:
Expand Down
Loading