Skip to content

Commit

Permalink
fix tests and add tests for QID
Browse files Browse the repository at this point in the history
  • Loading branch information
axif0 committed Jan 14, 2025
1 parent 78b82c0 commit 192b09c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/scribe_data/cli/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def prompt_user_download_all():
wikidata_dump_type=["form"],
data_types="all",
type_output_dir=output_dir,
wikidata_dump_path=wikidata_dump,
overwrite_all=overwrite,
)
else:
Expand All @@ -145,6 +146,7 @@ def prompt_user_download_all():
wikidata_dump_type=["form"],
data_types=[data_type],
type_output_dir=output_dir,
wikidata_dump_path=wikidata_dump,
overwrite_all=overwrite,
)
else:
Expand Down Expand Up @@ -181,12 +183,12 @@ def prompt_user_download_all():
# MARK: Translations

elif data_type == "translations":
# If no language specified, use "all".
if language is None:
language = "all"
parse_wd_lexeme_dump(
language=language,
wikidata_dump_type=["translations"],
data_types=data_types,
type_output_dir=output_dir,
wikidata_dump_path=wikidata_dump,
overwrite_all=overwrite,
Expand Down
55 changes: 55 additions & 0 deletions tests/cli/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def test_get_all_data_types_for_language_user_says_yes(
wikidata_dump_type=["form"],
data_types="all", # because if only language given, data_types is None
type_output_dir="scribe_data_json_export", # default for JSON
wikidata_dump_path=None, # explicitly set to None
overwrite_all=False,
)
mock_query_data.assert_not_called()
Expand Down Expand Up @@ -322,3 +323,57 @@ def test_get_translations_with_dump(self, mock_parse):
wikidata_dump_path="./wikidump.json",
overwrite_all=False,
)

# MARK: Use QID as language

@patch("scribe_data.cli.get.parse_wd_lexeme_dump")
@patch("scribe_data.cli.get.questionary.confirm")
def test_get_data_with_wikidata_identifier(
self, mock_questionary_confirm, mock_parse
):
"""
Test retrieving data with a Wikidata identifier as language.
Ensures that `parse_wd_lexeme_dump` is called with the correct parameters
when a Wikidata identifier is used.
"""
# Mock the user confirmation to return True (query Wikidata directly).
mock_questionary_confirm.return_value.ask.return_value = True

get_data(
language="Q9217",
wikidata_dump="scribe",
output_dir="exported_json",
all_bool=True,
)
mock_parse.assert_called_once_with(
language="Q9217",
wikidata_dump_type=["form"],
data_types="all",
type_output_dir="exported_json",
wikidata_dump_path="scribe",
overwrite_all=False,
)

@patch("scribe_data.cli.get.parse_wd_lexeme_dump")
def test_get_data_with_wikidata_identifier_and_data_type(self, mock_parse):
"""
Test retrieving a specific data type with a Wikidata identifier.
Ensures that `parse_wd_lexeme_dump` is called with the correct parameters
when a Wikidata identifier and specific data type are used.
"""
get_data(
language="Q9217",
data_type="nouns",
wikidata_dump="scribe",
output_dir="exported_json",
)
mock_parse.assert_called_once_with(
language="Q9217",
wikidata_dump_type=["form"],
data_types=["nouns"],
type_output_dir="exported_json",
wikidata_dump_path="scribe",
overwrite_all=False,
)

0 comments on commit 192b09c

Please sign in to comment.