Skip to content

Commit

Permalink
add test compile for example scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMarre committed Aug 3, 2024
1 parent cfe0bf5 commit 0dbfb39
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/python/picongpu/compiling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .species import * # pyflakes.ignore
from .distribution import * # pyflakes.ignore
from .simulation import * # pyflakes.ignore
from .compileexamples import * # pyflakes.ignore
53 changes: 53 additions & 0 deletions test/python/picongpu/compiling/compileexamples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
This file is part of PIConGPU.
Copyright 2021-2023 PIConGPU contributors
Authors: Brian Edward Marre
License: GPLv3+
"""

from picongpu import pypicongpu

import shutil
import importlib.util
import sys

import unittest


class TestExamples(unittest.TestCase):
def __load_example_script(self, path):
"""load and execute example PICMI script from given path"""
spec = importlib.util.spec_from_file_location("example", path)
example_script = importlib.util.module_from_spec(spec)

sys.modules["example"] = example_script
spec.loader.exec_module(example_script)

sim = example.sim # noqa
output_path = example.OUTPUT_DIRECTORY_PATH # noqa

return sim, output_path

def __build_simulation(sim):
"""build the given instance of simulation"""
runner = pypicongpu.Runner(sim)
runner.generate(printDirToConsole=True)
runner.build()

def test_LWFA_example(self):
sim, output_path = self.__load_example_script(
"$PICSRC/share/picongpu/pypicongpu/examples/laser_wakefield/main.py"
)

self.__try_to_build(sim)

# remove generated output
shutil.rmtree(output_path)

def test_warm_plasma_example(self):
sim, output_path = self.__load_example_script("$PICSRC/share/picongpu/pypicongpu/examples/warm_plasma/main.py")

self.__try_to_build(sim)

# remove generated output
shutil.rmtree(output_path)

0 comments on commit 0dbfb39

Please sign in to comment.