File tree 1 file changed +41
-0
lines changed
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+ import re
3
+ import importlib
4
+ import pytest
5
+
6
+ import thealgorithms
7
+
8
+
9
+ def _split_path_rec (path ):
10
+ rest , tail = os .path .split (path )
11
+ if rest == "" :
12
+ return [tail ]
13
+ return _split_path_rec (rest ) + [tail ]
14
+
15
+
16
+ def _gather_modules ():
17
+ """Gather all modules that should be imported, but exclude __init__
18
+ modules.
19
+ """
20
+ testdir = os .path .dirname (__file__ )
21
+ root = os .path .dirname (testdir )
22
+ algos_root = os .path .dirname (thealgorithms .__file__ )
23
+ modules = []
24
+
25
+ for dirpath , dirnames , filenames in os .walk (algos_root ):
26
+ for filename in filenames :
27
+ if not filename .endswith (".py" ) or filename .endswith ("__init__.py" ):
28
+ continue
29
+ reldirpath = os .path .relpath (dirpath , root )
30
+ path_nodes = _split_path_rec (os .path .join (reldirpath , filename ))
31
+ module = "." .join (path_nodes )[:- 3 ]
32
+ modules .append (module )
33
+ return modules
34
+
35
+
36
+ @pytest .mark .parametrize ("module" , _gather_modules ())
37
+ @pytest .mark .timeout (1 )
38
+ def test_import_module (module ):
39
+ """Test that all modules from project root can be imported"""
40
+ mod = importlib .import_module (module )
41
+ assert mod
You can’t perform that action at this time.
0 commit comments