Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Quid
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Schlüsselstellen
Quid
Commits
7e133783
Commit
7e133783
authored
2 years ago
by
Frederik Arnold
Browse files
Options
Downloads
Patches
Plain Diff
Add more tests
parent
95b2e068
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/TestCLI.py
+83
-0
83 additions, 0 deletions
test/TestCLI.py
test/TestPassager.py
+0
-0
0 additions, 0 deletions
test/TestPassager.py
with
83 additions
and
0 deletions
test/TestCLI.py
0 → 100644
+
83
−
0
View file @
7e133783
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
)
This diff is collapsed.
Click to expand it.
test/Test
Key
Passager.py
→
test/TestPassager.py
+
0
−
0
View file @
7e133783
File moved
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment