Skip to content

Commit

Permalink
Merge pull request #267 from axif0/capitalization
Browse files Browse the repository at this point in the history
add test and fix capitalization
  • Loading branch information
andrewtavis authored Oct 7, 2024
2 parents 02c7e1b + de9c931 commit f9e6f60
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 26 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
123 changes: 99 additions & 24 deletions tests/cli/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

0 comments on commit f9e6f60

Please sign in to comment.