Esempio n. 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',
        })
Esempio n. 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',
            })
Esempio n. 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',
        })
Esempio n. 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',
        })
Esempio n. 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',
     })
Esempio n. 6
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',
     })
Esempio n. 7
0
 def test_from_string(self):
     properties = Properties.from_string('color: red; font-weight: bold')
     self.assertEqual(properties, {
         'color': 'red',
         'font-weight': 'bold',
     })
Esempio n. 8
0
 def test_from_string(self):
     properties = Properties.from_string('color: red; font-weight: bold')
     self.assertEqual(properties, {
         'color': 'red',
         'font-weight': 'bold',
     })