Skip to content

Commit

Permalink
Merge pull request #2 from UG4/develop
Browse files Browse the repository at this point in the history
tests/integration/test-solvers.py
  • Loading branch information
anaegel authored Jun 13, 2024
2 parents 03a179f + bd98776 commit c98381c
Showing 1 changed file with 63 additions and 26 deletions.
89 changes: 63 additions & 26 deletions tests/integration/test-solvers.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,87 @@
import os
import sys

import unittest
import subprocess

def main():
if len(sys.argv) != 2:
print("Usage: python test_solvers.py <directory>")
sys.exit(1)

directory = sys.argv[1]
#
os.environ['PYVISTA_OFF_SCREEN'] = "True"

def set_test_dir(directory):
# Change to the specified directory
try:
os.chdir(directory)
except FileNotFoundError:
print(f"Error: Directory '{directory}' not found.")
sys.exit(1)
return False
except NotADirectoryError:
print(f"Error: '{directory}' is not a directory.")
sys.exit(1)
return False
except PermissionError:
print(f"Error: Permission denied to access '{directory}'.")
sys.exit(1)
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)
if process.returncode != 0:
print(process.returncode)
return False
else:
print(f"Skipping file: {filename}")
return True

return True

def test_dir(directory):
# Change to the specified directory
set_test_dir(directory)

# List files and perform a job on each
# List all files and perform a job on each
try:
for filename in os.listdir():
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)
if process.returncode != 0:
print(process.returncode)
sys.exit(1)

else:
print(f"Skipping file: {filename}")
# Example job: print the file's name
# You can add more complex processing here
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)

directory = sys.argv[1]
if not testdir(directory):
sys.exit(1)


class TestAll(unittest.TestCase):
def setUp(self):
os.environ['PYVISTA_OFF_SCREEN'] = "True"
set_test_dir("content/tutorial-solver")

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):
self.assertTrue(test_file("example01-smoothers.py"), "Must return true")

def test_multigrid(self):
self.assertTrue(test_file("example03-multigrid.py"), "Must return true")

if __name__ == "__main__":
main()
# main()
unittest.main()

0 comments on commit c98381c

Please sign in to comment.