def test_create_device_emulator(): """ :py:func:`luma.core.cmdline.create_device` supports emulators. """ display_name = 'emulator1234' display_types = { 'emulator': [display_name], 'led_matrix': [], 'lcd': [], 'oled': [] } class args(test_spi_opts): display = display_name module_mock = Mock() module_mock.emulator.device.emulator1234.return_value = display_name with patch.dict( 'sys.modules', **{ 'spidev': module_mock, 'luma': module_mock, 'luma.emulator': module_mock, 'luma.emulator.device': module_mock }): device = cmdline.create_device(args, display_types=display_types) assert device == display_name
def test_create_device_lcd(): """ :py:func:`luma.core.cmdline.create_device` supports LCD displays. """ display_name = 'lcd1234' display_types = {'lcd': [display_name], 'oled': []} class args(test_spi_opts): display = display_name gpio = 'fake_gpio' backlight_active = 'low' module_mock = Mock() module_mock.lcd.device.lcd1234.return_value = display_name with patch.dict( 'sys.modules', **{ 'fake_gpio': module_mock, 'spidev': module_mock, 'luma': module_mock, 'luma.lcd': module_mock, 'luma.lcd.aux': module_mock, 'luma.lcd.device': module_mock }): device = cmdline.create_device(args, display_types=display_types) assert device == display_name
def test_create_device_oled(): """ :py:func:`luma.core.cmdline.create_device` supports OLED displays. """ display_name = 'oled1234' display_types = {'oled': [display_name]} class args(test_spi_opts): display = display_name module_mock = Mock() module_mock.oled.device.oled1234.return_value = display_name with patch.dict('sys.modules', **{ # mock luma.oled package 'luma': module_mock, 'luma.oled': module_mock, 'luma.oled.device': module_mock }): try: device = cmdline.create_device(args, display_types=display_types) assert device == display_name except ImportError: pytest.skip(rpi_gpio_missing) except error.UnsupportedPlatform as e: # non-rpi platform pytest.skip('{0} ({1})'.format(type(e).__name__, str(e)))
def test_make_serial_spi_alt_gpio(): """ :py:func:`luma.core.cmdline.make_serial.spi` returns an SPI instance when using an alternative GPIO implementation. """ class opts(test_spi_opts): gpio = 'fake_gpio' with patch.dict('sys.modules', **{'fake_gpio': Mock(unsafe=True)}): factory = cmdline.make_serial(opts) with pytest.raises(error.DeviceNotFoundError): factory.spi()
def test_get_library_version(): """ :py:func:`luma.core.cmdline.get_library_version` returns the version number for the specified library name. """ lib_name = 'hotscreenz' lib_version = '0.1.2' # set version nr for fake luma library luma_fake_lib = Mock() luma_fake_lib.__version__ = lib_version with patch.dict('sys.modules', {'luma.' + lib_name: luma_fake_lib}): assert cmdline.get_library_version(lib_name) == lib_version
def test_make_serial_spi_alt_gpio(): """ :py:func:`luma.core.cmdline.make_serial.spi` returns an SPI instance when using an alternative GPIO implementation. """ class opts(test_spi_opts): gpio = 'fake_gpio' with patch.dict('sys.modules', **{'fake_gpio': Mock(unsafe=True)}): try: factory = cmdline.make_serial(opts) assert 'luma.core.interface.serial.spi' in repr(factory.spi()) except ImportError: pytest.skip(spidev_missing) except error.DeviceNotFoundError as e: # non-rpi platform, e.g. ubuntu 64-bit pytest.skip('{0} ({1})'.format(type(e).__name__, str(e)))
def test_create_parser(): """ :py:func:`luma.core.cmdline.create_parser` returns an argument parser instance. """ with patch.dict('sys.modules', **{ 'luma.emulator': Mock(), 'luma.emulator.render': Mock(), }): with patch('luma.core.cmdline.get_display_types') as mocka: mocka.return_value = { 'foo': ['a', 'b'], 'bar': ['c', 'd'], 'emulator': ['e', 'f'] } parser = cmdline.create_parser(description='test') args = parser.parse_args(['-f', test_config_file]) assert args.config == test_config_file
def test_create_device_oled(): """ :py:func:`luma.core.cmdline.create_device` supports OLED displays. """ display_name = 'oled1234' display_types = {'oled': [display_name]} class args(test_spi_opts): display = display_name module_mock = Mock() with patch.dict( 'sys.modules', **{ 'luma': module_mock, 'luma.oled': module_mock, 'luma.oled.device': module_mock }): with pytest.raises(error.UnsupportedPlatform): cmdline.create_device(args, display_types=display_types)
def test_create_device_led_matrix(): """ :py:func:`luma.core.cmdline.create_device` supports LED matrix displays. """ display_name = 'matrix1234' display_types = {'led_matrix': [display_name], 'lcd': [], 'oled': []} class args(test_spi_opts): display = display_name module_mock = Mock() module_mock.led_matrix.device.matrix1234.return_value = display_name with patch.dict('sys.modules', **{ # mock spidev and luma.led_matrix packages 'spidev': module_mock, 'luma': module_mock, 'luma.led_matrix': module_mock, 'luma.led_matrix.device': module_mock }): device = cmdline.create_device(args, display_types=display_types) assert device == display_name
def test_pygame_missing(): with patch.dict('sys.modules', {'pygame': None}): with pytest.raises(RuntimeError) as ex: emulator(1, 2, 3, 4, 5, 6) assert str(ex.value) == 'Emulator requires pygame to be installed'