-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathtest_statepoint_open_prompt.py
More file actions
140 lines (110 loc) · 4.14 KB
/
test_statepoint_open_prompt.py
File metadata and controls
140 lines (110 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from types import SimpleNamespace
from openmc_plotter import main_window
class FakeButton:
def __init__(self):
self.text = None
def setText(self, text):
self.text = text
class FakeMessageBox:
Yes = 1
Cancel = 2
Ok = 4
Information = 8
Warning = 16
next_result = Cancel
instances = []
def __init__(self, *args, **kwargs):
self.text = None
self.icon = None
self.standard_buttons = None
self.default_button = None
self.buttons = {}
type(self).instances.append(self)
def setText(self, text):
self.text = text
def setIcon(self, icon):
self.icon = icon
def setStandardButtons(self, buttons):
self.standard_buttons = buttons
def setDefaultButton(self, button):
self.default_button = button
def button(self, button):
return self.buttons.setdefault(button, FakeButton())
def exec(self):
return type(self).next_result
def make_window(events):
status_bar = SimpleNamespace(
showMessage=lambda message, timeout=None: events.append(
("status", message, timeout)
)
)
statepoint = SimpleNamespace(
filename="current.h5",
close=lambda: events.append("close-current-statepoint"),
)
model = SimpleNamespace(
statepoint=statepoint,
currentView=SimpleNamespace(selectedTally=17),
activeView=SimpleNamespace(selectedTally=17),
)
def open_statepoint(filename):
events.append(("open-statepoint", filename))
model.statepoint = SimpleNamespace(
filename=filename,
close=lambda: events.append(("close-statepoint", filename)),
)
model.openStatePoint = open_statepoint
window = SimpleNamespace(
model=model,
statusBar=lambda: status_bar,
updateDataMenu=lambda: events.append("update-data-menu"),
tallyPanel=SimpleNamespace(
selectTally=lambda: events.append("select-tally"),
update=lambda: events.append("update-tally-panel"),
),
plotIm=SimpleNamespace(updatePixmap=lambda: events.append("update-pixmap")),
)
window.closeStatePoint = lambda: main_window.MainWindow.closeStatePoint(window)
return window
def test_open_statepoint_cancel_keeps_current_file(monkeypatch):
events = []
FakeMessageBox.instances = []
FakeMessageBox.next_result = FakeMessageBox.Cancel
window = make_window(events)
def fake_get_open_file_name(*args, **kwargs):
events.append("show-open-dialog")
return ("replacement.h5", "*.h5")
monkeypatch.setattr(main_window, "QMessageBox", FakeMessageBox)
monkeypatch.setattr(
main_window.QFileDialog, "getOpenFileName", fake_get_open_file_name
)
main_window.MainWindow.openStatePoint(window)
assert events == []
assert window.model.statepoint.filename == "current.h5"
assert len(FakeMessageBox.instances) == 1
assert FakeMessageBox.instances[0].text == (
"A statepoint file is currently open. Continue to close it and open "
"a new one?"
)
assert FakeMessageBox.instances[0].button(FakeMessageBox.Yes).text == "Continue"
def test_open_statepoint_continue_closes_current_file_before_reopening(
monkeypatch,
):
events = []
FakeMessageBox.instances = []
FakeMessageBox.next_result = FakeMessageBox.Yes
window = make_window(events)
def fake_get_open_file_name(*args, **kwargs):
events.append("show-open-dialog")
return ("replacement.h5", "*.h5")
monkeypatch.setattr(main_window, "QMessageBox", FakeMessageBox)
monkeypatch.setattr(
main_window.QFileDialog, "getOpenFileName", fake_get_open_file_name
)
main_window.MainWindow.openStatePoint(window)
assert events.index("close-current-statepoint") < events.index("show-open-dialog")
assert ("open-statepoint", "replacement.h5") in events
assert ("status", "Opened statepoint file: replacement.h5", 5000) in events
assert window.model.currentView.selectedTally is None
assert window.model.activeView.selectedTally is None
assert window.model.statepoint.filename == "replacement.h5"