asr_system / tests /test_job_errors.py
Consulawtech's picture
Claude Opus 5.5 (1M context)
Fix 'NoneType has no attribute tokenizer' and harden job failures
c98b787
Raw History Blame Contribute Delete
2.48 kB
import unittest
from types import SimpleNamespace
try:
import app as api
except Exception as exc: # heavy optional deps missing
api = None
_err = exc
@unittest.skipIf(api is None, "app import needs the server dependencies")
class FailureMessages(unittest.TestCase):
def test_user_part_and_staff_part(self):
d = api._failure_detail(AttributeError("'NoneType' object has no attribute 'tokenizer'"))
self.assertEqual(api._user_detail(d), "Something went wrong on our side while transcribing. Please try again.")
self.assertIn("staff: AttributeError: 'NoneType' object has no attribute 'tokenizer'", d)
def test_categories(self):
self.assertIn("couldn't read this audio file", api._user_detail(api._failure_detail(RuntimeError("ffmpeg: Invalid data found"))))
self.assertIn("too busy", api._user_detail(api._failure_detail(RuntimeError("CUDA out of memory"))))
self.assertIn("too long", api._user_detail(api._failure_detail(TimeoutError("timed out"))))
def test_plain_details_pass_through(self):
# Messages written for users (no staff part) are returned as they are.
self.assertEqual(api._user_detail("The server restarted. Please try again."), "The server restarted. Please try again.")
self.assertEqual(api._user_detail(None), "")
def test_bad_audio_is_not_retried(self):
self.assertFalse(api._worth_retrying(RuntimeError("Invalid data found when processing input")))
self.assertTrue(api._worth_retrying(AttributeError("'NoneType' object has no attribute 'tokenizer'")))
class UseModelLoads(unittest.TestCase):
def test_returned_model_is_loaded(self):
"""A Whisper model handed out by _use_model is loaded, so callers can
read .pipeline.tokenizer straight away (the 19 Oct 'NoneType' failures)."""
from src.transcription import engine as eng
e = eng.TranscriptionEngine.__new__(eng.TranscriptionEngine)
e.current_model_key = "whisper-large-v3"
class Pipe:
pipeline = None
def _initialize_pipeline(self):
if self.pipeline is None:
self.pipeline = SimpleNamespace(tokenizer="tok")
pipe = Pipe()
e._get_pipeline = lambda: pipe
e.set_model = lambda k: setattr(e, "current_model_key", k)
self.assertEqual(e._use_model("whisper-large-v3").pipeline.tokenizer, "tok")
if __name__ == "__main__":
unittest.main()