-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
423 additions
and
135 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
Tests for the CLI convert functionality. | ||
.. raw:: html | ||
<!-- | ||
* Copyright (C) 2024 Scribe | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
--> | ||
""" | ||
|
||
import unittest | ||
from unittest.mock import patch | ||
from pathlib import Path | ||
from scribe_data.cli.convert import export_json, convert_to_sqlite | ||
|
||
|
||
class TestConvert(unittest.TestCase): | ||
|
||
@patch('scribe_data.cli.convert.Path') | ||
@patch('scribe_data.cli.convert.data_to_sqlite') | ||
@patch('shutil.copy') | ||
def test_convert_to_sqlite(self, mock_shutil_copy, mock_data_to_sqlite, mock_path): | ||
mock_path.return_value.exists.return_value = True | ||
|
||
convert_to_sqlite('english', 'nouns', '/output', True) | ||
|
||
mock_data_to_sqlite.assert_called_with(['english'], ['nouns']) | ||
mock_shutil_copy.assert_called() | ||
|
||
@patch('scribe_data.cli.convert.Path') | ||
@patch('scribe_data.cli.convert.data_to_sqlite') | ||
def test_convert_to_sqlite_no_output_dir(self, mock_data_to_sqlite, mock_path): | ||
convert_to_sqlite('english', 'nouns', None, True) | ||
|
||
mock_data_to_sqlite.assert_called_with(['english'], ['nouns']) | ||
mock_path.assert_not_called() | ||
|
||
@patch('scribe_data.cli.convert.Path') | ||
@patch('scribe_data.cli.convert.data_to_sqlite') | ||
@patch('scribe_data.cli.convert.get_language_iso') | ||
@patch('shutil.copy') | ||
def test_convert_to_sqlite_with_language_iso(self, mock_copy, mock_get_language_iso, mock_data_to_sqlite, mock_path): | ||
mock_get_language_iso.return_value = "en" | ||
mock_path.return_value.exists.return_value = True | ||
|
||
convert_to_sqlite("English", "data_type", "/output", True) | ||
|
||
mock_data_to_sqlite.assert_called_with(["English"], ["data_type"]) | ||
mock_copy.assert_called() | ||
|
||
@patch('scribe_data.cli.convert.language_map') | ||
def test_export_json_invalid_language(self, mock_language_map): | ||
mock_language_map.get.return_value = None | ||
|
||
with self.assertRaises(ValueError): | ||
export_json("invalid", "data_type", Path("/output"), True) | ||
|
||
|
||
def test_convert_to_sqlite_no_language(self): | ||
with self.assertRaises(ValueError): | ||
convert_to_sqlite(None, "data_type", "/output", True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
Tests for the CLI get functionality. | ||
.. raw:: html | ||
<!-- | ||
* Copyright (C) 2024 Scribe | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
--> | ||
""" | ||
|
||
import unittest | ||
from unittest.mock import patch, call | ||
from scribe_data.cli.get import get_data | ||
|
||
class TestCLIGetCommand(unittest.TestCase): | ||
@patch('scribe_data.cli.get.query_data') | ||
@patch('scribe_data.cli.get.export_json') | ||
@patch('scribe_data.cli.get.convert_to_csv_or_tsv') | ||
@patch('os.system') | ||
def test_get_command(self, mock_system, mock_convert, mock_export_json, mock_query_data): | ||
expected_calls = [ | ||
call(['English'], ['nouns']), | ||
call(['English'], ['nouns']), | ||
call() | ||
] | ||
|
||
# Execute the test | ||
get_data(language='English', data_type='nouns', output_dir='outputs', output_type='json') | ||
get_data(language='English', data_type='nouns', output_dir='outputs', output_type='csv') | ||
get_data(all=True) | ||
|
||
# Validate the calls | ||
mock_query_data.assert_has_calls(expected_calls, any_order=True) |
Oops, something went wrong.