Coverage for tests/test_calc.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.2.1, created at 2024-07-26 12:59 +0300

1""" 

2 

3This file contains the test cases for the calc module. 

4 

5""" 

6 

7from src.calc import add, sub 

8import pytest 

9 

10 

11def test_add(): 

12 """ 

13 Test add function 

14 :return: None 

15 """ 

16 result = add(1, '1') 

17 assert result == 2 

18 assert 2 == add(1, 1) 

19 

20 

21def test_sub(): 

22 """ 

23 Test sub function 

24 :return: None 

25 """ 

26 result = sub(2, '1') 

27 assert result == 1 

28 assert 1 == sub(2, 1) 

29 

30 

31@pytest.mark.parametrize("expected_result,a,b", [(2, 1, 1), (3, 2, 1)]) 

32def test_add_param(expected_result, a, b): 

33 """ 

34 Test add function with parameters 

35 :param expected_result: 

36 :param a: 

37 :param b: 

38 :return: 

39 """ 

40 result = add(a, b) 

41 assert result == expected_result 

42 

43 

44@pytest.mark.parametrize("expected_result,a,b", [(2, 3, 1), (3, 4, 1)]) 

45def test_sub_param(expected_result, a, b): 

46 """ 

47 Test sub function with parameters 

48 :param expected_result: 

49 :param a: 

50 :param b: 

51 :return: 

52 """ 

53 result = sub(a, b) 

54 assert result == expected_result 

55 

56 

57def test_add_fixture(data_to_add): 

58 expected_result, a, b = data_to_add 

59 result = add(a, b) 

60 assert result == expected_result 

61 

62 

63def test_sub_fixture(data_to_sub): 

64 expected_result, a, b = data_to_sub 

65 result = sub(a, b) 

66 assert result == expected_result