def test_is_patched(): assert not MockTurtle.is_patched() MockTurtle.monkey_patch() try: assert MockTurtle.is_patched() finally: MockTurtle.remove_monkey_patch() assert not MockTurtle.is_patched()
def display_diff(self, actual: LivePainter, expected: LivePainter): if not self.is_displayed: return if not MockTurtle.is_patched(): return t = MockTurtle() w = t.getscreen().window_width() h = t.getscreen().window_height() ox, oy = w / 2, h / 2 actual_width, actual_height = actual.get_size() expected_width, expected_height = expected.get_size() diff_width, diff_height = self.diff.get_size() text_space = (h - actual_height - diff_height - expected_height) text_height = max(20, text_space // 3) font = ('Arial', text_height // 2, 'normal') t.penup() t.goto(-ox, oy) t.right(90) t.forward(text_height) t.write('Actual', font=font) actual.display(t.pos()) t.forward(actual_height) t.forward(text_height) t.write('Diff ({} pixels)'.format(self.diff_count), font=font) self.diff.display(t.pos()) t.forward(diff_height) t.forward(text_height) t.write('Expected', font=font) expected.display(t.pos())
def test_offset(): assert not MockTurtle.is_patched() expected_report = """\ create_line 400 300 500 300 fill='black' pensize=1 """ t = MockTurtle(canvas=Canvas(800, 600)) t.fd(100) report = t.report assert report == expected_report.splitlines()
def test_offset_with_scale(): """ The offset is applied BEFORE the scale. """ assert not MockTurtle.is_patched() expected_report = """\ create_line 400 300 500 300 fill='black' pensize=1 """ t = MockTurtle(canvas=Canvas(800, 600)) t.screen.xscale = 100 t.fd(1) report = t.report assert report == expected_report.splitlines()