Skip to content

Commit 47c7453

Browse files
Update getheightwidth MagicMocks to return height and width with side_effect argument
1 parent 4a43313 commit 47c7453

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

Lib/test/test_pyrepl/support.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def prepare_console(events: Iterable[Event], **kwargs) -> MagicMock | Console:
8888
console.get_event.side_effect = events
8989
console.height = 100
9090
console.width = 80
91+
console.getheightwidth = MagicMock(side_effect=lambda: (console.height, console.width))
92+
9193
for key, val in kwargs.items():
9294
setattr(console, key, val)
9395
return console

Lib/test/test_pyrepl/test_reader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def _prepare_console(events):
228228
console.get_event.side_effect = events
229229
console.height = 100
230230
console.width = 80
231+
console.getheightwidth = MagicMock(side_effect=lambda: (console.height, console.width))
231232
console.input_hook = input_hook
232233
return console
233234

Lib/test/test_pyrepl/test_windows_console.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ def test_resize_wider(self):
129129
events = code_to_events(code)
130130
reader, console = self.handle_events_narrow(events)
131131

132-
console.height = 20
133-
console.width = 80
134-
console.getheightwidth = MagicMock(lambda _: (20, 80))
132+
console.getheightwidth = MagicMock(side_effect=lambda: (20, 80))
135133

136134
def same_reader(_):
137135
return reader
@@ -157,9 +155,7 @@ def test_resize_narrower(self):
157155
events = code_to_events(code)
158156
reader, console = self.handle_events(events)
159157

160-
console.height = 20
161-
console.width = 4
162-
console.getheightwidth = MagicMock(lambda _: (20, 4))
158+
console.getheightwidth = MagicMock(side_effect=lambda: (20, 4))
163159

164160
def same_reader(_):
165161
return reader
@@ -292,8 +288,7 @@ def test_resize_bigger_on_multiline_function(self):
292288
events = itertools.chain(code_to_events(code))
293289
reader, console = self.handle_events_short(events)
294290

295-
console.height = 2
296-
console.getheightwidth = MagicMock(lambda _: (2, 80))
291+
console.getheightwidth = MagicMock(side_effect=lambda: (2, 80))
297292

298293
def same_reader(_):
299294
return reader
@@ -330,8 +325,7 @@ def test_resize_smaller_on_multiline_function(self):
330325
events = itertools.chain(code_to_events(code))
331326
reader, console = self.handle_events_height_3(events)
332327

333-
console.height = 1
334-
console.getheightwidth = MagicMock(lambda _: (1, 80))
328+
console.getheightwidth = MagicMock(side_effect=lambda: (1, 80))
335329

336330
def same_reader(_):
337331
return reader

0 commit comments

Comments
 (0)