Skip to content

Commit 9be744a

Browse files
committed
Adding test for batch image function
1 parent bbe0c4f commit 9be744a

4 files changed

Lines changed: 37 additions & 6 deletions

File tree

openmc_plotter/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def run_app(user_args):
7575

7676
if user_args.batch_mode:
7777
for view_file in user_args.batch_mode:
78-
print(view_file)
7978
mainWindow.saveBatchImage(view_file)
8079
mainWindow.close()
8180
sys.exit()

openmc_plotter/main_window.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _openmcReload(threads=None, model_path='.'):
3636
args = ["-c"]
3737
if threads is not None:
3838
args += ["-s", str(threads)]
39-
args.append(model_path)
39+
args.append(str(model_path))
4040
openmc.lib.init(args)
4141
openmc.lib.settings.verbosity = 1
4242

@@ -450,6 +450,14 @@ def updateWindowMenu(self):
450450
self.mainWindowAction.setChecked(self.isActiveWindow())
451451

452452
def saveBatchImage(self, view_file):
453+
"""
454+
Loads a view in the GUI and generates an image
455+
456+
Parameters
457+
----------
458+
view_file : str or pathlib.Path
459+
The path to a view file that is compatible with the loaded model.
460+
"""
453461
# store the
454462
cv = self.model.currentView
455463
# load the view from file

tests/setup_test/test.pltvw

1.86 KB
Binary file not shown.

tests/setup_test/test.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import filecmp
2+
import shutil
3+
24
import pytest
5+
36
from openmc_plotter.main_window import MainWindow, _openmcReload
47

58
@pytest.fixture
@@ -12,12 +15,33 @@ def run_in_tmpdir(tmpdir):
1215

1316
def test_window(tmpdir, qtbot):
1417
orig = tmpdir.chdir()
18+
mw = MainWindow(model_path=orig)
19+
_openmcReload(model_path=orig)
20+
mw.loadGui()
21+
22+
try:
23+
mw.saveImage(tmpdir / 'test.png')
24+
mw.close()
25+
qtbot.addWidget(mw)
26+
finally:
27+
orig.chdir()
1528

16-
_openmcReload(model_path=str(orig))
29+
filecmp.cmp(orig / 'ref.png', tmpdir / 'test.png')
30+
31+
def test_batch_image(tmpdir, qtbot):
32+
orig = tmpdir.chdir()
33+
34+
# move view file into tmpdir
35+
shutil.copy2(orig / 'test.pltvw', tmpdir)
36+
37+
_openmcReload(model_path=orig)
1738

1839
mw = MainWindow(model_path=orig)
1940
mw.loadGui()
20-
mw.saveImage(tmpdir / 'test.png')
21-
qtbot.addWidget(mw)
41+
try:
42+
mw.saveBatchImage('test.pltvw')
43+
qtbot.addWidget(mw)
44+
finally:
45+
orig.chdir()
2246

23-
filecmp.cmp(orig / 'ref.png', tmpdir / 'test.png')
47+
filecmp.cmp(orig / 'ref.png', tmpdir / 'test.png')

0 commit comments

Comments
 (0)