Skip to content

Commit

Permalink
add test and fix capitalization
Browse files Browse the repository at this point in the history
  • Loading branch information
axif0 committed Oct 7, 2024
1 parent 02c7e1b commit 6a46196
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/scribe_data/cli/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/scribe_data/wikidata/query_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
107 changes: 86 additions & 21 deletions tests/cli/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,96 @@

import unittest
from unittest.mock import patch

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",
)
class TestGetData(unittest.TestCase):
# MARK: Test for 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: Test for invalid arguments
def test_invalid_arguments(self):
with self.assertRaises(ValueError):
get_data()

# MARK: Test for getting 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: Test for specific 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: Test for capitalized language input
@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,
)

get_data(all=True)
# MARK: Test for lowercase language input
@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,
)

# Validate the calls.
assert mock_get_data.call_count == 2
# MARK: Test for different 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,
)

args, kwargs = mock_get_data.mock_calls[0]
self.assertEqual(args, ("English", "nouns", "tests_output"))
self.assertFalse(kwargs.get("all"))
# MARK: Test for overwrite=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,
)

args, kwargs = mock_get_data.mock_calls[-1] # Get the last call
self.assertIsNone(args)
self.assertTrue(kwargs["all"])
# MARK: Test for overwrite=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,
)

0 comments on commit 6a46196

Please sign in to comment.