Feat: packaging (#127)

- Add configuration files for packaging
- Precommit now uses ruff

Co-authored-by: bkfox <thomas bkfox net>
Reviewed-on: rc/aircox#127
This commit is contained in:
Thomas Kairos
2023-10-11 10:58:34 +02:00
parent 5ea092dba6
commit f7a61fe6c0
82 changed files with 332 additions and 935 deletions

View File

@ -21,30 +21,21 @@ class TestDiffusion:
def test_update(self, monitor, schedules, sched_initials, logger):
monitor.update()
diffusions = models.Diffusion.objects.filter(
schedule__in=sched_initials
)
diffusions = models.Diffusion.objects.filter(schedule__in=sched_initials)
by_date = {}
for diff in diffusions:
assert diff.episode_id
by_date.setdefault(diff.schedule_id, set()).add(
(diff.start, diff.end)
)
by_date.setdefault(diff.schedule_id, set()).add((diff.start, diff.end))
for schedule in sched_initials:
if schedule.pk not in by_date:
continue
_, items = schedule.diffusions_of_month(now)
assert all(
(item.start, item.end) in by_date[schedule.pk]
for item in items
)
assert all((item.start, item.end) in by_date[schedule.pk] for item in items)
@pytest.mark.django_db
def test_clean(self, monitor, episode):
start = tz.make_aware(
datetime.combine(monitor.date - timedelta(days=1), time(10, 20))
)
start = tz.make_aware(datetime.combine(monitor.date - timedelta(days=1), time(10, 20)))
diff = models.Diffusion(
type=models.Diffusion.TYPE_UNCONFIRMED,
episode=episode,

View File

@ -79,16 +79,12 @@ class TestLogArchiver:
def test_archive_then_load_file(self, archiver, file, gzip, logs, logs_qs):
# before logs are deleted from db, get data
sorted = archiver.sort_logs(logs_qs)
paths = {
archiver.get_path(station, date) for station, date in sorted.keys()
}
paths = {archiver.get_path(station, date) for station, date in sorted.keys()}
count = archiver.archive(logs_qs, keep=False)
assert count == len(logs)
assert not logs_qs.count()
assert all(
path in paths for path, *_ in gzip._traces("open", args=True)
)
assert all(path in paths for path, *_ in gzip._traces("open", args=True))
results = archiver.load_file("dummy path")
assert results
@ -104,7 +100,4 @@ class TestLogArchiver:
assert sorted
for (station, date), logs in sorted.items():
assert all(
log.station == station and log.date.date() == date
for log in logs
)
assert all(log.station == station and log.date.date() == date for log in logs)

View File

@ -53,13 +53,7 @@ def path_infos():
@pytest.fixture
def sound_files(path_infos):
return {
k: r
for k, r in (
(path, SoundFile(conf.MEDIA_ROOT + "/" + path))
for path in path_infos.keys()
)
}
return {k: r for k, r in ((path, SoundFile(conf.MEDIA_ROOT + "/" + path)) for path in path_infos.keys())}
def test_sound_path(sound_files):
@ -78,17 +72,9 @@ def test_read_path(path_infos, sound_files):
def _setup_diff(program, info):
episode = models.Episode(program=program, title="test-episode")
at = tz.datetime(
**{
k: info[k]
for k in ("year", "month", "day", "hour", "minute")
if info.get(k)
}
)
at = tz.datetime(**{k: info[k] for k in ("year", "month", "day", "hour", "minute") if info.get(k)})
at = tz.make_aware(at)
diff = models.Diffusion(
episode=episode, start=at, end=at + timedelta(hours=1)
)
diff = models.Diffusion(episode=episode, start=at, end=at + timedelta(hours=1))
episode.save()
diff.save()
return diff

View File

@ -92,9 +92,7 @@ class TestTask:
task.log_msg = "--{event.src_path}--"
sound_file = task(event, logger=logger, kw=13)
assert sound_file._trace("sync", kw=True) == {"kw": 13}
assert logger._trace("info", args=True) == (
task.log_msg.format(event=event),
)
assert logger._trace("info", args=True) == (task.log_msg.format(event=event),)
class TestDeleteTask:
@ -125,9 +123,7 @@ class TestModifiedTask:
datetime = Interface.inject(sound_monitor, "datetime", {"now": dt_now})
def sleep(imeta, n):
datetime._imeta.funcs[
"now"
] = modified_task.timestamp + tz.timedelta(hours=10)
datetime._imeta.funcs["now"] = modified_task.timestamp + tz.timedelta(hours=10)
time = Interface.inject(sound_monitor, "time", {"sleep": sleep})
modified_task.wait()
@ -175,9 +171,7 @@ class TestMonitorHandler:
def test__submit(self, monitor_handler, event):
handler = Interface()
handler, created = monitor_handler._submit(
handler, event, "prefix", kw=13
)
handler, created = monitor_handler._submit(handler, event, "prefix", kw=13)
assert created
assert handler.future._trace("add_done_callback")
assert monitor_handler.pool._trace("submit") == (
@ -192,9 +186,7 @@ class TestMonitorHandler:
@pytest.fixture
def monitor_interfaces():
items = {
"atexit": Interface.inject(
sound_monitor, "atexit", {"register": None, "leave": None}
),
"atexit": Interface.inject(sound_monitor, "atexit", {"register": None, "leave": None}),
"observer": Interface.inject(
sound_monitor,
"Observer",

View File

@ -38,12 +38,8 @@ sox_values = {
@pytest.fixture
def sox_interfaces():
process = Interface(
None, {"communicate": ("", sox_output.encode("utf-8"))}
)
subprocess = Interface.inject(
sound_stats, "subprocess", {"Popen": lambda *_, **__: process}
)
process = Interface(None, {"communicate": ("", sox_output.encode("utf-8"))})
subprocess = Interface.inject(sound_stats, "subprocess", {"Popen": lambda *_, **__: process})
yield {"process": process, "subprocess": subprocess}
subprocess._irelease()
@ -110,9 +106,7 @@ class TestSoundStats:
def test_check(self, stats):
good = [{"val": i} for i in range(0, 11)]
bad = [{"val": i} for i in range(-10, 0)] + [
{"val": i} for i in range(11, 20)
]
bad = [{"val": i} for i in range(-10, 0)] + [{"val": i} for i in range(11, 20)]
stats.stats = good + bad
calls = {}
stats.resume = lambda *_: calls.setdefault("resume", True)