Skip to content

Commit 5572803

Browse files
committed
Reset OpenMC IDs for each test
Update gold files for local tests
1 parent ad87eef commit 5572803

10 files changed

+48
-21
lines changed

test/gold/cylinder.jou

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ set warning off
44
graphics pause
55
set journal off
66
set default autosize off
7-
#CELL 3
7+
#CELL 1
88
cylinder height 500 radius 6.0
99
#{ id1 = Id("body") }
1010
body { id1 } rotate 90.0 about Y
1111
body { id1 } rotate 45.0 about Z
12-
body { id1 } name "Cell_3"
12+
body { id1 } name "Cell_1"
1313
group "mat:void" add body { id1 }
1414
graphics flush
1515
set default autosize on

test/gold/x_cone.jou

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ set warning off
44
graphics pause
55
set journal off
66
set default autosize off
7-
#CELL 4
7+
#CELL 1
88
create frustum height 500 radius 50.0 top 0
99
#{ id1 = Id("body") }
1010
rotate body { id1 } about y angle 90
1111
body { id1 } move 30.0 3.0 5.0
12-
body { id1 } name "Cell_4"
12+
body { id1 } name "Cell_1"
1313
group "mat:void" add body { id1 }
1414
graphics flush
1515
set default autosize on

test/gold/x_torus.jou

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ set warning off
44
graphics pause
55
set journal off
66
set default autosize off
7-
#CELL 7
7+
#CELL 1
88
torus major radius 5.0 minor radius 2.0
99
#{ id1 = Id("body") }
1010
rotate body { id1 } about y angle 90
1111
body { id1 } move 10.0 10.0 10.0
12-
body { id1 } name "Cell_7"
12+
body { id1 } name "Cell_1"
1313
group "mat:void" add body { id1 }
1414
graphics flush
1515
set default autosize on

test/gold/y_cone.jou

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ set warning off
44
graphics pause
55
set journal off
66
set default autosize off
7-
#CELL 5
7+
#CELL 1
88
create frustum height 500 radius 31.622776601683793 top 0
99
#{ id1 = Id("body") }
1010
rotate body { id1 } about x angle 90
1111
body { id1 } move 40.0 20.0 7.0
12-
body { id1 } name "Cell_5"
12+
body { id1 } name "Cell_1"
1313
group "mat:void" add body { id1 }
1414
graphics flush
1515
set default autosize on

test/gold/y_torus.jou

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ set warning off
44
graphics pause
55
set journal off
66
set default autosize off
7-
#CELL 8
7+
#CELL 1
88
torus major radius 5.0 minor radius 2.0
99
#{ id1 = Id("body") }
1010
rotate body { id1 } about x angle 90
1111
body { id1 } move -10.0 -10.0 -10.0
12-
body { id1 } name "Cell_8"
12+
body { id1 } name "Cell_1"
1313
group "mat:void" add body { id1 }
1414
graphics flush
1515
set default autosize on

test/gold/ycylinder.jou

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ set warning off
44
graphics pause
55
set journal off
66
set default autosize off
7-
#CELL 2
7+
#CELL 1
88
cylinder height 500 radius 1.0
99
#{ id1 = Id("body") }
1010
rotate body { id1 } about x angle 90
1111
body { id1 } move 10.0 0 5.0
12-
body { id1 } name "Cell_2"
12+
body { id1 } name "Cell_1"
1313
group "mat:void" add body { id1 }
1414
graphics flush
1515
set default autosize on

test/gold/z_cone.jou

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ set warning off
44
graphics pause
55
set journal off
66
set default autosize off
7-
#CELL 6
7+
#CELL 1
88
create frustum height 500 radius 22.360679774997898 top 0
99
#{ id1 = Id("body") }
1010
body { id1 } move 50.0 10.0 2.0
11-
body { id1 } name "Cell_6"
11+
body { id1 } name "Cell_1"
1212
group "mat:void" add body { id1 }
1313
graphics flush
1414
set default autosize on

