Skip to content

Commit

Permalink
add test for sub_language
Browse files Browse the repository at this point in the history
  • Loading branch information
axif0 committed Oct 28, 2024
1 parent 79e8686 commit fffc0f2
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/cli/test_total.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,42 @@ def test_get_total_lexemes_various_data_types(self, mock_query, mock_get_qid):
]
mock_print.assert_has_calls(expected_calls)

@patch("scribe_data.cli.total.get_qid_by_input")
@patch("scribe_data.cli.total.sparql.query")
@patch("scribe_data.cli.total.LANGUAGE_DATA_EXTRACTION_DIR")
def test_get_total_lexemes_sub_languages(self, mock_dir, mock_query, mock_get_qid):
# Setup for sub-languages
mock_get_qid.side_effect = lambda x: {
"bokmål": "Q25167",
"nynorsk": "Q25164",
}.get(x.lower())
mock_results = MagicMock()
mock_results.convert.return_value = {
"results": {"bindings": [{"total": {"value": "30"}}]}
}
mock_query.return_value = mock_results

# Mocking directory paths and contents
mock_dir.__truediv__.return_value.exists.return_value = True
mock_dir.__truediv__.return_value.iterdir.return_value = [
MagicMock(name="verbs", is_dir=lambda: True),
MagicMock(name="nouns", is_dir=lambda: True),
]

with patch("builtins.print") as mock_print:
get_total_lexemes("Norwegian", "verbs")
get_total_lexemes("Norwegian", "nouns")

expected_calls = [
call(
"\nLanguage: Norwegian\nData type: verbs\nTotal number of lexemes: 30\n"
),
call(
"\nLanguage: Norwegian\nData type: nouns\nTotal number of lexemes: 30\n"
),
]
mock_print.assert_has_calls(expected_calls)


class TestGetQidByInput(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit fffc0f2

Please sign in to comment.