Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scRNA-seq-simulation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
zavolan_group
pipelines
scRNA-seq-simulation
Commits
89da273b
Commit
89da273b
authored
3 years ago
by
Kathleen Moriarty
Browse files
Options
Downloads
Patches
Plain Diff
add test for cli - but needs to be improved
parent
31915d91
No related branches found
No related tags found
1 merge request
!17
Issue 7
Pipeline
#13907
failed
3 years ago
Stage: qc
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_read_sequence_cli.py
+103
-0
103 additions, 0 deletions
tests/test_read_sequence_cli.py
with
103 additions
and
0 deletions
tests/test_read_sequence_cli.py
0 → 100644
+
103
−
0
View file @
89da273b
"""
Test Functionality of Read Sequencing CLI.
This test needs to be modified correctly.
"""
import
argparse
import
importlib.util
import
os
from
pathlib
import
Path
import
sys
import
pytest
from
src.read_sequencing.cli
import
(
main
,
parse_args
,
)
PACKAGE_DIR
=
Path
(
__file__
).
resolve
().
parents
[
1
]
/
"
src/read_sequencing
"
TEST_FILE
=
Path
.
cwd
()
/
'
tests/resources/test_terminal_fragments.txt
'
,
class
TestParseArgs
:
"""
Test ``parse_args()`` function.
"""
def
test_help_option
(
self
,
monkeypatch
):
"""
Test help option.
"""
monkeypatch
.
setattr
(
sys
,
'
argv
'
,
[
'
htsinfer
'
,
'
--help
'
,
]
)
with
pytest
.
raises
(
SystemExit
)
as
exc
:
assert
parse_args
()
assert
exc
.
value
.
code
==
0
def
test_one_positional_arg
(
self
,
monkeypatch
):
"""
Call with one positional arg.
"""
monkeypatch
.
setattr
(
sys
,
'
argv
'
,
[
str
(
TEST_FILE
),
]
)
ret_val
=
parse_args
()
assert
isinstance
(
ret_val
,
argparse
.
Namespace
)
def
test_too_many_positional_args
(
self
,
monkeypatch
):
"""
Call with two positional args.
"""
monkeypatch
.
setattr
(
sys
,
'
argv
'
,
[
'
htsinfer
'
,
str
(
TEST_FILE
),
str
(
TEST_FILE
),
]
)
with
pytest
.
raises
(
SystemExit
)
as
exc
:
parse_args
()
assert
exc
.
value
.
code
!=
0
class
TestMain
:
"""
Test ``main()`` function.
"""
def
test_with_too_many_args
(
self
,
monkeypatch
):
"""
Call with too many positional args.
"""
monkeypatch
.
setattr
(
sys
,
'
argv
'
,
[
'
read_sequencing
'
,
str
(
TEST_FILE
),
str
(
TEST_FILE
),
]
)
with
pytest
.
raises
(
SystemExit
)
as
exc
:
main
()
assert
exc
.
value
.
code
!=
0
def
test_keyboard_interrupt
(
self
,
monkeypatch
):
"""
Test keyboard interrupt.
"""
class
RaiseKeyboardInterrupt
:
"""
Helper class to raise `ValueError`.
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
"""
Class constructor.
"""
raise
KeyboardInterrupt
monkeypatch
.
setattr
(
'
src.read_sequencing.cli.parse_args
'
,
RaiseKeyboardInterrupt
,
)
with
pytest
.
raises
(
SystemExit
)
as
exc
:
main
()
assert
exc
.
value
.
code
>=
128
def
test_main_as_script
():
"""
Run as script.
"""
main_file
=
PACKAGE_DIR
/
"
cli.py
"
fl
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
main_file
)
spec
=
importlib
.
util
.
spec_from_file_location
(
'
__main__
'
,
fl
)
module
=
importlib
.
util
.
module_from_spec
(
spec
)
with
pytest
.
raises
(
SystemExit
)
as
exc
:
spec
.
loader
.
exec_module
(
module
)
# type: ignore
assert
exc
.
value
.
code
!=
0
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