コード例 #1
0
    def test_new_image_to_display(self, mock_image_manager):
        Definitions.TEMP_IMAGE_BLACK = self.TEST_IMAGE_DOES_NOT_EXIST
        Definitions.TEMP_IMAGE_COLOUR = self.TEST_IMAGE_DOES_NOT_EXIST

        copyfile(Definitions.PC33_BLACK_FILEPATH, self.BLACK_TEST_PNG)
        copyfile(Definitions.PC33_COLOUR_FILEPATH, self.COLOUR_TEST_PNG)

        mock_im_instance = MagicMock()
        mock_image_manager.return_value = mock_im_instance

        test_epaper_image = EpaperImage(MagicMock(), MagicMock())
        mock_im_instance.get_epaper_image.return_value = test_epaper_image

        image_lock = Lock()
        class_under_test = PictureDisplayManager(image_lock)

        Definitions.TEMP_IMAGE_BLACK = self.BLACK_TEST_PNG
        Definitions.TEMP_IMAGE_COLOUR = self.COLOUR_TEST_PNG

        self.assertTrue(class_under_test.new_image_to_display(False))

        mock_im_instance.assert_has_calls([call.reset_to_background(),
                                           call.generate_display_image(Definitions.TEMP_IMAGE_BLACK, Definitions.TEMP_IMAGE_COLOUR),
                                           call.get_epaper_image()])

        self.assertFalse(os.path.isfile(Definitions.TEMP_IMAGE_BLACK))
        self.assertFalse(os.path.isfile(Definitions.TEMP_IMAGE_COLOUR))
コード例 #2
0
    def test_update_display_with_pre_generated(self, mock_image_manager):
        mock, mock_im_instance, mock_epd = MagicMock(), MagicMock(), MagicMock()
        mock.im_instance, mock.epd = mock_im_instance, mock_epd

        mock_image_manager.return_value = mock_im_instance
        test_epaper_image = EpaperImage(Images.epaper_00pc, Images.epaper_00pc)
        mock_im_instance.get_epaper_image.return_value = test_epaper_image

        image_lock = Lock()
        class_under_test = PictureDisplayManager(image_lock)
        class_under_test.update_display(mock_epd)
        mock.assert_has_calls([call.epd.safe_display(test_epaper_image)])
コード例 #3
0
    def test_update_display_from_filepath(self, mock_image_manager):
        mock, mock_im_instance, mock_epd = MagicMock(), MagicMock(), MagicMock()
        mock.im_instance, mock.epd = mock_im_instance, mock_epd

        mock_image_manager.return_value = mock_im_instance
        empty_epaper_image = EpaperImage()
        mock_im_instance.get_epaper_image.return_value = empty_epaper_image

        test_epaper_image = EpaperImage(MagicMock(), MagicMock())
        mock_im_instance.generate_display_image.return_value = test_epaper_image

        Definitions.READY_IMAGE_BLACK = Definitions.PC33_BLACK_FILEPATH
        Definitions.READY_IMAGE_COLOUR = Definitions.PC33_COLOUR_FILEPATH

        image_lock = Lock()
        class_under_test = PictureDisplayManager(image_lock)

        class_under_test.update_display(mock_epd)
        mock.assert_has_calls([call.epd.safe_display(test_epaper_image)])
コード例 #4
0
 def test_get_mode(self):
     self.assertIs(PictureDisplayManager.get_mode(), DisplayMode.IMAGE)
コード例 #5
0
 def test_can_register(self):
     class_under_test = PictureDisplayManager(Lock())
     self.assertTrue(class_under_test.can_register())
コード例 #6
0
 def test_printable_name(self):
     class_under_test = PictureDisplayManager(Lock())
     self.assertEqual(class_under_test.printable_name(), 'Image display - crops, resizes and anti-aliases a black and/or a colour image.')
コード例 #7
0
            # the epd in full power mode.
            except:
                logging.error('Error:')
                logging.error(traceback.format_exc())
                epd.full_exit()
                exit(1)


logging.basicConfig(filename='torrent_box.log', level=logging.INFO)
config = Configuration()

# Setup display manager switcher and add PictureDisplayManager
image_lock = Lock()
switch_mode_lock = Lock()
dm_switcher = DisplayManagerSwitcher(switch_mode_lock,
                                     PictureDisplayManager(image_lock))

dm_switcher.register(
    TorrentDisplayManager(config, config.get(ConfigKeys.chilli_display_mode)))

# Set starting mode, if available
starting_display_mode = DisplayMode[config.get(
    ConfigKeys.default_display_mode)]
if starting_display_mode:
    try:
        dm_switcher.propose_mode(starting_display_mode)
    except KeyError:
        logging.error(
            "default_display_mode is %s but this was not accepted, is it configured in config.yml ?",
            config.get(ConfigKeys.default_display_mode))