test/gold/z_torus.jou

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ set warning off
44
graphics pause
55
set journal off
66
set default autosize off
7-
#CELL 9
7+
#CELL 1
88
torus major radius 5.0 minor radius 2.0
99
#{ id1 = Id("body") }
1010
body { id1 } move 50.0 50.0 50.0
11-
body { id1 } name "Cell_9"
11+
body { id1 } name "Cell_1"
1212
group "mat:void" add body { id1 }
1313
graphics flush
1414
set default autosize on

test/test_local.py

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
import openmc
1+
from functools import wraps
2+
23
import pytest
34

5+
import openmc
6+
47
from openmc_cad_adapter import to_cubit_journal
58

69
from .test_utilities import diff_gold_file
710
from test import run_in_tmpdir
811

912

13+
def reset_openmc_ids(func):
14+
"""
15+
Decorator to reset the auto-generated IDs in OpenMC before running a test
16+
"""
17+
@wraps(func)
18+
def wrapper(*args, **kwargs):
19+
openmc.reset_auto_ids()
20+
func(*args, **kwargs)
21+
return wrapper
22+
23+
24+
@reset_openmc_ids
1025
def test_planes(request, run_in_tmpdir):
1126
plane1 = openmc.Plane(A=1.0, B=1.0, C=0.0, D=-5.0)
1227
plane2 = openmc.Plane(A=1.0, B=1.0, C=0.0, D=5.0)
@@ -18,80 +33,92 @@ def test_planes(request, run_in_tmpdir):
1833
to_cubit_journal(g, world=(500, 500, 500), filename='plane.jou')
1934
diff_gold_file('plane.jou')
2035

36+
2137
# Test the XCylinder and YCylinder classes, the ZCylinder surface is tested
2238
# extensively in the OpenMC example tests
39+
@reset_openmc_ids
2340
def test_xcylinder(request, run_in_tmpdir):
2441
x_cyl = openmc.XCylinder(r=1.0, y0=10.0, z0=5.0)
2542
g = openmc.Geometry([openmc.Cell(region=-x_cyl)])
2643
to_cubit_journal(g, world=(500, 500, 500), filename='xcylinder.jou')
2744
diff_gold_file('xcylinder.jou')
2845

2946

47+
@reset_openmc_ids
3048
def test_ycylinder(request, run_in_tmpdir):
3149
y_cyl = openmc.YCylinder(r=1.0, x0=10.0, z0=5.0)
3250
g = openmc.Geometry([openmc.Cell(region=-y_cyl)])
3351
to_cubit_journal(g, world=(500, 500, 500), filename='ycylinder.jou')
3452
diff_gold_file('ycylinder.jou')
3553

3654

55+
@reset_openmc_ids
3756
def test_cylinder(request, run_in_tmpdir):
3857
cyl = openmc.Cylinder(x0=0.0, y0=0.0, z0=0.0, r=6.0, dx=0.7071, dy=0.7071, dz=0.0)
3958
g = openmc.Geometry([openmc.Cell(region=-cyl)])
4059
to_cubit_journal(g, world=(500, 500, 500), filename='cylinder.jou')
4160
diff_gold_file('cylinder.jou')
4261

4362

63+
@reset_openmc_ids
4464
def test_x_cone(request, run_in_tmpdir):
4565
x_cone = openmc.XCone(x0=30.0, y0=3.0, z0=5.0, r2=5.0)
4666
g = openmc.Geometry([openmc.Cell(region=-x_cone)])
4767
to_cubit_journal(g, world=(500, 500, 500), filename='x_cone.jou')
4868
diff_gold_file('x_cone.jou')
4969

5070

