Coverage for tests/test_wrapper_slidetranscript.py: 100%

37 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-09 04:47 +0000

1#!/usr/bin/env python3 

2 

3import sys 

4import pytest 

5from unittest.mock import patch 

6from unittest.mock import MagicMock 

7from tests.torch_mock import TorchMock 

8from tests.openaiclient_mock import OpenAIClientMock 

9 

10mock_torch = TorchMock() 

11mock_openai = OpenAIClientMock() 

12 

13sys.path.append("wrapper") 

14sys.path.append("wrapper/slidetranscript") 

15 

16 

17with patch.dict(sys.modules, { 

18 'fitz': MagicMock(), 

19 'azure': MagicMock(), 

20 'azure.identity': MagicMock(), 

21 'nvidia_smi': MagicMock(), 

22 'tenacity': MagicMock(), 

23 'torch': mock_torch, 

24 'openai': mock_openai, 

25}): 

26 from slidetranscript.wrapper_slidetranscript import SlideTranscriptGenerator 

27 

28 

29@pytest.mark.asyncio 

30async def test_slide_transcript() -> None: 

31 model = SlideTranscriptGenerator() 

32 assert model is not None 

33 assert model.model_name == "slidetranscript" 

34 

35 model.init() 

36 health = model.get_health() 

37 assert health is not None 

38 assert health is not None 

39 timestamps = model.get_timestamps() 

40 assert timestamps is not None 

41 

42 # with pytest.raises(ValueError): 

43 args = await model.get_rest_args({}) 

44 assert args is not None 

45 args = await model.get_rest_args({ 

46 "pptx_base64": "http://example.com/doc.pdf" 

47 }) 

48 assert args is not None 

49 assert args["task"] == "slidetranscript" 

50 

51 await model.warmup() 

52 

53 with pytest.raises(ValueError): 

54 await model.generate() 

55 

56 pptx_texts = [ 

57 "--- SLIDE 1 ---\nIntroduction to AI", 

58 "--- SLIDE 2 ---\nMachine Learning Basics", 

59 "--- SLIDE 3 ---\nDeep Learning Overview", 

60 ] 

61 pptx_images = [ 

62 "AAAA", 

63 "AAAA", 

64 "AAAA", 

65 ] 

66 

67 await model.generate( 

68 pptx_texts=pptx_texts, 

69 pptx_images=pptx_images) 

70 with pytest.raises(ValueError, match="must have the same length"): 

71 await model.generate( 

72 pptx_texts=pptx_texts, 

73 pptx_images=pptx_images[0:1]) 

74 """ 

75 with pytest.raises(Exception, match="Failed to download PDF"): 

76 await model.generate(pdf_url="http://example.com/doc.pdf") 

77 with pytest.raises(Exception, match="Cannot query LLM for script"): 

78 await model.generate(pdf_url="https://arxiv.org/pdf/2501.16634") 

79 """