Coverage for tests/test_dependenpy.py: 100.00%

23 statements  

« prev     ^ index     » next       coverage.py v6.4.1, created at 2022-09-04 11:35 +0200

1"""Tests for main features.""" 

2 

3import pytest 

4 

5from dependenpy.cli import main 

6from dependenpy.dsm import DSM 

7 

8 

9@pytest.mark.parametrize( 

10 "args", 

11 [ 

12 ["-l", "dependenpy"], 

13 ["-m", "dependenpy"], 

14 ["-t", "dependenpy"], 

15 ["dependenpy", "-d100"], 

16 ["dependenpy,internal,dependenpy"], 

17 ], 

18) 

19def test_main_ok(args): 

20 """ 

21 Main test method. 

22 

23 Arguments: 

24 args: Command line arguments. 

25 """ 

26 assert main(args) == 0 

27 

28 

29def test_main_not_ok(): 

30 """Main test method.""" 

31 assert main(["do not exist"]) == 1 

32 

33 

34def test_tree(): 

35 """Test the built tree.""" 

36 dsm = DSM("internal") 

37 items = [ 

38 "internal", 

39 "internal.subpackage_a", 

40 "internal.subpackage_a.subpackage_1", 

41 "internal.subpackage_a.subpackage_1.__init__", 

42 "internal.subpackage_a.subpackage_1.module_i", 

43 "internal.subpackage_a.__init__", 

44 "internal.subpackage_a.module_1", 

45 "internal.__init__", 

46 "internal.module_a", 

47 ] 

48 for item in items: 

49 assert dsm.get(item) 

50 

51 

52def test_inner_imports(): 

53 """Test inner imports.""" 

54 dsm = DSM("internal") 

55 module_i = dsm["internal.subpackage_a.subpackage_1.module_i"] 

56 assert len(module_i.dependencies) == 4 

57 assert module_i.cardinal(to=dsm["internal"]) == 3 

58 

59 

60def test_delayed_build(): 

61 """Test delayed build.""" 

62 dsm = DSM("internal", build_tree=False) 

63 dsm.build_tree() 

64 dsm.build_dependencies() 

65 assert len(dsm.submodules) == 6