diff --git a/src/scribe_data/cli/get.py b/src/scribe_data/cli/get.py index 8f5abb436..323404e1b 100644 --- a/src/scribe_data/cli/get.py +++ b/src/scribe_data/cli/get.py @@ -92,7 +92,7 @@ def get_data( if all: print("Updating all languages and data types ...") - query_data(None, None, overwrite) + query_data(None, None, None, overwrite) subprocess_result = True # MARK: Emojis diff --git a/src/scribe_data/wikidata/query_data.py b/src/scribe_data/wikidata/query_data.py index 4082b3a23..afd12e41b 100644 --- a/src/scribe_data/wikidata/query_data.py +++ b/src/scribe_data/wikidata/query_data.py @@ -64,7 +64,7 @@ def query_data( PATH_TO_LANGUAGE_EXTRACTION_FILES = ( SCRIBE_DATA_SRC_PATH / "language_data_extraction" ) - + languages = [lang.capitalize() for lang in languages] current_languages = list(language_metadata["languages"]) current_data_type = ["nouns", "verbs", "prepositions"] diff --git a/tests/cli/test_get.py b/tests/cli/test_get.py index c96f6a7c4..bcaaed667 100644 --- a/tests/cli/test_get.py +++ b/tests/cli/test_get.py @@ -26,27 +26,102 @@ from scribe_data.cli.get import get_data -class TestCLIGetCommand(unittest.TestCase): - @unittest.skip("Mocking doesn't work as expected.") - def test_get_command(self): - with patch("scribe_data.cli.get.get_data") as mock_get_data: - # Call the function you're testing - get_data( - language="English", - data_type="nouns", - output_dir="tests_output", - output_type="json", - ) - - get_data(all=True) - - # Validate the calls. - assert mock_get_data.call_count == 2 - - args, kwargs = mock_get_data.mock_calls[0] - self.assertEqual(args, ("English", "nouns", "tests_output")) - self.assertFalse(kwargs.get("all")) - - args, kwargs = mock_get_data.mock_calls[-1] # Get the last call - self.assertIsNone(args) - self.assertTrue(kwargs["all"]) +class TestGetData(unittest.TestCase): + # MARK: Subprocess Patching + + @patch("subprocess.run") + def test_get_emoji_keywords(self, mock_subprocess_run): + get_data(language="English", data_type="emoji-keywords") + self.assertTrue(mock_subprocess_run.called) + + # MARK: Invalid Arguments + + def test_invalid_arguments(self): + with self.assertRaises(ValueError): + get_data() + + # MARK: All Data + + @patch("scribe_data.cli.get.query_data") + def test_get_all_data(self, mock_query_data): + get_data(all=True) + mock_query_data.assert_called_once_with(None, None, None, False) + + # MARK: Language and Data Type + + @patch("scribe_data.cli.get.query_data") + def test_get_specific_language_and_data_type(self, mock_query_data): + get_data(language="german", data_type="nouns", output_dir="./test_output") + mock_query_data.assert_called_once_with( + languages=["german"], + data_type=["nouns"], + output_dir="./test_output", + overwrite=False, + ) + + # MARK: Capitalized Language + + @patch("scribe_data.cli.get.query_data") + def test_get_data_with_capitalized_language(self, mock_query_data): + get_data(language="German", data_type="nouns") + mock_query_data.assert_called_once_with( + languages=["German"], + data_type=["nouns"], + output_dir="scribe_data_json_export", + overwrite=False, + ) + + # MARK: Lowercase Language + + @patch("scribe_data.cli.get.query_data") + def test_get_data_with_lowercase_language(self, mock_query_data): + get_data(language="german", data_type="nouns") + mock_query_data.assert_called_once_with( + languages=["german"], + data_type=["nouns"], + output_dir="scribe_data_json_export", + overwrite=False, + ) + + # MARK: Output Directory + + @patch("scribe_data.cli.get.query_data") + def test_get_data_with_different_output_directory(self, mock_query_data): + get_data( + language="german", data_type="nouns", output_dir="./custom_output_test" + ) + mock_query_data.assert_called_once_with( + languages=["german"], + data_type=["nouns"], + output_dir="./custom_output_test", + overwrite=False, + ) + + # MARK: Overwrite is True + + @patch("scribe_data.cli.get.query_data") + def test_get_data_with_overwrite_true(self, mock_query_data): + get_data(language="English", data_type="verbs", overwrite=True) + mock_query_data.assert_called_once_with( + languages=["English"], + data_type=["verbs"], + output_dir="scribe_data_json_export", + overwrite=True, + ) + + # MARK: Overwrite is False + + @patch("scribe_data.cli.get.query_data") + def test_get_data_with_overwrite_false(self, mock_query_data): + get_data( + language="English", + data_type="verbs", + overwrite=False, + output_dir="./custom_output_test", + ) + mock_query_data.assert_called_once_with( + languages=["English"], + data_type=["verbs"], + output_dir="./custom_output_test", + overwrite=False, + )