Spaces:
Sleeping
Sleeping
Claude Opus 5.5 (1M context)
Fix 'NoneType has no attribute tokenizer' and harden job failures
c98b787 Download tests/test_job_errors.py from ConsulawTechnologies/asr_system: direct link, hf CLI and curl.
- Browser
- Download file 2.48 kB
-
https://huggingface.co/spaces/ConsulawTechnologies/asr_system/resolve/main/tests/test_job_errors.py
- Command line
-
hf download hf://spaces/ConsulawTechnologies/asr_system/tests/test_job_errors.py
-
curl -L -o test_job_errors.py https://huggingface.co/spaces/ConsulawTechnologies/asr_system/resolve/main/tests/test_job_errors.py
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 | |
| 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() | |