Skip to content
Snippets Groups Projects
Commit 7e133783 authored by Frederik Arnold's avatar Frederik Arnold
Browse files

Add more tests

parent 95b2e068
No related branches found
No related tags found
No related merge requests found
from unittest import TestCase, mock
from quid.cli.QuidCLI import main
from quid.match.Match import Match
from quid.match.MatchSpan import MatchSpan
from quid.visualization.Visualizer import Visualizer
class CLITestCase(TestCase):
@mock.patch('quid.cli.QuidCLI.isfile')
@mock.patch('quid.cli.QuidCLI.listdir')
@mock.patch('quid.cli.QuidCLI.Path.mkdir')
@mock.patch('quid.cli.QuidCLI.Quid')
def test_cli_compare(self, mock_quid, mock_mkdir, mock_list_dir, mock_is_file):
quid_instance = mock_quid.return_value
match_1_source_match_span = MatchSpan(0, 10)
match_1_target_match_span = MatchSpan(0, 10)
match_1 = Match(match_1_source_match_span, match_1_target_match_span)
quid_instance.compare.return_value = [match_1]
mock_is_file.return_value = True
with mock.patch("builtins.open", mock.mock_open(read_data='')) as file_mock:
handler_1 = file_mock.return_value
with mock.patch("builtins.open", mock.mock_open(read_data='')) as file_mock_2:
handler_2 = file_mock_2.return_value
handlers = (handler_1, handler_1, handler_2)
file_mock.side_effect = handlers
main(["compare", "test.txt", "test.txt", "--output-folder-path", "output"])
handler_2.write.assert_called_once_with('[{"source_span": {"start": 0, "end": 10}, '
'"target_span": {"start": 0, "end": 10}}]')
@mock.patch('quid.cli.QuidCLI.listdir')
@mock.patch('quid.cli.QuidCLI.isfile')
@mock.patch('quid.cli.QuidCLI.load_matches')
def test_cli_passage(self, mock_load_matches, mock_is_file, mock_list_dir):
mock_list_dir.return_value = ['test.json']
mock_is_file.return_value = True
mock_load_matches.return_value = []
with mock.patch("builtins.open", mock.mock_open(read_data='')) as file_mock:
handler_1 = file_mock.return_value
with mock.patch("builtins.open", mock.mock_open(read_data='')) as file_mock_2:
handler_2 = file_mock_2.return_value
handlers = (handler_1, handler_1, handler_2)
file_mock.side_effect = handlers
main(["passage", "folder", "folder", "folder", "folder"])
self.assertEqual(5, handler_2.write.call_count)
@mock.patch('quid.cli.QuidCLI.Path.mkdir')
@mock.patch('quid.cli.QuidCLI.json.load')
@mock.patch('quid.cli.QuidCLI.copyfile')
@mock.patch('quid.cli.QuidCLI.load_citation_source_links')
@mock.patch('quid.cli.QuidCLI.load_citation_sources')
@mock.patch('quid.cli.QuidCLI.Visualizer')
def test_cli_visualize(self, mock_visualizer, mock_load_citation_sources, mock_load_citation_source_links,
mock_copyfile, mock_json_load, mock_mkdir):
mock_visualizer.return_value = Visualizer()
mock_load_citation_sources.return_value = []
mock_load_citation_source_links.return_value = []
mock_json_load.return_value = []
with mock.patch("builtins.open", mock.mock_open(read_data='')) as file_mock:
handler_1 = file_mock.return_value
with mock.patch("builtins.open", mock.mock_open(read_data='')) as file_mock_2:
handler_2 = file_mock_2.return_value
handlers = (handler_1, handler_1, handler_2)
file_mock.side_effect = handlers
main(["visualize", "folder", "folder", "folder", "folder"])
self.assertEqual(4, handler_2.write.call_count)
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment