From 13ae7e5b57d2eb36f757c1b40f1cfa8c05964bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Fr=C4=85tczak?= Date: Fri, 16 Feb 2024 22:35:01 +0100 Subject: [PATCH] adding test cases, adding logger --- README.md | 2 +- notescriber.py | 18 +++++++++++++++++- notescriber/__init__.py | 19 +++++++++++-------- notescriber/config.py | 3 ++- notescriber/picker.py | 11 ++--------- notescriber/transcriber.py | 3 ++- tests/config_test.py | 26 +++++++++++++------------- tests/picker_test.py | 35 +++++++++++++++++++++++++++++++++++ 8 files changed, 83 insertions(+), 34 deletions(-) create mode 100644 tests/picker_test.py diff --git a/README.md b/README.md index e30a556..2769f8b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## Usage ```bash -python notescriber.py +python notescriber.py --path /path/to/data ``` ## Testing diff --git a/notescriber.py b/notescriber.py index aedce18..ed6f36e 100755 --- a/notescriber.py +++ b/notescriber.py @@ -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() \ No newline at end of file diff --git a/notescriber/__init__.py b/notescriber/__init__.py index 4f377d9..34f4f33 100644 --- a/notescriber/__init__.py +++ b/notescriber/__init__.py @@ -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) \ No newline at end of file +# 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) \ No newline at end of file diff --git a/notescriber/config.py b/notescriber/config.py index 61fcd5e..58fc0d6 100644 --- a/notescriber/config.py +++ b/notescriber/config.py @@ -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) \ No newline at end of file + logging.info(f"Loaded config from {path}") \ No newline at end of file diff --git a/notescriber/picker.py b/notescriber/picker.py index 99fa4bd..3123949 100644 --- a/notescriber/picker.py +++ b/notescriber/picker.py @@ -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() diff --git a/notescriber/transcriber.py b/notescriber/transcriber.py index ec3529a..002ddd8 100644 --- a/notescriber/transcriber.py +++ b/notescriber/transcriber.py @@ -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'] diff --git a/tests/config_test.py b/tests/config_test.py index 3aa0611..2ef7c15 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -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) diff --git a/tests/picker_test.py b/tests/picker_test.py new file mode 100644 index 0000000..e2abfac --- /dev/null +++ b/tests/picker_test.py @@ -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 \ No newline at end of file