adding test cases, adding logger

This commit is contained in:
Tomasz Frątczak 2024-02-16 22:35:01 +01:00
parent 1b15792e00
commit 13ae7e5b57
8 changed files with 83 additions and 34 deletions

View File

@ -3,7 +3,7 @@
## Usage
```bash
python notescriber.py
python notescriber.py --path /path/to/data
```
## Testing

View File

@ -1,7 +1,23 @@
#!/usr/bin/env python
from notescriber import picker
# from notescriber import picker
# from notescriber import config
# from notescriber import dispatcher
# from notescriber import notetaker
# from notescriber import transcriber
import notescriber
import logging
if __name__ == '__main__':
config = notescriber.config.Config()
config.load_config(".config.yaml")
dispatcher = notescriber.dispatcher.Dispatcher()
notetaker = notescriber.notetaker.Notetaker(config.username,config.password, config.url)
picker = notescriber.picker.Picker(config.path, dispatcher)
transcriber = notescriber.transcriber.Transcriber()
dispatcher.add_note_generator(notetaker)
dispatcher.add_audio_processor(transcriber)
picker.observe()

View File

@ -4,13 +4,16 @@ from notescriber import dispatcher
from notescriber import notetaker
from notescriber import picker
from notescriber import transcriber
import logging
config = config.Config()
config.load_config(".config.yaml")
dispatcher = dispatcher.Dispatcher()
notetaker = notetaker.Notetaker(config.username,config.password, config.url)
picker = picker.Picker(config.path, dispatcher)
transcriber = transcriber.Transcriber()
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
dispatcher.add_note_generator(notetaker)
dispatcher.add_audio_processor(transcriber)
# config = config.Config()
# config.load_config(".config.yaml")
# dispatcher = dispatcher.Dispatcher()
# notetaker = notetaker.Notetaker(config.username,config.password, config.url)
# picker = picker.Picker(config.path, dispatcher)
# transcriber = transcriber.Transcriber()
# dispatcher.add_note_generator(notetaker)
# dispatcher.add_audio_processor(transcriber)

View File

@ -1,4 +1,5 @@
import argparse
import logging
import yaml
class Config:
@ -24,4 +25,4 @@ class Config:
self.path = self.parse_args().path
if self.path is None:
self.path = confFile['path']
print(self.path)
logging.info(f"Loaded config from {path}")

View File

@ -1,3 +1,4 @@
import logging
import time
import os
@ -7,7 +8,6 @@ class Picker:
directory = None
dispatcher = None
observer = None
last_file_marker = None
def __init__(self, directory, dispatcher):
@ -33,14 +33,6 @@ class Picker:
if file_marker < marker:
return file
def identify_time_window(self, file_time):
if self.last_file_time is None:
self.last_file_time = time.time()
if file_time > self.last_file_time:
return True
return False
def list_files(self):
files = []
for filename in os.listdir(self.directory):
@ -50,6 +42,7 @@ class Picker:
return files
def observe(self):
logging.info(f"Watching directory: {self.directory}")
while True:
file_marker = self.read_last_file_marker()
files = self.list_files()

View File

@ -1,4 +1,5 @@
import whisper
import logging
class Transcriber:
@ -8,6 +9,6 @@ class Transcriber:
self.model = whisper.load_model("base")
def execute(self, audio_file):
print("Transcribing audio file: " + audio_file)
logging.info(f"Transcribing audio file: {audio_file}")
result = self.model.transcribe(audio_file)
return result['text']

View File

@ -1,16 +1,16 @@
import unittest
from notescriber.config import Config
# import unittest
# from notescriber.config import Config
class TranscriptorTest(unittest.TestCase):
def setUp(self):
pass
# class TranscriptorTest(unittest.TestCase):
# def setUp(self):
# pass
def tearDown(self):
pass
# def tearDown(self):
# pass
def test_run(self):
cfg = Config()
cfg.load_config(path="example.config.yaml")
self.assertEqual("username", cfg.username)
self.assertEqual("password", cfg.password)
self.assertEqual("url.org", cfg.url)
# def test_run(self):
# cfg = Config()
# cfg.load_config(path="example.config.yaml")
# self.assertEqual("username", cfg.username)
# self.assertEqual("password", cfg.password)
# self.assertEqual("url.org", cfg.url)

35
tests/picker_test.py Normal file
View File

@ -0,0 +1,35 @@
import unittest
from notescriber.picker import Picker
class FakeDispatcher:
def process_audio_file(filename):
pass
class TranscriptorTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_constructor(self):
directory = "/data"
dispatcher = FakeDispatcher()
picker = Picker(directory, dispatcher)
self.assertEqual(directory, picker.directory)
self.assertEqual(dispatcher, picker.dispatcher)
def test_read_file_marker(self):
pass
def test_update_last_file_marker(self):
pass
def find_next_file(self):
pass
def test_list_files(self):
pass
def test_observe(self):
pass