71+
@reset_openmc_ids
5172
def test_y_cone(request, run_in_tmpdir):
5273
y_cone = openmc.YCone(x0=40.0, y0=20.0, z0=7.0, r2=2.0)
5374
g = openmc.Geometry([openmc.Cell(region=-y_cone)])
5475
to_cubit_journal(g, world=(500, 500, 500), filename='y_cone.jou')
5576
diff_gold_file('y_cone.jou')
5677

5778

79+
@reset_openmc_ids
5880
def test_z_cone(request, run_in_tmpdir):
5981
z_cone = openmc.ZCone(x0=50.0, y0=10.0, z0=2.0, r2=1.0)
6082
g = openmc.Geometry([openmc.Cell(region=-z_cone)])
6183
to_cubit_journal(g, world=(500, 500, 500), filename='z_cone.jou')
6284
diff_gold_file('z_cone.jou')
6385

6486

87+
@reset_openmc_ids
6588
def test_x_torus(request, run_in_tmpdir):
6689
x_torus = openmc.XTorus(x0=10.0, y0=10.0, z0=10.0, a=5.0, b=2.0, c=2.0)
6790
g = openmc.Geometry([openmc.Cell(region=-x_torus)])
6891
to_cubit_journal(g, world=(500, 500, 500), filename='x_torus.jou')
6992
diff_gold_file('x_torus.jou')
7093

7194

95+
@reset_openmc_ids
7296
def test_y_torus(request, run_in_tmpdir):
7397
y_torus = openmc.YTorus(x0=-10.0, y0=-10.0, z0=-10.0, a=5.0, b=2.0, c=2.0)
7498
g = openmc.Geometry([openmc.Cell(region=-y_torus)])
7599
to_cubit_journal(g, world=(500, 500, 500), filename='y_torus.jou')
76100
diff_gold_file('y_torus.jou')
77101

78102

103+
@reset_openmc_ids
79104
def test_z_torus(request, run_in_tmpdir):
80105
z_torus = openmc.ZTorus(x0=50.0, y0=50.0, z0=50.0, a=5.0, b=2.0, c=2.0)
81106
g = openmc.Geometry([openmc.Cell(region=-z_torus)])
82107
to_cubit_journal(g, world=(500, 500, 500), filename='z_torus.jou')
83108
diff_gold_file('z_torus.jou')
84109

85110

111+
@reset_openmc_ids
86112
def test_torus_diff_radii(request, run_in_tmpdir):
87113
with pytest.raises(ValueError):
88114
z_torus = openmc.ZTorus(x0=50.0, y0=50.0, z0=50.0, a=5.0, b=2.0, c=3.0)
89115
g = openmc.Geometry([openmc.Cell(region=-z_torus)])
90116
to_cubit_journal(g, world=(500, 500, 500), filename='a_torus.jou')
91117

92118

119+
@reset_openmc_ids
93120
def test_general_cone(request, run_in_tmpdir):
94121
with pytest.raises(NotImplementedError):
95122
cone = openmc.Cone(x0=0.0, y0=0.0, z0=0.0, r2=6.0, dx=1, dy=1, dz=1)
96123
g = openmc.Geometry([openmc.Cell(region=-cone)])
97-
to_cubit_journal(g, world=(500, 500, 500), filename='cone.jou')
124+
to_cubit_journal(g, world=(500, 500, 500), filename='cone.jou')

test/test_utilities.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def diff_files(test_output, gold_file):
1212
shutil.copy(test_output, gold_file)
1313

1414
if not filecmp.cmp(test_output, gold_file):
15-
print(''.join(difflib.unified_diff(open(test_output, 'r').readlines(),
16-
open(gold_file, 'r').readlines())))
17-
raise RuntimeError(f'{test_output} and {gold_file} are different')
15+
print(''.join(difflib.unified_diff(open(gold_file, 'r').readlines(),
16+
open(test_output, 'r').readlines())))
17+
raise RuntimeError(f'{gold_file} and {test_output} are different')
1818

1919

2020
def diff_gold_file(gold_file, request=None):

0 commit comments

Comments
 (0)