Ejemplo n.º 1
0
class TestBase64Images(unittest.TestCase):

    def setUp(self):
        self.paths = ["tests/fixtures/happy.png"]
        self.sprite = Sprite(self.paths)

    def test_get_base_64_str(self):
        img = self.sprite.get_base64_str()
        self.assertEquals(img, HAPPY_BASE64)

    def test_get_css_str_with_base64_sprite(self):
        css_template = self.sprite.get_css_base64()
        self.assertIn("image/png", css_template)
        self.assertIn(HAPPY_BASE64, css_template)

    def test_gen_css_file_with_base64_sprite(self):
        css_path = self.sprite.do_write_css(is_base64=True)
        with open(css_path) as arq:
            css_str = arq.read()
        self.assertIn(HAPPY_BASE64, css_str)


    def test_gen_sprite_files_with_base64_sprite(self):
        css_path, image_path = self.sprite.gen_sprite(is_base64=True)
        with open(css_path) as arq:
            css_str = arq.read()
        self.assertIn(HAPPY_BASE64, css_str)
        self.assertIsNone(image_path)
Ejemplo n.º 2
0
class TestBase64Images(unittest.TestCase):
    def setUp(self):
        self.paths = ["tests/fixtures/happy.png"]
        self.sprite = Sprite(self.paths)

    def test_get_base_64_str(self):
        img = self.sprite.get_base64_str()
        self.assertEquals(img, HAPPY_BASE64)

    def test_get_css_str_with_base64_sprite(self):
        css_template = self.sprite.get_css_base64()
        self.assertIn("image/png", css_template)
        self.assertIn(HAPPY_BASE64, css_template)

    def test_gen_css_file_with_base64_sprite(self):
        css_path = self.sprite.do_write_css(is_base64=True)
        with open(css_path) as arq:
            css_str = arq.read()
        self.assertIn(HAPPY_BASE64, css_str)

    def test_gen_sprite_files_with_base64_sprite(self):
        css_path, image_path = self.sprite.gen_sprite(is_base64=True)
        with open(css_path) as arq:
            css_str = arq.read()
        self.assertIn(HAPPY_BASE64, css_str)
        self.assertIsNone(image_path)
Ejemplo n.º 3
0
    def dispatch(self, event):
        if event.is_directory:
            return False

        path = os.path.dirname(event.src_path)

        print("Image {0} {1}").format(os.path.basename(event.src_path),
                                      event.event_type)
        files = []
        for arg in os.listdir(path):
            j = os.path.join(path, arg)
            if imghdr.what(j) is not None:
                files.append(j)

        sprite = Sprite(files,
                        css_path=css_dir,
                        sprite_path=sprite_dir,
                        class_name=class_name)

        sprite.gen_sprite()
Ejemplo n.º 4
0
    def dispatch(self, event):
        if event.is_directory:
            return False

        path = os.path.dirname(event.src_path)

        print("Image {0} {1}").format(os.path.basename(event.src_path),
                                      event.event_type)
        files = []
        for arg in os.listdir(path):
            j = os.path.join(path, arg)
            if imghdr.what(j) is not None:
                files.append(j)

        sprite = Sprite(files,
                        css_path=css_dir,
                        sprite_path=sprite_dir,
                        class_name=class_name)

        sprite.gen_sprite()