Coverage for skema/program_analysis/comment_extractor/tests/test_comment_extractor.py: 100%

36 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-30 17:15 +0000

1from pathlib import Path 

2 

3from fastapi.testclient import TestClient 

4 

5import skema.program_analysis.comment_extractor.comment_extractor as comment_service 

6from skema.program_analysis.comment_extractor.server import app 

7 

8EXAMPLES_PATH = Path(__file__).parent / "examples" 

9 

10client = TestClient(app) 

11 

12def test_extract_c(): 

13 c_source_path = EXAMPLES_PATH / "comments.c" 

14 request = { 

15 "language": "c", 

16 "source": c_source_path.read_text() 

17 } 

18 response = client.post("/comment_service/comments-extract", json=request) 

19 assert response.status_code == 200 

20 

21 

22def test_extract_cpp(): 

23 cpp_source_path = EXAMPLES_PATH / "comments.cpp" 

24 request = { 

25 "language": "cpp", 

26 "source": cpp_source_path.read_text() 

27 } 

28 response = client.post("/comment_service/comments-extract", json=request) 

29 assert response.status_code == 200 

30 

31def test_extract_fortran(): 

32 fortran_source_path = EXAMPLES_PATH / "comments.f95" 

33 request = { 

34 "language": "fortran", 

35 "source": fortran_source_path.read_text() 

36 } 

37 response = client.post("/comment_service/comments-extract", json=request) 

38 assert response.status_code == 200 

39 

40def test_extract_matlab(): 

41 matlab_source_path = EXAMPLES_PATH / "comments.m" 

42 request = { 

43 "language": "matlab", 

44 "source": matlab_source_path.read_text() 

45 } 

46 response = client.post("/comment_service/comments-extract", json=request) 

47 assert response.status_code == 200 

48 

49def test_extract_python(): 

50 python_source_path = EXAMPLES_PATH / "comments.py" 

51 request = { 

52 "language": "python", 

53 "source": python_source_path.read_text() 

54 } 

55 response = client.post("/comment_service/comments-extract", json=request) 

56 assert response.status_code == 200 

57 

58def test_extract_r(): 

59 r_source_path = EXAMPLES_PATH / "comments.r" 

60 request = { 

61 "language": "r", 

62 "source": r_source_path.read_text() 

63 } 

64 response = client.post("/comment_service/comments-extract", json=request) 

65 assert response.status_code == 200