Skip to content

Commit

Permalink
Fixed pytests
Browse files Browse the repository at this point in the history
  • Loading branch information
mazzalab committed Dec 9, 2024
1 parent 45dbdac commit 6b32f17
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"python.analysis.autoImportCompletions": true,
"python.analysis.typeCheckingMode": "basic"
"python.analysis.typeCheckingMode": "basic",
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
5 changes: 3 additions & 2 deletions fastqwiper/fastq_wiper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from enum import auto, Enum
from pathlib import Path
from typing import Pattern, TextIO
from wipertool_abstract import WiperTool
from fastqwiper.wipertool_abstract import WiperTool


# region Variables for final report
Expand Down Expand Up @@ -65,6 +65,7 @@ def file_choices(choices, fname):
if ext not in choices:
parser.error(
f"File '{fname}' doesn't end with one of {choices}")
raise ValueError(f"File '{fname}' doesn't end with one of {choices}")
return fname

parser.add_argument("-i", "--fastq_in", help="FASTQ file to be wiped", type=lambda s: file_choices(
Expand Down Expand Up @@ -188,7 +189,7 @@ def open_fastq_file(self, file_path: str) -> None | TextIO:
fastq_file_handler = codecs.open(
file_path, encoding="utf-8", errors="replace"
)

return fastq_file_handler

def read_next_line(self, fin: TextIO, log_frequency: int) -> str:
Expand Down
29 changes: 15 additions & 14 deletions tests/test_fastq_wiper.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,35 @@ def fw_bad_fastq(fw):
def fw_parser():
fastq_in: str = "./tests/testdata/bad.fastq"
fastq_out: str = "./tests/testdata/bad_wiped.fastq"
log_out: str = "./tests/testdata/bad.log"
report: str = "./tests/testdata/bad.report"
log_frequency: int = 100
alphabet: str = "ACGTN"

return argparse.Namespace(
fastq_in=fastq_in,
fastq_out=fastq_out,
log_out=log_out,
report=report,
log_frequency=log_frequency,
alphabet=alphabet,
)


@pytest.fixture
def fw_run(fw, fw_parser):
fw.run(fw_parser)

print("\nSetting up resources...")
with open("./tests/testdata/bad_wiped.fastq", "r") as file:
data = file.read()
with open("./tests/testdata/bad.log", "r") as file_log:
with open("./tests/testdata/bad.report", "r") as file_log:
data_log = file_log.read()

# Execute the actual test
yield (data, data_log)

print("\nTearing down resources...")
os.remove("./tests/testdata/bad_wiped.fastq")
os.remove("./tests/testdata/bad.log")
os.remove("./tests/testdata/bad.report")


def test_set_parser(fw, fw_parser):
Expand All @@ -76,6 +77,14 @@ def test_set_parser(fw, fw_parser):
# print(f"\n{excinfo.value}")


def test_set_parser_bad_argument_ext(fw, fw_parser):
fw_parser.fastq_out = "wrong_ext.txt"

with pytest.raises(ValueError):
fw.set_parser(fw_parser)
# print(f"\n{excinfo.value}")


def test_run(fw_run):
with open("./tests/testdata/bad_wiped_test.fastq", "r") as file_test:
data_test = file_test.read()
Expand All @@ -91,16 +100,8 @@ def test_run_wrong_filein(fw, fw_parser):
# print(f"\n{excinfo.value}")


def test_run_wrong_fileout(fw, fw_parser):
fw_parser.fastq_out = "wrong_file.txt"

with pytest.raises(ValueError):
fw.run(fw_parser)
# print(f"\n{excinfo.value}")


def test_summary(fw_run):
with open("./tests/testdata/bad_test.log", "r") as file_log_test:
def test_report(fw_run):
with open("./tests/testdata/bad_test.report", "r") as file_log_test:
data_test = file_log_test.read()

assert fw_run[1] == data_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FASTQWIPER SUMMARY:
FASTQWIPER REPORT:

Total lines: 60
Well-formed lines: 16 (26.67%)
Clean reads: 4Bad headers or misplaced lines: 10 (16.67%) of which 4 fixed
Clean reads: 4
Bad headers or misplaced lines: 10 (16.67%) of which 4 fixed
BAD SEQ lines: 2 (3.33%)
BAD '+' lines: 2 (3.33%)
BAD QUAL lines: 2 (3.33%)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FASTQWIPER SUMMARY:
FASTQWIPER REPORT:

Total lines: 30
Well-formed lines: 8 (26.67%)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FASTQWIPER SUMMARY:
FASTQWIPER REPORT:

Total lines: 12
Well-formed lines: 2 (16.67%)
Expand Down

0 comments on commit 6b32f17

Please sign in to comment.