test: audit suite for meaningfulness, reach 100% coverage
The suite had 8 empty `pass` tests, two tests that made live network calls to a production healthcheck endpoint, and a write_csv test that only asserted the file existed. CI ran only test_komodo_deploy, so the main suite never executed at all. - Split tests by module: test_qlist, test_qprocess, test_qlogging_extra, test_apprise, test_qbt; rewrote test_qbitmaid and test_write_csv. - qbt_fakes.py: shared fakes (FakeQbt, FakeQbtClient, FakeAPIError, StubPushover, FailingPushover, torrent factory). - test_qbt.py loads the hyphenated qbit-maid.py via importlib and covers the __main__ entry point. - Replaced the live-network tests with a RecordingRequests stub (suite time 14s -> 0.035s). - .coveragerc + CI unit-tests job running the full suite with --fail-under=100. 127 unit tests, 100% statement coverage on all 5 first-party modules (440 stmts), 15/15 mutations caught. Seven pre-existing bugs are pinned by tests with KNOWN BUG docstrings and left unfixed pending a decision.
This commit is contained in:
1 parent
5b54d9e558
commit
925f9619be
10 files changed
+1645
-461
No files matched your search
+50
-41
@@ -1,41 +1,50 @@
|
||||
from qprocess import write_csv
|
||||
import csv
|
||||
import unittest
|
||||
import os
|
||||
# Torrent Items needed for testing
|
||||
# canidate['state'] {canidate["ratio"]} {torrent["tags"]} torrent["seeding_time"] {torrent["category"]} {torrent["name"][0:20]} {canidate["time_active"]}
|
||||
class TestWriteCSV(unittest.TestCase):
|
||||
def test_write_csv_dragnet(self):
|
||||
self.cv = csv
|
||||
outfile = './test_dragnet_outfile.csv'
|
||||
state = 'downloading'
|
||||
ratio = 1.05
|
||||
tags = 'ipt'
|
||||
added = 1
|
||||
age = 240000
|
||||
time = 123456
|
||||
thash = 'asfasdf23412adfqwer'
|
||||
tname = 'thisismynamehahahah'
|
||||
trname = 'https://localhost.stackoverflow.tech/317332f1c125bc9c1b9b14fb8e054908/announce'
|
||||
header = ['state','ratio','tags','added','age','time','thash','tname','trname']
|
||||
row = [state,ratio,tags,added,age,time,thash,tname,trname]
|
||||
write_csv(self.cv,outfile,header,row)
|
||||
self.assertTrue(os.path.exists(outfile))
|
||||
|
||||
def test_write_csv_telemetry(self):
|
||||
self.cv = csv
|
||||
outfile = './test_telemetry_outfile.csv'
|
||||
state = 'downloading'
|
||||
ratio = 1.05
|
||||
tags = 'ipt'
|
||||
added = 1
|
||||
thash = 'asfasdf23412adfqwer'
|
||||
tname = 'thisismynamehahahah'
|
||||
trname = 'https://localhost.stackoverflow.tech/317332f1c125bc9c1b9b14fb8e054908/announce'
|
||||
header = ['state','ratio','tags','added','hash','name','tracker']
|
||||
row = [state,ratio,tags,added,thash,tname,trname]
|
||||
write_csv(self.cv,outfile,header,row)
|
||||
self.assertTrue(os.path.exists(outfile))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
"""Tests for qprocess.write_csv — header-once, append semantics."""
|
||||
import csv
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from qprocess import write_csv
|
||||
|
||||
HEADER = ["state", "ratio", "tags", "added", "hash", "name", "tracker"]
|
||||
ROW = ["downloading", 1.05, "ipt", 1, "asfasdf23412adfqwer",
|
||||
"thisismynamehahahah", "https://localhost.stackoverflow.tech/announce"]
|
||||
|
||||
|
||||
class TestWriteCSV(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, self.tmp, ignore_errors=True)
|
||||
self.outfile = os.path.join(self.tmp, "out.csv")
|
||||
|
||||
def read_rows(self):
|
||||
with open(self.outfile, newline="", encoding="UTF8") as fh:
|
||||
return list(csv.reader(fh))
|
||||
|
||||
def test_writes_header_then_row(self):
|
||||
write_csv(csv, self.outfile, HEADER, ROW)
|
||||
rows = self.read_rows()
|
||||
self.assertEqual(rows[0], HEADER)
|
||||
self.assertEqual(len(rows), 2)
|
||||
self.assertEqual(rows[1][4], "asfasdf23412adfqwer")
|
||||
|
||||
def test_header_is_written_only_once(self):
|
||||
write_csv(csv, self.outfile, HEADER, ROW)
|
||||
write_csv(csv, self.outfile, HEADER, ROW)
|
||||
rows = self.read_rows()
|
||||
self.assertEqual(rows.count(HEADER), 1)
|
||||
self.assertEqual(len(rows), 3)
|
||||
|
||||
def test_creates_the_file_when_missing(self):
|
||||
self.assertFalse(os.path.exists(self.outfile))
|
||||
write_csv(csv, self.outfile, HEADER, ROW)
|
||||
self.assertTrue(os.path.exists(self.outfile))
|
||||
|
||||
def test_values_are_round_tripped(self):
|
||||
write_csv(csv, self.outfile, HEADER, ROW)
|
||||
self.assertEqual(self.read_rows()[1], [str(value) for value in ROW])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user