Ejemplo n.º 1
0
    def test__get_border(self):
        """
        Test for _get_border method
        """
        obj = base.FullScreenImage(HIRES)
        self.assertEqual(obj._get_border(), 0)

        obj._load()
        obj._find_best_palette_map()
        histogram = obj._src_image.histogram()
        obj._find_most_freq_color(histogram)
        self.assertEqual(obj._get_border(), 0)

        obj = base.FullScreenImage(COLORS_256)
        obj.set_border_color(12)
        self.assertEqual(obj._get_border(), 12)

        obj = base.FullScreenImage(COLORS_256)
        self.assertEqual(obj._get_border(), 0)

        obj._load()
        obj._find_best_palette_map()
        histogram = obj._src_image.histogram()
        obj._find_most_freq_color(histogram)
        self.assertEqual(obj._get_border(), 5)
        obj.set_border_color(7)
        self.assertEqual(obj._get_border(), 7)
Ejemplo n.º 2
0
    def test_convert(self):
        """
        Test convert process
        """
        obj = base.FullScreenImage("nofile")
        self.assertFalse(obj.convert())

        obj = base.FullScreenImage(COLORS_256)
        self.assertRaises(NotImplementedError, obj.convert)

        obj = base.FullScreenImage(CROP_BOTH)
        self.assertFalse(obj.convert())
Ejemplo n.º 3
0
    def test__load(self):
        """
        Test of loading images
        """
        self.assertTrue(base.FullScreenImage(HIRES)._load())
        obj = base.FullScreenImage("nofile")
        self.assertFalse(obj._load())

        obj = base.FullScreenImage("/none/existing")
        self.assertFalse(obj._load())
        obj.log.setLevel(logging.DEBUG)
        self.assertRaises(IOError, obj._load)
        obj.log.setLevel(logging.WARNING)
Ejemplo n.º 4
0
 def test_save(self):
     """
     Test save method
     """
     obj = base.FullScreenImage(HIRES)
     obj._load()
     self.assertRaises(NotImplementedError, obj.save, "fn")
Ejemplo n.º 5
0
 def test__fill_memory(self):
     """
     Test _fill_memory method
     """
     obj = base.FullScreenImage(HIRES)
     obj._load()
     self.assertRaises(NotImplementedError, obj._fill_memory)
Ejemplo n.º 6
0
    def test__get_best_palette_map(self):
        """
        Test for method _find_best_palette_map
        """
        obj = base.FullScreenImage(COLORS_1)
        obj._load()
        obj._find_best_palette_map()
        self.assertEqual(obj._palette_map, {(0, 0, 0): 0})

        obj = base.FullScreenImage(COLORS_2)
        obj._load()
        obj._find_best_palette_map()
        histogram = obj._src_image.histogram()
        obj._find_most_freq_color(histogram)

        self.assertEqual(obj.data['most_freq_color'], 11)
Ejemplo n.º 7
0
    def test__check_dimensions(self):
        """
        Test of dimensions of the input images
        """
        for fname in (CROP_V, CROP_H, CROP_BOTH, CLASH_M2, MULTI, PAL_PEPTO,
                      PAL_TIMANTHES, PAL_UNKNOWN, PAL_VICE):
            obj = base.FullScreenImage(fname)
            obj.log.error = lambda *x: None  # suppress log
            obj._load()
            self.assertFalse(obj._check_dimensions())

        for fname in (CLASH_H, CLASH_M, COLORS_256, COLORS_1, COLORS_2,
                      COLORS_256_U16, HIRES, MULTI_320):
            obj = base.FullScreenImage(fname)
            obj._load()
            self.assertTrue(obj._check_dimensions())
Ejemplo n.º 8
0
 def test_set_border_color(self):
     """
     Test set_border_color method
     """
     obj = base.FullScreenImage(HIRES)
     self.assertEqual(obj.data.get('border'), None)
     obj.set_border_color(14)
     self.assertEqual(obj.data.get('border'), 14)
Ejemplo n.º 9
0
 def test_set_bg_color(self):
     """
     Test set_bg_color method
     """
     obj = base.FullScreenImage(HIRES)
     self.assertEqual(obj.data.get('background'), None)
     obj.set_bg_color(15)
     self.assertEqual(obj.data.get('background'), 15)
