Example #1
0
    def test_from_string(self):
        properties = Properties.from_string('color: red; font-weight: bold')
        self.assertEqual(properties, {
            'color': 'red',
            'font-weight': 'bold',
        })

        properties = Properties.from_string('padding: 0 10px')
        self.assertEqual(properties, {
            'padding-top': '0',
            'padding-right': '10px',
            'padding-bottom': '0',
            'padding-left': '10px',
        })
Example #2
0
    def test_from_string(self):
        properties = Properties.from_string('color: red; font-weight: bold')
        self.assertEqual(properties, {
            'color': 'red',
            'font-weight': 'bold',
        })

        properties = Properties.from_string('padding: 0 10px')
        self.assertEqual(
            properties, {
                'padding-top': '0',
                'padding-right': '10px',
                'padding-bottom': '0',
                'padding-left': '10px',
            })
Example #3
0
    def test_does_not_override_inlined_styles(self):
        tree = html.document_fromstring("""
            <html>
            <head>
                <style type="text/css">
                    h1 {
                        color: red;
                        display: block;
                    }
                </style>
            </head>
            <body>
                <h1 style="color: blue; font-weight: bold">Hello, world.</h1>
            </body>
            </html>
        """)

        inline(tree)

        heading, = tree.cssselect('h1')
        properties = Properties.from_string(heading.attrib['style'])
        self.assertEqual(properties, {
            'color': 'blue',
            'display': 'block',
            'font-weight': 'bold',
        })
Example #4
0
    def test_does_not_override_inlined_styles(self):
        tree = html.document_fromstring("""
            <html>
            <head>
                <style type="text/css">
                    h1 {
                        color: red;
                        display: block;
                    }
                </style>
            </head>
            <body>
                <h1 style="color: blue; font-weight: bold">Hello, world.</h1>
            </body>
            </html>
        """)

        inline(tree)

        heading, = tree.cssselect('h1')
        properties = Properties.from_string(heading.attrib['style'])
        self.assertEqual(properties, {
            'color': 'blue',
            'display': 'block',
            'font-weight': 'bold',
        })
Example #5
0
 def test_from_string_cleans_whitespace(self):
     properties = Properties.from_string(
         'color : red;\nfont-weight: bold ;')
     self.assertEqual(properties, {
         'color': 'red',
         'font-weight': 'bold',
     })
Example #6
0
    def test_compresses_shorthand_properties(self):
        properties = Properties({
            'margin-top': '10px',
            'margin-right': '10px',
            'margin-bottom': '10px',
            'margin-left': '10px',
        })

        assert '%s' % (properties, ) == 'margin: 10px'
Example #7
0
    def test_serializes_to_attribute_string(self):
        properties = Properties({
            'font-weight': 'bold',
            'color': 'red',
        })

        # XXX: Ordering is non-deterministic, so we have to check both variations.
        expected = set((
            'font-weight: bold; color: red',
            'color: red; font-weight: bold',
        ))

        self.assertIn(u'%s' % (properties, ), expected)
Example #8
0
 def test_from_string_cleans_whitespace(self):
     properties = Properties.from_string('color : red;\nfont-weight: bold ;')
     self.assertEqual(properties, {
         'color': 'red',
         'font-weight': 'bold',
     })
Example #9
0
 def test_from_string(self):
     properties = Properties.from_string('color: red; font-weight: bold')
     self.assertEqual(properties, {
         'color': 'red',
         'font-weight': 'bold',
     })
Example #10
0
 def test_from_string(self):
     properties = Properties.from_string('color: red; font-weight: bold')
     self.assertEqual(properties, {
         'color': 'red',
         'font-weight': 'bold',
     })