forked from rc/aircox
code quality
This commit is contained in:
@ -1,2 +1,15 @@
|
||||
from .sound_file import *
|
||||
from .sound_monitor import *
|
||||
from .sound_file import SoundFileTestCase
|
||||
from .sound_monitor import (
|
||||
ModifiedHandlerTestCase,
|
||||
MonitorHandlerTestCase,
|
||||
MoveHandlerTestCase,
|
||||
NotifyHandlerTestCase,
|
||||
)
|
||||
|
||||
__all__ = (
|
||||
"SoundFileTestCase",
|
||||
"NotifyHandlerTestCase",
|
||||
"MoveHandlerTestCase",
|
||||
"ModifiedHandlerTestCase",
|
||||
"MonitorHandlerTestCase",
|
||||
)
|
||||
|
@ -7,30 +7,56 @@ from django.utils import timezone as tz
|
||||
from aircox import models
|
||||
from aircox.management.sound_file import SoundFile
|
||||
|
||||
|
||||
__all__ = ('SoundFileTestCase',)
|
||||
__all__ = ("SoundFileTestCase",)
|
||||
|
||||
|
||||
class SoundFileTestCase(TestCase):
|
||||
path_infos = {
|
||||
'test/20220101_10h13_1_sample_1.mp3': {
|
||||
'year': 2022, 'month': 1, 'day': 1, 'hour': 10, 'minute': 13,
|
||||
'n': 1, 'name': 'Sample 1'},
|
||||
'test/20220102_10h13_sample_2.mp3': {
|
||||
'year': 2022, 'month': 1, 'day': 2, 'hour': 10, 'minute': 13,
|
||||
'name': 'Sample 2'},
|
||||
'test/20220103_1_sample_3.mp3': {
|
||||
'year': 2022, 'month': 1, 'day': 3, 'n': 1, 'name': 'Sample 3'},
|
||||
'test/20220104_sample_4.mp3': {
|
||||
'year': 2022, 'month': 1, 'day': 4, 'name': 'Sample 4'},
|
||||
'test/20220105.mp3': {
|
||||
'year': 2022, 'month': 1, 'day': 5, 'name': '20220105'},
|
||||
"test/20220101_10h13_1_sample_1.mp3": {
|
||||
"year": 2022,
|
||||
"month": 1,
|
||||
"day": 1,
|
||||
"hour": 10,
|
||||
"minute": 13,
|
||||
"n": 1,
|
||||
"name": "Sample 1",
|
||||
},
|
||||
"test/20220102_10h13_sample_2.mp3": {
|
||||
"year": 2022,
|
||||
"month": 1,
|
||||
"day": 2,
|
||||
"hour": 10,
|
||||
"minute": 13,
|
||||
"name": "Sample 2",
|
||||
},
|
||||
"test/20220103_1_sample_3.mp3": {
|
||||
"year": 2022,
|
||||
"month": 1,
|
||||
"day": 3,
|
||||
"n": 1,
|
||||
"name": "Sample 3",
|
||||
},
|
||||
"test/20220104_sample_4.mp3": {
|
||||
"year": 2022,
|
||||
"month": 1,
|
||||
"day": 4,
|
||||
"name": "Sample 4",
|
||||
},
|
||||
"test/20220105.mp3": {
|
||||
"year": 2022,
|
||||
"month": 1,
|
||||
"day": 5,
|
||||
"name": "20220105",
|
||||
},
|
||||
}
|
||||
subdir_prefix = "test"
|
||||
sound_files = {
|
||||
k: r
|
||||
for k, r in (
|
||||
(path, SoundFile(conf.MEDIA_ROOT + "/" + path))
|
||||
for path in path_infos.keys()
|
||||
)
|
||||
}
|
||||
subdir_prefix = 'test'
|
||||
sound_files = {k: r for k, r in (
|
||||
(path, SoundFile(conf.MEDIA_ROOT + '/' + path))
|
||||
for path in path_infos.keys()
|
||||
)}
|
||||
|
||||
def test_sound_path(self):
|
||||
for path, sound_file in self.sound_files.items():
|
||||
@ -45,21 +71,25 @@ class SoundFileTestCase(TestCase):
|
||||
self.assertEqual(expected, result, "path: {}".format(path))
|
||||
|
||||
def _setup_diff(self, 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)
|
||||
})
|
||||
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.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
|
||||
|
||||
def test_find_episode(self):
|
||||
station = models.Station(name='test-station')
|
||||
program = models.Program(station=station, title='test')
|
||||
station = models.Station(name="test-station")
|
||||
program = models.Program(station=station, title="test")
|
||||
station.save()
|
||||
program.save()
|
||||
|
||||
|
@ -1,15 +1,21 @@
|
||||
import concurrent.futures as futures
|
||||
from datetime import datetime, timedelta
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from aircox.management.sound_monitor import \
|
||||
NotifyHandler, MoveHandler, ModifiedHandler, MonitorHandler
|
||||
from aircox.management.sound_monitor import (
|
||||
ModifiedHandler,
|
||||
MonitorHandler,
|
||||
NotifyHandler,
|
||||
)
|
||||
|
||||
|
||||
__all__ = ('NotifyHandlerTestCase', 'MoveHandlerTestCase',
|
||||
'ModifiedHandlerTestCase', 'MonitorHandlerTestCase',)
|
||||
__all__ = (
|
||||
"NotifyHandlerTestCase",
|
||||
"MoveHandlerTestCase",
|
||||
"ModifiedHandlerTestCase",
|
||||
"MonitorHandlerTestCase",
|
||||
)
|
||||
|
||||
|
||||
class FakeEvent:
|
||||
@ -57,21 +63,21 @@ class ModifiedHandlerTestCase(TestCase):
|
||||
class MonitorHandlerTestCase(TestCase):
|
||||
def setUp(self):
|
||||
pool = futures.ThreadPoolExecutor(2)
|
||||
self.monitor = MonitorHandler('archives', pool)
|
||||
self.monitor = MonitorHandler("archives", pool)
|
||||
|
||||
def test_submit_new_job(self):
|
||||
event = FakeEvent(src_path='dummy_src')
|
||||
event = FakeEvent(src_path="dummy_src")
|
||||
handler = NotifyHandler()
|
||||
result, _ = self.monitor._submit(handler, event, 'up')
|
||||
result, _ = self.monitor._submit(handler, event, "up")
|
||||
self.assertIs(handler, result)
|
||||
self.assertIsInstance(handler.future, futures.Future)
|
||||
self.monitor.pool.shutdown()
|
||||
|
||||
def test_submit_job_exists(self):
|
||||
event = FakeEvent(src_path='dummy_src')
|
||||
event = FakeEvent(src_path="dummy_src")
|
||||
|
||||
job_1, new_1 = self.monitor._submit(WaitHandler(), event, 'up')
|
||||
job_2, new_2 = self.monitor._submit(NotifyHandler(), event, 'up')
|
||||
job_1, new_1 = self.monitor._submit(WaitHandler(), event, "up")
|
||||
job_2, new_2 = self.monitor._submit(NotifyHandler(), event, "up")
|
||||
self.assertIs(job_1, job_2)
|
||||
self.assertTrue(new_1)
|
||||
self.assertFalse(new_2)
|
||||
|
Reference in New Issue
Block a user