Ejemplo n.º 10
0
 def test___init(self):
     """
     Test initialization
     """
     self.assertRaises(TypeError, base.FullScreenImage)
     obj = base.FullScreenImage(MULTI_320)
     self.assertEqual(obj._fname, MULTI_320)
     self.assertEqual(obj._errors_action, "none")
     self.assertEqual(obj._src_image, None)
     self.assertTrue(isinstance(obj.log, logging.Logger))
     self.assertEqual(obj.data, {})
Ejemplo n.º 11
0
    def test__colors_check(self):
        """
        Test _colors_check method
        """
        obj = base.FullScreenImage(COLORS_256)
        obj._load()
        histogram = obj._src_image.histogram()
        # even if input image have 256 colors, internally it will be converted
        # to 16 colors.
        self.assertEqual(obj._colors_check(histogram), 16)

        obj = base.FullScreenImage(COLORS_1)
        obj.log.warn = lambda x, y: None  # suppress log
        obj._load()
        histogram = obj._src_image.histogram()
        self.assertEqual(obj._colors_check(histogram), 1)

        obj = base.FullScreenImage(COLORS_2)
        obj._load()
        histogram = obj._src_image.histogram()
        self.assertEqual(obj._colors_check(histogram), 2)
Ejemplo n.º 12
0
    def test__get_palette(self):
        """
        Test _get_palette method
        """
        obj = base.FullScreenImage(PAL_PEPTO)
        obj._load()

        ref_palette = set(
            ((0, 0, 0), (53, 40, 121), (67, 57, 0), (68, 68, 68),
             (88, 141, 67), (104, 55, 43), (108, 94, 181), (108, 108, 108),
             (111, 61, 134), (111, 79, 37), (112, 164, 178), (149, 149, 149),
             (154, 103, 89), (154, 210, 132), (184, 199, 111), (255, 255,
                                                                255)))

        # got 16 colors pepto palette ordered by lightness
        self.assertEqual(set(obj._get_palette()), ref_palette)
Ejemplo n.º 13
0
    def test_attributes(self):
        """
        Test settting background/border colors
        """
        obj = base.FullScreenImage(HIRES)
        self.assertEqual(obj.data, {})

        obj.set_border_color(12)
        self.assertEqual(obj.data, {'border': 12})

        obj.set_bg_color(11)
        self.assertEqual(obj.data, {'background': 11, 'border': 12})

        obj.set_border_color(1)
        self.assertEqual(obj.data, {'background': 11, 'border': 1})

        obj.set_bg_color(0)
        self.assertEqual(obj.data, {'background': 0, 'border': 1})
Ejemplo n.º 14
0
    def test__error_image_action(self):
        """
        Test for _error_image_action method
        """
        error_img = base.get_modified_fname(MULTI, 'png', '_error.')

        if os.path.exists(error_img):
            os.unlink(error_img)

        obj = base.FullScreenImage(MULTI)
        obj._load()
        result = obj._error_image_action([(0, 0)], True)
        self.assertEqual(result, None)

        obj._errors_action = "save"
        result = obj._error_image_action([(0, 0)], True)
        self.assertTrue(os.path.exists(error_img))
        os.unlink(error_img)

        # does nothing. maybe some refactoring needed for _error_image_action
        # method?
        obj._errors_action = "show"
        obj._error_image_action([(0, 0)], True)

        obj = base.FullScreenImage(MULTI)
        obj._load()
        obj._errors_action = "show"
        obj._error_image_action([(0, 0)], True)

        error_img = base.get_modified_fname(MULTI_320, 'png', '_error.')

        if os.path.exists(error_img):
            os.unlink(error_img)

        obj = base.FullScreenImage(MULTI_320)
        obj._load()
        result = obj._error_image_action([(0, 0)])
        self.assertEqual(result, None)

        obj._errors_action = "save"
        result = obj._error_image_action([(0, 0)])
        self.assertTrue(os.path.exists(error_img))
        os.unlink(error_img)

        # does nothing. maybe some refactoring needed for _error_image_action
        # method?
        obj._errors_action = "show"
        obj._error_image_action([(0, 0)])

        obj = base.FullScreenImage(MULTI_320)
        obj._load()
        obj._errors_action = "show"
        obj._error_image_action([(0, 0)])

        error_img = base.get_modified_fname(HIRES, 'png', '_error.')

        if os.path.exists(error_img):
            os.unlink(error_img)

        obj = base.FullScreenImage(HIRES)
        obj._load()
        result = obj._error_image_action([(0, 0)])
        self.assertEqual(result, None)

        obj._errors_action = "save"
        result = obj._error_image_action([(0, 0)])
        self.assertTrue(os.path.exists(error_img))
        os.unlink(error_img)

        # does nothing. maybe some refactoring needed for _error_image_action
        # method?
        obj._errors_action = "show"
        obj._error_image_action([(0, 0)])

        obj = base.FullScreenImage(MULTI)
        obj._load()
        obj._errors_action = "show"
        obj._error_image_action([(0, 0)])

        # Test the grafx2 option
        error_img = base.get_modified_fname(MULTI_320, 'png', '_error.')
        obj = base.FullScreenImage(MULTI_320)
        obj._load()
        obj._errors_action = "grafx2"
        obj._error_image_action([(0, 0)])
        self.assertTrue("grafx2" in self.os_system_params)
        os.unlink(error_img)
