How to use the premailer.premailer.merge_styles function in premailer

To help you get started, we’ve selected a few premailer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github peterbe / premailer / premailer / test_premailer.py View on Github external
def run(self):
                """Calls merge_styles in a loop and sets exc attribute if merge_styles raises an exception."""
                for i in range(0, REPEATS):
                    try:
                        merge_styles(self.old, self.new, self.class_)
                    except Exception as e:
                        logging.exception("Exception in thread %s", self.name)
                        self.exc = e
github peterbe / premailer / premailer / test_premailer.py View on Github external
def test_merge_styles_basic(self):
        old = 'font-size:1px; color: red'
        new = 'font-size:2px; font-weight: bold'
        expect = 'color:red;', 'font-size:2px;', 'font-weight:bold'
        result = merge_styles(old, new)
        for each in expect:
            ok_(each in result)
github peterbe / premailer / premailer / test_premailer.py View on Github external
def test_merge_styles_non_trivial(self):
        old = 'background-image:url("data:image/png;base64,iVBORw0KGg")'
        new = 'font-size:2px; font-weight: bold'
        expect = (
            'background-image:url("data:image/png;base64,iVBORw0KGg")',
            'font-size:2px;',
            'font-weight:bold'
        )
        result = merge_styles(old, new)
        for each in expect:
            ok_(each in result)
github peterbe / premailer / premailer / test_premailer.py View on Github external
def test_merge_styles_with_class(self):
        old = 'color:red; font-size:1px;'
        new, class_ = 'font-size:2px; font-weight: bold', ':hover'

        # because we're dealing with dicts (random order) we have to
        # test carefully.
        # We expect something like this:
        #  {color:red; font-size:1px} :hover{font-size:2px; font-weight:bold}

        result = merge_styles(old, new, class_)
        ok_(result.startswith('{'))
        ok_(result.endswith('}'))
        ok_(' :hover{' in result)
        split_regex = re.compile('{([^}]+)}')
        eq_(len(split_regex.findall(result)), 2)
        expect_first = 'color:red', 'font-size:1px'
        expect_second = 'font-weight:bold', 'font-size:2px'
        for each in expect_first:
            ok_(each in split_regex.findall(result)[0])
        for each in expect_second:
            ok_(each in split_regex.findall(result)[1])