Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/test-brom.py
Original file line number Diff line number Diff line change
@@ -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)
79 changes: 11 additions & 68 deletions tests/integration/test-solvers.py
Original file line number Diff line number Diff line change
@@ -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 <directory>")
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")
Expand All @@ -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)
48 changes: 48 additions & 0 deletions tests/integration/utils.py
Original file line number Diff line number Diff line change
@@ -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