Example #1
0
    def test_render(self):
        css = Css(self.css_dict)
        rendered_css = css.render()
        expected_counter = Counter(
            '<style> {} html { background-color: lightblue; } h1 { color: white; text-align: center; } </style>'
        )
        # We count chars occurrence 'cause in python < 3.6 kwargs is not an OrderedDict'
        self.assertEqual(Counter(rendered_css), expected_counter)

        link = A()
        link_with_id = A(id='ex_a')
        link_with_class = A(klass='cl_a')
        css_complex = Css({
            'html': {
                'body': {
                    'color': 'red',
                    Div: {
                        'color': 'green',
                        'border': '1px'
                    },
                    link: {
                        'color': 'grey'
                    },
                    link_with_class: {
                        'color': 'grey'
                    },
                    A: {
                        'color': 'blue'
                    }
                }
            },
            '#myid': {
                'color': 'purple'
            },
            link_with_id: {
                'color': 'grey'
            },
            'td, tr': {
                'color': 'pink'
            }
        })
        rendered_css = css_complex.render()
        expected_css = '<style>{ } html { } #myid { color: purple; } #ex_a { color: grey; }' \
                       ' td, tr { color: pink; } html body { color: red; } ' \
                       'html body div { color: green; border: 1px; } html body #89602992 { color: grey; }' \
                       ' html body .cl_a { color: grey; } html body a { color: yellow; } </style>'
        expected_counter = Counter(x for x in expected_css if not x.isdigit())
        self.assertEqual(Counter(x for x in rendered_css if not x.isdigit()),
                         expected_counter)
Example #2
0
 def test_function_content(self):
     css = Css({'h1': {'color': lambda: 'TEST'}})
     self.assertTrue('TEST' in css.render())
Example #3
0
 def test_render(self):
     expected = '<style>html { background-color: lightblue; } h1 { color: white; text-align: center; } </style>'
     css = Css(self.css_dict)
     rendered_css = css.render()
     # We count chars occurrence 'cause in python < 3.6 kwargs is not an OrderedDict'
     self.assertEqual(Counter(rendered_css), Counter(expected))