Skip to content

Commit

Permalink
Ability to run regression tests using pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
paulromano committed Feb 5, 2018
1 parent 72aebfc commit 98d5496
Show file tree
Hide file tree
Showing 84 changed files with 351 additions and 639 deletions.
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
python_files = test*.py
python_classes = NoThanks
filterwarnings = ignore::UserWarning
11 changes: 5 additions & 6 deletions tests/regression_tests/asymmetric_lattice/test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env python

import os
import sys
import glob
import hashlib
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import PyAPITestHarness

import openmc

from tests.testing_harness import PyAPITestHarness


class AsymmetricLatticeTestHarness(PyAPITestHarness):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -90,6 +88,7 @@ def _get_results(self, hash_output=True):
return outstr


if __name__ == '__main__':
def test_asymmetric_lattice(request):
harness = AsymmetricLatticeTestHarness('statepoint.10.h5')
harness.request = request
harness.main()
10 changes: 3 additions & 7 deletions tests/regression_tests/cmfd_feed/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python
from tests.testing_harness import CMFDTestHarness

import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import CMFDTestHarness


if __name__ == '__main__':
def test_cmfd_feed(request):
harness = CMFDTestHarness('statepoint.20.h5')
harness.request = request
harness.main()
10 changes: 3 additions & 7 deletions tests/regression_tests/cmfd_nofeed/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python
from tests.testing_harness import CMFDTestHarness

import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import CMFDTestHarness


if __name__ == '__main__':
def test_cmfd_nofeed(request):
harness = CMFDTestHarness('statepoint.20.h5')
harness.request = request
harness.main()
10 changes: 3 additions & 7 deletions tests/regression_tests/complex_cell/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python
from tests.testing_harness import TestHarness

import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import TestHarness


if __name__ == '__main__':
def test_complex_cell(request):
harness = TestHarness('statepoint.10.h5')
harness.request = request
harness.main()
10 changes: 3 additions & 7 deletions tests/regression_tests/confidence_intervals/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python
from tests.testing_harness import TestHarness

import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import TestHarness


if __name__ == '__main__':
def test_confidence_intervals(request):
harness = TestHarness('statepoint.10.h5')
harness.request = request
harness.main()
11 changes: 4 additions & 7 deletions tests/regression_tests/create_fission_neutrons/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python

import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import PyAPITestHarness
import openmc

from tests.testing_harness import PyAPITestHarness


class CreateFissionNeutronsTestHarness(PyAPITestHarness):
def _build_inputs(self):
Expand Down Expand Up @@ -69,6 +65,7 @@ def _get_results(self):
return outstr


if __name__ == '__main__':
def test_create_fission_neutrons(request):
harness = CreateFissionNeutronsTestHarness('statepoint.10.h5')
harness.request = request
harness.main()
10 changes: 3 additions & 7 deletions tests/regression_tests/density/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python
from tests.testing_harness import TestHarness

import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import TestHarness


if __name__ == '__main__':
def test_density(request):
harness = TestHarness('statepoint.10.h5')
harness.request = request
harness.main()
12 changes: 5 additions & 7 deletions tests/regression_tests/diff_tally/test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/usr/bin/env python

import glob
import os
import sys

import pandas as pd

sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import PyAPITestHarness
import openmc

from tests.testing_harness import PyAPITestHarness