Ejemplo n.º 15
0
    def test__discover_best_palette(self):
        """
        Test _discover_best_palette method
        """
        obj = base.FullScreenImage(PAL_PEPTO)
        obj._load()
        obj._find_best_palette_map()
        self.assertEqual(
            obj._palette_map, {
                (184, 199, 111): 7,
                (154, 210, 132): 13,
                (112, 164, 178): 3,
                (88, 141, 67): 5,
                (0, 0, 0): 0,
                (108, 94, 181): 14,
                (68, 68, 68): 11,
                (154, 103, 89): 10,
                (67, 57, 0): 9,
                (53, 40, 121): 6,
                (111, 79, 37): 8,
                (108, 108, 108): 12,
                (111, 61, 134): 4,
                (255, 255, 255): 1,
                (104, 55, 43): 2,
                (149, 149, 149): 15
            })

        obj = base.FullScreenImage(PAL_VICE)
        obj._load()
        obj._find_best_palette_map()
        self.assertEqual(
            obj._palette_map, {
                (182, 89, 0): 9,
                (0, 142, 0): 5,
                (147, 81, 182): 4,
                (56, 255, 52): 5,
                (154, 154, 154): 15,
                (0, 81, 158): 6,
                (134, 134, 134): 12,
                (0, 182, 182): 14,
                (255, 109, 109): 10,
                (0, 0, 0): 0,
                (85, 85, 85): 11,
                (109, 121, 255): 14,
                (213, 223, 124): 7,
                (255, 255, 255): 1,
                (109, 52, 0): 9,
                (207, 0, 0): 2
            })

        obj = base.FullScreenImage(PAL_TIMANTHES)
        obj._load()
        obj._find_best_palette_map()
        self.assertEqual(
            obj._palette_map, {
                (103, 93, 182): 14,
                (143, 194, 113): 13,
                (86, 141, 53): 5,
                (174, 183, 94): 7,
                (101, 159, 166): 3,
                (143, 143, 143): 15,
                (156, 100, 90): 10,
                (115, 58, 145): 4,
                (0, 0, 0): 0,
                (71, 71, 71): 11,
                (75, 60, 0): 9,
                (114, 53, 44): 2,
                (107, 107, 107): 12,
                (119, 79, 30): 8,
                (213, 213, 213): 1,
                (46, 35, 125): 6
            })

        obj = base.FullScreenImage(PAL_UNKNOWN)
        obj._load()
        obj._find_best_palette_map()
        self.assertEqual(
            obj._palette_map, {
                (91, 50, 8): 9,
                (130, 130, 130): 12,
                (230, 122, 122): 10,
                (0, 181, 181): 14,
                (211, 211, 112): 7,
                (23, 63, 194): 6,
                (49, 150, 49): 5,
                (79, 123, 255): 14,
                (198, 0, 0): 2,
                (193, 90, 0): 9,
                (160, 160, 160): 15,
                (178, 66, 178): 4,
                (255, 255, 255): 1,
                (42, 232, 112): 5,
                (85, 85, 85): 11,
                (0, 0, 0): 0
            })