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_bounds(): expected_width = 800 expected_height = 600 t = MockTurtle(canvas=Canvas(expected_width, expected_height)) width = t.getscreen().window_width() height = t.getscreen().window_height() size = t.getscreen().screensize() assert width == expected_width assert height == expected_height assert size == (expected_width, expected_height)
def test_colormode(): expected_report = """\ create_line 0 0 100 0 fill='#007fff' pensize=1""" t = MockTurtle() t.getscreen().colormode(255) t.color(0, 127, 255) t.fd(100) report = t.report assert report == expected_report.splitlines()
def test_mode(patched_turtle): expected_report = """\ create_line 0 0 0 -100 fill='black' pensize=1 """ t = MockTurtle() t.getscreen().mode('logo') t.forward(100) report = t.report assert report == expected_report.splitlines()
def test_clearscreen(patched_turtle): expected_report = """\ create_line 0 0 20 0 fill='black' pensize=1""" t = MockTurtle() for i in range(4): t.pensize(i + 1) # force new line t.fd(100) t.left(90) t.getscreen().clear() t2 = MockTurtle() t2.fd(20) report = t2.report assert report == expected_report.splitlines() assert not any(item['deleted'] for item in t.getscreen().cv.items)