diff --git a/.github/workflows/push_event_workflow.yml b/.github/workflows/unit_test.yml similarity index 62% rename from .github/workflows/push_event_workflow.yml rename to .github/workflows/unit_test.yml index 66702d5..0578e2e 100644 --- a/.github/workflows/push_event_workflow.yml +++ b/.github/workflows/unit_test.yml @@ -20,12 +20,24 @@ jobs: - name : Install Packages run : pip install ug4py-base matplotlib ipython pyvista nbformat trame ipywidgets unittest-xml-reporting - - name : Run tests + - name : Run tests + continue-on-error: true run : | - python -m unittest tests/integration/test-solvers.py + python tests/integration/test-solvers.py || true + python tests/integration/test-brom.py || true ls cd $HOME ls + - name : Upload test artifacts + uses: actions/upload-artifact@v4 + with: + # Name of the artifact to upload. + # Optional. Default is 'artifact' + name: unittest-artifacts + path: test-reports + - uses: test-summary/action@v2 + with: + paths: "test-reports/TEST-*.xml" #- name: Push to main # if: success() diff --git a/tests/integration/test-brom.py b/tests/integration/test-brom.py new file mode 100644 index 0000000..ca099fa --- /dev/null +++ b/tests/integration/test-brom.py @@ -0,0 +1,26 @@ + +from utils import set_test_dir, test_file, test_dir + +import os +import unittest +import xmlrunner + + +class Bromide3D(unittest.TestCase): + def setUp(self): + os.environ['PYVISTA_OFF_SCREEN'] = "True" + + def tearDown(self): + set_test_dir("../..") + + def test_bromide(self): + set_test_dir("content/brom") + self.assertEqual(test_file("BromDiffusion.py"), 0, "Must return true") + +if __name__ == "__main__": + # unittest.main() + unittest.main( + testRunner=xmlrunner.XMLTestRunner(output='test-reports'), + # these make sure that some options that are not applicable + # remain hidden from the help menu. + failfast=False, buffer=False, catchbreak=False) diff --git a/tests/integration/test-solvers.py b/tests/integration/test-solvers.py index 9a57cad..dc39a9e 100644 --- a/tests/integration/test-solvers.py +++ b/tests/integration/test-solvers.py @@ -1,77 +1,20 @@ -import os -import sys - -import unittest -import subprocess - - -def set_test_dir(directory): - # Change to the specified directory - try: - os.chdir(directory) - except FileNotFoundError: - print(f"Error: Directory '{directory}' not found.") - return False - except NotADirectoryError: - print(f"Error: '{directory}' is not a directory.") - return False - except PermissionError: - print(f"Error: Permission denied to access '{directory}'.") - return False - return True - - -def test_file(filename): - print(f"test_File: {filename}") - if os.path.isfile(filename): # Check if it's a file - # Replace the next line with the job you want to perform - - if (filename.endswith(".py")): - print(f"Processing file: {filename}") - process = subprocess.run("ipython "+ filename, shell=True, capture_output=True, text=True) - print("OUT: " +process.stdout) - print("ERR: " + process.stderr) - return process.returncode - else: - print(f"Skipping file: {filename}") - return 0 -def test_dir(directory): - # Change to the specified directory - set_test_dir(directory) - # List all files and perform a job on each - try: - for filename in os.listdir(): - if not test_file(filename): - return False - except Exception as e: - print(f"Error while processing files: {e}") - return False - - return True - -# This is the 'old' main. -def main(): - if len(sys.argv) != 2: - print("Usage: python test_solvers.py ") - sys.exit(1) +from utils import set_test_dir, test_file, test_dir - directory = sys.argv[1] - if not testdir(directory): - sys.exit(1) +import os +import unittest +import xmlrunner class TestAll(unittest.TestCase): def setUp(self): os.environ['PYVISTA_OFF_SCREEN'] = "True" + def tearDown(self): set_test_dir("../..") - #def test_solvers(self): - # self.assertEqual(test_dir("content/tutorial-solver"), True, "Must return true") - def test_smoothers(self): set_test_dir("content/tutorial-solver") self.assertEqual(test_file("example01-smoothers.py"), 0, "Must return true") @@ -80,11 +23,11 @@ def test_multigrid(self): set_test_dir("content/tutorial-solver") self.assertEqual(test_file("example03-multigrid.py"), 0, "Must return true") - def test_bromide(self): - set_test_dir("content/brom") - self.assertEqual(test_file("BromDiffusion.py"), 0, "Must return true") if __name__ == "__main__": - # main() - unittest.main() - + # unittest.main() + unittest.main( + testRunner=xmlrunner.XMLTestRunner(output='test-reports'), + # these make sure that some options that are not applicable + # remain hidden from the help menu. + failfast=False, buffer=False, catchbreak=False) diff --git a/tests/integration/utils.py b/tests/integration/utils.py new file mode 100644 index 0000000..c08538e --- /dev/null +++ b/tests/integration/utils.py @@ -0,0 +1,48 @@ +import os +import subprocess + +def set_test_dir(directory): + # Change to the specified directory + try: + os.chdir(directory) + except FileNotFoundError: + print(f"Error: Directory '{directory}' not found.") + return False + except NotADirectoryError: + print(f"Error: '{directory}' is not a directory.") + return False + except PermissionError: + print(f"Error: Permission denied to access '{directory}'.") + return False + return True + + +def test_file(filename): + print(f"test_File: {filename}") + if os.path.isfile(filename): # Check if it's a file + # Replace the next line with the job you want to perform + + if (filename.endswith(".py")): + print(f"Processing file: {filename}") + process = subprocess.run("ipython "+ filename, shell=True, capture_output=True, text=True) + print("OUT: " +process.stdout) + print("ERR: " + process.stderr) + return process.returncode + else: + print(f"Skipping file: {filename}") + return 0 + +def test_dir(directory): + # Change to the specified directory + set_test_dir(directory) + + # List all files and perform a job on each + try: + for filename in os.listdir(): + if not test_file(filename): + return False + except Exception as e: + print(f"Error while processing files: {e}") + return False + + return True \ No newline at end of file