Skip to content

Commit

Permalink
style: correct style with black
Browse files Browse the repository at this point in the history
  • Loading branch information
deliaBlue committed Dec 2, 2023
1 parent 58a33e2 commit 52a1910
Show file tree
Hide file tree
Showing 6 changed files with 764 additions and 484 deletions.
128 changes: 73 additions & 55 deletions scripts/tests/test_filter_multimappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
find_best_alignments,
main,
parse_arguments,
write_output
write_output,
)


Expand Down Expand Up @@ -143,21 +143,20 @@ class TestParseArguments:
def test_no_input(self, monkeypatch):
"""Call without input file."""
with pytest.raises(SystemExit) as sysex:
monkeypatch.setattr(
sys, 'argv',
['filter_multimappers']
)
monkeypatch.setattr(sys, "argv", ["filter_multimappers"])
parse_arguments().parse_args()
assert sysex.value.code == 2

def test_correct_input(self, monkeypatch, sam_no_multimappers_file):
"""Call with a single input file."""
sam_1 = sam_no_multimappers_file
monkeypatch.setattr(
sys, 'argv',
['filter_multimappers',
str(sam_1),
]
sys,
"argv",
[
"filter_multimappers",
str(sam_1),
],
)
args = parse_arguments().parse_args()
assert isinstance(args, argparse.Namespace)
Expand All @@ -166,11 +165,13 @@ def test_all_input_options(self, monkeypatch, sam_no_multimappers_file):
"""Call with a single input file and the --nh option."""
sam_1 = sam_no_multimappers_file
monkeypatch.setattr(
sys, 'argv',
['filter_multimappers',
str(sam_1),
'--nh',
]
sys,
"argv",
[
"filter_multimappers",
str(sam_1),
"--nh",
],
)
args = parse_arguments().parse_args()
assert isinstance(args, argparse.Namespace)
Expand All @@ -179,10 +180,13 @@ def test_too_many_inputs(self, monkeypatch, sam_multimappers_files):
"""Call with too many input files."""
sam_1, sam_2 = sam_multimappers_files
monkeypatch.setattr(
sys, 'argv',
['filter_multimappers',
str(sam_1), str(sam_2),
]
sys,
"argv",
[
"filter_multimappers",
str(sam_1),
str(sam_2),
],
)
with pytest.raises(SystemExit) as sysex:
parse_arguments().parse_args()
Expand Down Expand Up @@ -270,16 +274,16 @@ def test_write_output_one_alignment(self, capsys, sam_multimappers_files):
"""Test funciton with a single alignment."""
in_sam, out_sam = sam_multimappers_files

with pysam.AlignmentFile(in_sam, 'r') as in_file:
with pysam.AlignmentFile(in_sam, "r") as in_file:
alignment = next(in_file)

write_output([alignment])
captured = capsys.readouterr()

with pysam.AlignmentFile(out_sam, 'r') as out_file:
with pysam.AlignmentFile(out_sam, "r") as out_file:
out_alignment = next(out_file)

assert captured.out == out_alignment.to_string() + '\n'
assert captured.out == out_alignment.to_string() + "\n"


class TestMain:
Expand All @@ -290,87 +294,101 @@ def test_main_empty_file(self, capsys, monkeypatch, sam_empty_file):
empty_file = sam_empty_file

monkeypatch.setattr(
sys, 'argv',
['filter_multimappers',
str(empty_file),
]
sys,
"argv",
[
"filter_multimappers",
str(empty_file),
],
)
args = parse_arguments().parse_args()
main(args)
captured = capsys.readouterr()

with open(empty_file, 'r') as out_file:
with open(empty_file, "r") as out_file:
assert captured.out == out_file.read()

def test_main_multimappers(self, capsys, monkeypatch,
sam_multimappers_files):
def test_main_multimappers(
self, capsys, monkeypatch, sam_multimappers_files
):
"""Test main function with multimappers."""
in_sam, out_sam = sam_multimappers_files

monkeypatch.setattr(
sys, 'argv',
['filter_multimappers',
str(in_sam),
]
sys,
"argv",
[
"filter_multimappers",
str(in_sam),
],
)
args = parse_arguments().parse_args()
main(args)
captured = capsys.readouterr()

with open(out_sam, 'r') as out_file:
with open(out_sam, "r") as out_file:
assert captured.out == out_file.read()

def test_main_multimappers_nh(self, capsys, monkeypatch,
sam_multimappers_nh_files):
def test_main_multimappers_nh(
self, capsys, monkeypatch, sam_multimappers_nh_files
):
"""Test main function with multimappers with nh argument."""
in_sam, out_sam = sam_multimappers_nh_files

monkeypatch.setattr(
sys, 'argv',
['filter_multimappers',
str(in_sam),
'--nh',
]
sys,
"argv",
[
"filter_multimappers",
str(in_sam),
"--nh",
],
)
args = parse_arguments().parse_args()
main(args)
captured = capsys.readouterr()

with open(out_sam, 'r') as out_file:
with open(out_sam, "r") as out_file:
assert captured.out == out_file.read()

def test_main_no_multimappers(self, capsys, monkeypatch,
sam_no_multimappers_file):
def test_main_no_multimappers(
self, capsys, monkeypatch, sam_no_multimappers_file
):
"""Test main function with no multimappers."""
sam_file = sam_no_multimappers_file

monkeypatch.setattr(
sys, 'argv',
['filter_multimappers',
str(sam_file),
]
sys,
"argv",
[
"filter_multimappers",
str(sam_file),
],
)
args = parse_arguments().parse_args()
main(args)
captured = capsys.readouterr()

with open(sam_file, 'r') as out_file:
with open(sam_file, "r") as out_file:
assert captured.out == out_file.read()

def test_main_secondary_supplementary(self, capsys, monkeypatch,
sam_sec_sup_files):
def test_main_secondary_supplementary(
self, capsys, monkeypatch, sam_sec_sup_files
):
"""Test main function with secondary and supplementary alignments."""
in_sam, out_sam = sam_sec_sup_files

monkeypatch.setattr(
sys, 'argv',
['filter_multimappers',
str(in_sam),
]
sys,
"argv",
[
"filter_multimappers",
str(in_sam),
],
)
args = parse_arguments().parse_args()
main(args)
captured = capsys.readouterr()

with open(out_sam, 'r') as out_file:
with open(out_sam, "r") as out_file:
assert captured.out == out_file.read()
Loading

0 comments on commit 52a1910

Please sign in to comment.