class DiffTallyTestHarness(PyAPITestHarness):
def __init__(self, *args, **kwargs):
super(DiffTallyTestHarness, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -125,6 +122,7 @@ def _get_results(self):
return df.to_csv(None, columns=cols, index=False, float_format='%.7e')


if __name__ == '__main__':
def test_diff_tally(request):
harness = DiffTallyTestHarness('statepoint.3.h5')
harness.request = request
harness.main()
11 changes: 4 additions & 7 deletions tests/regression_tests/distribmat/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python

import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import TestHarness, PyAPITestHarness
import openmc

from tests.testing_harness import TestHarness, PyAPITestHarness


class DistribmatTestHarness(PyAPITestHarness):
def _build_inputs(self):
Expand Down Expand Up @@ -103,6 +99,7 @@ def _get_results(self):
return outstr


if __name__ == '__main__':
def test_distribmat(request):
harness = DistribmatTestHarness('statepoint.5.h5')
harness.request = request
harness.main()
10 changes: 3 additions & 7 deletions tests/regression_tests/eigenvalue_genperbatch/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python
from tests.testing_harness import TestHarness

import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import TestHarness


if __name__ == '__main__':
def test_eigenvalue_genperbatch(request):
harness = TestHarness('statepoint.7.h5')
harness.request = request
harness.main()
10 changes: 3 additions & 7 deletions tests/regression_tests/eigenvalue_no_inactive/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python
from tests.testing_harness import TestHarness

import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import TestHarness


if __name__ == '__main__':
def test_eigenvalue_no_inactive(request):
harness = TestHarness('statepoint.10.h5')
harness.request = request
harness.main()
11 changes: 4 additions & 7 deletions tests/regression_tests/energy_cutoff/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python

import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import PyAPITestHarness
import openmc

from tests.testing_harness import PyAPITestHarness


class EnergyCutoffTestHarness(PyAPITestHarness):
def _build_inputs(self):
Expand Down Expand Up @@ -73,6 +69,7 @@ def _get_results(self):
return outstr


if __name__ == '__main__':
def test_energy_cutoff(request):
harness = EnergyCutoffTestHarness('statepoint.10.h5')
harness.request = request
harness.main()
10 changes: 3 additions & 7 deletions tests/regression_tests/energy_grid/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python
from tests.testing_harness import TestHarness

import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import TestHarness


if __name__ == '__main__':
def test_energy_grid(request):
harness = TestHarness('statepoint.10.h5')
harness.request = request
harness.main()
11 changes: 3 additions & 8 deletions tests/regression_tests/energy_laws/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python

"""The purpose of this test is to provide coverage of energy distributions that
are not covered in other tests. It has a single material with the following
nuclides:
Expand All @@ -18,13 +16,10 @@
"""

import glob
import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import TestHarness
from tests.testing_harness import TestHarness


if __name__ == '__main__':
def test_energy_laws(request):
harness = TestHarness('statepoint.10.h5')
harness.request = request
harness.main()
5 changes: 1 addition & 4 deletions tests/regression_tests/enrichment/test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#!/usr/bin/env python

import os
import sys

import numpy as np

sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from openmc import Material
from openmc.data import NATURAL_ABUNDANCE, atomic_mass


if __name__ == '__main__':
def test_enrichment():
# This test doesn't require an OpenMC run. We just need to make sure the
# element.expand() method expands Uranium to the proper enrichment.

Expand Down
11 changes: 5 additions & 6 deletions tests/regression_tests/entropy/test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env python

import glob
import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import TestHarness

from openmc import StatePoint

from tests.testing_harness import TestHarness


class EntropyTestHarness(TestHarness):
def _get_results(self):
Expand All @@ -26,6 +24,7 @@ def _get_results(self):
return outstr


if __name__ == '__main__':
def test_entropy(request):
harness = EntropyTestHarness('statepoint.10.h5')
harness.request = request
harness.main()
11 changes: 4 additions & 7 deletions tests/regression_tests/filter_distribcell/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python

import glob
import hashlib
import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import *

from tests.testing_harness import *


class DistribcellTestHarness(TestHarness):
Expand Down Expand Up @@ -72,6 +68,7 @@ def _test_output_created(self, tallies_out_present):
'Tally output file does not exist.'


if __name__ == '__main__':
def test_filter_distribcell(request):
harness = DistribcellTestHarness()
harness.request = request
harness.main()
15 changes: 5 additions & 10 deletions tests/regression_tests/filter_energyfun/test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#!/usr/bin/env python

import os
import sys
import glob
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import PyAPITestHarness
import openmc

from tests.testing_harness import PyAPITestHarness


class FilterEnergyFunHarness(PyAPITestHarness):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -38,8 +33,7 @@ def __init__(self, *args, **kwargs):

def _get_results(self):
# Read the statepoint file.
statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0]
sp = openmc.StatePoint(statepoint)
sp = openmc.StatePoint(self._sp_name)

# Use tally arithmetic to compute the branching ratio.
br_tally = sp.tallies[2] / sp.tallies[1]
Expand All @@ -48,6 +42,7 @@ def _get_results(self):
return br_tally.get_pandas_dataframe().to_string() + '\n'


if __name__ == '__main__':
def test_filter_energyfun(request):
harness = FilterEnergyFunHarness('statepoint.10.h5')
harness.request = request
harness.main()
11 changes: 4 additions & 7 deletions tests/regression_tests/filter_mesh/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python

import os
import sys
sys.path.insert(0, os.path.join(os.pardir, os.pardir))
from testing_harness import HashedPyAPITestHarness
import openmc

from tests.testing_harness import HashedPyAPITestHarness


class FilterMeshTestHarness(HashedPyAPITestHarness):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -67,6 +63,7 @@ def __init__(self, *args, **kwargs):
self._model.tallies.append(tally)


if __name__ == '__main__':
def test_filter_mesh(request):
harness = FilterMeshTestHarness('statepoint.10.h5')
harness.request = request
harness.main()
Loading

0 comments on commit 98d5496

Please sign in to comment.