def test_display(): """ UC1701X LCD screen can draw and display an image. """ device = uc1701x(serial, gpio=Mock()) serial.reset_mock() recordings = [] def data(data): recordings.append({'data': data}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command = Mock(side_effect=command, unsafe=True) serial.data = Mock(side_effect=data, unsafe=True) # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) serial.data.assert_called() serial.command.assert_called() assert recordings == get_reference_data('demo_uc1701x')
def test_display(): device = st7735(serial) serial.reset_mock() recordings = [] def data(data): recordings.append({'data': data}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command.side_effect = command serial.data.side_effect = data # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) assert serial.data.called assert serial.command.called assert recordings == [{ 'command': [42] }, { 'data': [0, 0, 0, 159] }, { 'command': [43] }, { 'data': [0, 0, 0, 127] }, { 'command': [44] }, { 'data': get_reference_data('demo_st7735') }]
def test_greyscale_display(): """ SSD1322 OLED screen can draw and display a greyscale image. """ device = ssd1322(serial, mode="RGB", framebuffer=full_frame()) serial.reset_mock() recordings = [] def data(data): recordings.append({'data': data}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command.side_effect = command serial.data.side_effect = data # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) assert serial.data.called assert serial.command.called # To regenerate test data, uncomment the following (remember not to commit though) # ================================================================================ # from baseline_data import save_reference_data # save_reference_data("demo_ssd1322_greyscale", recordings) assert recordings == get_reference_data('demo_ssd1322_greyscale')
def test_display(): """ SH1106 OLED screen can draw and display an image. """ device = sh1106(serial) serial.reset_mock() recordings = [] def data(data): recordings.append({'data': data}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command = Mock(side_effect=command, unsafe=True) serial.data = Mock(side_effect=data, unsafe=True) # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) serial.data.assert_called() serial.command.assert_called() assert recordings == get_json_data('demo_sh1106')
def test_display(): """ SH1106 OLED screen can draw and display an image. """ device = sh1106(serial) serial.reset_mock() recordings = [] def data(data): recordings.append({'data': data}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command = Mock(side_effect=command, unsafe=True) serial.data = Mock(side_effect=data, unsafe=True) # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) serial.data.assert_called() serial.command.assert_called() # To regenerate test data, uncomment the following (remember not to commit though) # ================================================================================ # from baseline_data import save_reference_data # save_reference_data("demo_sh1106", recordings) assert recordings == get_reference_data('demo_sh1106')
def test_display_full_frame(): device = ili9486(serial, gpio=Mock(), framebuffer=full_frame()) serial.reset_mock() recordings = [] def data(data): recordings.append({'data': list(data)}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command.side_effect = command serial.data.side_effect = data # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) assert serial.data.called assert serial.command.called # To regenerate test data, uncomment the following (remember not to commit though) # ================================================================================ # from baseline_data import save_reference_data # save_reference_data("demo_ili9486", recordings) assert recordings == get_reference_data('demo_ili9486')
def test_greyscale_display(): """ SSD1322_NHD OLED screen can draw and display a greyscale image. """ device = ssd1322_nhd(serial, mode="RGB") serial.reset_mock() recordings = [] def data(data): recordings.append({'data': data}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command.side_effect = command serial.data.side_effect = data # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) assert serial.data.called assert serial.command.called assert recordings == [ {'command': [21]}, {'data': [28, 91]}, {'command': [117]}, {'data': [0, 63]}, {'command': [92]}, {'data': get_json_data('demo_ssd1322_nhd_greyscale')} ]
def test_display(): with NamedTemporaryFile(suffix='.png', delete=True) as temp: fname = temp.name device = capture(file_template=fname, transform="none") # Use the same drawing primitives as the demo with canvas(device) as draw: baseline_data.primitives(device, draw) assert_identical('capture.png', fname)
def test_diplay(): device = sh1106(bus) bus.reset() # Use the same drawing primitives as the demo with canvas(device) as draw: baseline_data.primitives(device, draw) assert len(bus.recordings) == 40 for i in range(40): assert bus.recordings[i] == baseline_data.demo_sh1106[i]
def test_portrait(): reference = os.path.abspath( os.path.join(os.path.dirname(__file__), 'reference', 'portrait.png')) fname = NamedTemporaryFile(suffix=".png").name device = capture(rotate=1, file_template=fname, transform="none") # Use the same drawing primitives as the demo with canvas(device) as draw: baseline_data.primitives(device, draw) assert md5(reference) == md5(fname)
def test_display(): device = pcd8544(serial, gpio=Mock()) serial.reset_mock() # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) # Initial command to reset the display serial.command.assert_called_once_with(32, 128, 64) # Next 1024 bytes are data representing the drawn image serial.data.assert_called_once_with(get_reference_data('demo_pcd8544'))
def test_portrait(): img_path = get_reference_image('portrait.png') with open(img_path, 'rb') as p: reference = Image.open(p) device = dummy(rotate=1) # Use the same drawing primitives as the demo with canvas(device) as draw: baseline_data.primitives(device, draw) assert_identical_image(reference, device.image)
def test_display(): device = pcd8544(serial) serial.reset_mock() # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) # Initial command to reset the display serial.command.assert_called_once_with(32, 128, 64) # Next 1024 bytes are data representing the drawn image serial.data.assert_called_once_with(get_reference_data('demo_pcd8544'))
def test_display(): device = ssd1331(serial) serial.reset_mock() # Use the same drawing primitives as the demo with canvas(device) as draw: baseline_data.primitives(device, draw) # Initial command to reset the display serial.command.assert_called_once_with(21, 0, 95, 117, 0, 63) # Next 12288 bytes are data representing the drawn image serial.data.assert_called_once_with(baseline_data.demo_ssd1331)
def test_viewport_set_position(): reference = os.path.abspath( os.path.join(os.path.dirname(__file__), 'reference', 'set_position.png')) fname = NamedTemporaryFile(suffix=".png").name device = capture(file_template=fname, transform="none") virtual = viewport(device, 200, 200) # Use the same drawing primitives as the demo with canvas(virtual) as draw: baseline_data.primitives(virtual, draw) virtual.set_position((20, 30)) assert md5(reference) == md5(fname)
def test_viewport_set_position(): img_path = get_reference_image('set_position.png') with open(img_path, 'rb') as p: reference = Image.open(p) device = dummy() virtual = viewport(device, 200, 200) # Use the same drawing primitives as the demo with canvas(virtual) as draw: baseline_data.primitives(virtual, draw) virtual.set_position((20, 30)) assert_identical_image(reference, device.image, img_path)
def test_display(): """ SSD1309 OLED screen can draw and display an image. """ device = ssd1309(serial) serial.reset_mock() # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) # Initial command to reset the display serial.command.assert_called_once_with(33, 0, 127, 34, 0, 7) # Next 1024 bytes are data representing the drawn image serial.data.assert_called_once_with(get_json_data('demo_ssd1309'))
def test_diplay(): device = ssd1306(bus) bus.reset() # Use the same drawing primitives as the demo with canvas(device) as draw: baseline_data.primitives(device, draw) assert len(bus.recordings) == 33 # Initial command to reset the display assert bus.recordings[0] == mock.recording(60, 0, [33, 0, 127, 34, 0, 7]) # Next 32 recordings are data representing the drawn image for i in range(32): assert bus.recordings[i + 1] == baseline_data.demo_ssd1306[i]
def test_display(): """ SSD1306 OLED screen can draw and display an image. """ device = ssd1306(serial) serial.reset_mock() # Use the same drawing primitives as the demo with canvas(device) as draw: baseline_data.primitives(device, draw) # Initial command to reset the display serial.command.assert_called_once_with(33, 0, 127, 34, 0, 7) # Next 1024 bytes are data representing the drawn image serial.data.assert_called_once_with(baseline_data.demo_ssd1306)
def test_monochrome_display(): """ SSD1325 OLED screen can draw and display a monochrome image. """ device = ssd1325(serial, mode="1") serial.reset_mock() # Use the same drawing primitives as the demo with canvas(device) as draw: baseline_data.primitives(device, draw) # Initial command to reset the display serial.command.assert_called_once_with(21, 0, 127, 117, 0, 63) # Next 4096 bytes are data representing the drawn image serial.data.assert_called_once_with(baseline_data.demo_ssd1325_monochrome)
def test_gifanim_write(): with NamedTemporaryFile(suffix='.gif') as temp: fname = temp.name device = gifanim(filename=fname) with canvas(device) as draw: baseline_data.primitives(device, draw) with canvas(device) as draw: draw.text((30, 10), text="Blipvert", fill="white") with canvas(device) as draw: baseline_data.primitives(device, draw) device.write_animation() assert_identical('anim.gif', fname)
def test_monochrome_display(): """ SSD1327 OLED screen can draw and display a monochrome image. """ device = ssd1327(serial, mode="1") serial.reset_mock() # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) # Initial command to reset the display serial.command.assert_called_once_with(21, 0, 63, 117, 0, 127) # Next 4096 bytes are data representing the drawn image serial.data.assert_called_once_with(get_json_data('demo_ssd1327_monochrome'))
def test_display(): """ SSD1331 OLED screen can draw and display an image. """ device = ssd1331(serial) serial.reset_mock() # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) # Initial command to reset the display serial.command.assert_called_once_with(21, 0, 95, 117, 0, 63) # Next 12288 bytes are data representing the drawn image serial.data.assert_called_once_with(get_json_data('demo_ssd1331'))
def test_greyscale_display(): """ SSD1362 OLED screen can draw and display a greyscale image. """ device = ssd1362(serial, mode="RGB") serial.reset_mock() # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) # Initial command to reset the display serial.command.assert_called_once_with(21, 0, 127, 117, 0, 63) # Next 4096 bytes are data representing the drawn image serial.data.assert_called_once_with(get_json_data('demo_ssd1362_greyscale'))
def test_gifanim_write(): reference = os.path.abspath( os.path.join(os.path.dirname(__file__), 'reference', 'anim.gif')) fname = NamedTemporaryFile(suffix=".gif").name device = gifanim(filename=fname) with canvas(device) as draw: baseline_data.primitives(device, draw) with canvas(device) as draw: draw.text((30, 10), text="Blipvert", fill="white") with canvas(device) as draw: baseline_data.primitives(device, draw) device.write_animation() assert md5(reference) == md5(fname)
def test_display(): device = pcd8544(serial, gpio=Mock()) serial.reset_mock() # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) # Initial command to reset the display serial.command.assert_called_once_with(32, 128, 64) # To regenerate test data, uncomment the following (remember not to commit though) # ================================================================================ # from baseline_data import save_reference_data # save_reference_data("demo_pcd8544", serial.data.call_args.args[0]) # Next 1024 bytes are data representing the drawn image serial.data.assert_called_once_with(get_reference_data('demo_pcd8544'))
def test_save_and_restore_reverts_image(): device = dummy() hist = history(device) with canvas(hist) as draw: baseline_data.primitives(hist, draw) img1 = device.image hist.savepoint() assert len(hist) == 1 with canvas(hist) as draw: draw.text((10, 10), text="Hello", fill="white") img2 = device.image assert img1 != img2 hist.restore() img3 = device.image assert img1 == img3 assert len(hist) == 0
def test_display(): """ SSD1331 OLED screen can draw and display an image. """ device = ssd1331(serial, framebuffer=full_frame()) serial.reset_mock() # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) # Initial command to reset the display serial.command.assert_called_once_with(21, 0, 95, 117, 0, 63) # To regenerate test data, uncomment the following (remember not to commit though) # ================================================================================ # from baseline_data import save_reference_data # save_reference_data("demo_ssd1331", serial.data.call_args.args[0]) # Next 12288 bytes are data representing the drawn image serial.data.assert_called_once_with(get_reference_data('demo_ssd1331'))
def test_display(): # If ascii art works, then do the test otherwise just end the function call if ASCII_AVAILABLE: scr_height = 40 scr_width = 100 fake_result = struct.pack('HHHH', scr_height, scr_width, 600, 616) with redirect_stdout() as f: sys.stdout.fileno = lambda: 1 with patch('fcntl.ioctl', return_value=fake_result): device = asciiblock() with canvas(device) as draw: baseline_data.primitives(device, draw) device.cleanup = noop out = f.getvalue().encode('utf-8') digest = hashlib.md5(out).hexdigest() fname = Path(__file__).resolve().parent.joinpath( 'reference', 'asciiblock.txt') assert md5(str(fname)) == digest
def test_monochrome_display(): """ SSD1322 OLED screen can draw and display a monochrome image. """ device = ssd1322(serial, mode="1") serial.reset_mock() recordings = [] def data(data): recordings.append({'data': data}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command.side_effect = command serial.data.side_effect = data # Use the same drawing primitives as the demo with canvas(device) as draw: baseline_data.primitives(device, draw) assert serial.data.called assert serial.command.called assert recordings == [{ 'command': [21] }, { 'data': [28, 91] }, { 'command': [117] }, { 'data': [0, 127] }, { 'command': [92] }, { 'data': baseline_data.demo_ssd1322_monochrome }]
def test_display(): """ SSD1351 OLED screen can draw and display a color image. """ device = ssd1351(serial) serial.reset_mock() recordings = [] def data(data): recordings.append({'data': data}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command.side_effect = command serial.data.side_effect = data # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) assert serial.data.called assert serial.command.called assert recordings == [{ 'command': [21] }, { 'data': [0, 127] }, { 'command': [117] }, { 'data': [0, 127] }, { 'command': [92] }, { 'data': get_json_data('demo_ssd1351') }]
def test_greyscale_display(): """ SSD1322_NHD OLED screen can draw and display a greyscale image. """ device = ssd1322_nhd(serial, mode="RGB") serial.reset_mock() recordings = [] def data(data): recordings.append({'data': data}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command.side_effect = command serial.data.side_effect = data # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) assert serial.data.called assert serial.command.called assert recordings == [{ 'command': [21] }, { 'data': [28, 91] }, { 'command': [117] }, { 'data': [0, 63] }, { 'command': [92] }, { 'data': get_json_data('demo_ssd1322_nhd_greyscale') }]
def test_display(): device = sh1106(serial) serial.reset_mock() recordings = [] def data(data): recordings.append({'data': data}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command = Mock(side_effect=command, unsafe=True) serial.data = Mock(side_effect=data, unsafe=True) # Use the same drawing primitives as the demo with canvas(device) as draw: baseline_data.primitives(device, draw) serial.data.assert_called() serial.command.assert_called() assert recordings == baseline_data.demo_sh1106
def test_display(): device = st7567(serial) serial.reset_mock() recordings = [] def data(data): recordings.append({'data': data}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command.side_effect = command serial.data.side_effect = data # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) assert serial.data.called assert serial.command.called assert recordings == get_reference_data('demo_st7567')
def test_display(): device = st7567(serial, gpio=Mock()) serial.reset_mock() recordings = [] def data(data): recordings.append({'data': data}) def command(*cmd): recordings.append({'command': list(cmd)}) serial.command.side_effect = command serial.data.side_effect = data # Use the same drawing primitives as the demo with canvas(device) as draw: primitives(device, draw) assert serial.data.called assert serial.command.called assert recordings == get_reference_data('demo_st7567')
def draw_fn(draw, width, height): baseline_data.primitives(device, draw)