MCPcopy Create free account
hub / github.com/SINGROUP/dscribe / test_examples

Function test_examples

tests/test_examples.py:7–42  ·  view source on GitHub ↗

Walks through the examples folder and tests each example by dynamically importing them which will also run their code.

()

Source from the content-addressed store, hash-verified

5
6
7def test_examples():
8 """Walks through the examples folder and tests each example by
9 dynamically importing them which will also run their code.
10 """
11 # The training and analysis examples are not included since they require
12 # installing quite large libraries and can take a significant amount of
13 # time.
14 exclude = {
15 "./forces_and_energies/training_pytorch.py",
16 "./forces_and_energies/training_tensorflow.py",
17 "./forces_and_energies/analysis.py",
18 "./clustering/training.py",
19 }
20 old_cwd = os.getcwd()
21 os.chdir(Path(__file__).parent.parent / "examples")
22 example_root = os.getcwd()
23 paths = set()
24 for root, dirs, files in list(os.walk("./")):
25 files.sort()
26 for f in files:
27 filename = os.path.join(root, f)
28 if filename.endswith(".py") and filename not in exclude:
29 parts = filename[2:-3]
30 parts = parts.rsplit("/", 1)
31 if len(parts) != 1:
32 folder = parts[0]
33 cwd = "{}/{}".format(example_root, folder)
34 else:
35 cwd = example_root
36 os.chdir(cwd)
37 modulename = parts[-1]
38 if cwd not in paths:
39 sys.path.insert(0, cwd)
40 paths.add(cwd)
41 import_module(modulename)
42 os.chdir(old_cwd)

Callers

nothing calls this directly

Calls 1

sortMethod · 0.45

Tested by

no test coverage detected