コード例 #1
0
ファイル: test_css_parser.py プロジェクト: 284928489/zulip
 def test_empty_block(self) -> None:
     my_css = '''
         div {
         }'''
     error = 'Empty declaration'
     with self.assertRaisesRegex(CssParserException, error):
         parse(my_css)
コード例 #2
0
 def test_empty_block(self) -> None:
     my_css = '''
         div {
         }'''
     error = 'Empty declaration'
     with self.assertRaisesRegex(CssParserException, error):
         parse(my_css)
コード例 #3
0
 def test_multi_line_selector(self) -> None:
     my_css = '''
         h1,
         h2,
         h3 {
             top: 0
         }'''
     res = parse(my_css)
     section = res.sections[0]
     selectors = section.selector_list.selectors
     self.assertEqual(len(selectors), 3)
コード例 #4
0
ファイル: test_css_parser.py プロジェクト: 284928489/zulip
 def test_media_block(self) -> None:
     my_css = '''
         @media (max-width: 300px) {
             h5 {
                 margin: 0;
             }
         }'''
     res = parse(my_css)
     self.assertEqual(len(res.sections), 1)
     expected = '@media (max-width: 300px) {\n    h5 {\n        margin: 0;\n    }\n}'
     self.assertEqual(res.text().strip(), expected)
コード例 #5
0
ファイル: test_css_parser.py プロジェクト: 284928489/zulip
 def test_multi_line_selector(self) -> None:
     my_css = '''
         h1,
         h2,
         h3 {
             top: 0
         }'''
     res = parse(my_css)
     section = res.sections[0]
     selectors = section.selector_list.selectors
     self.assertEqual(len(selectors), 3)
コード例 #6
0
 def test_media_block(self) -> None:
     my_css = '''
         @media (max-width: 300px) {
             h5 {
                 margin: 0;
             }
         }'''
     res = parse(my_css)
     self.assertEqual(len(res.sections), 1)
     expected = '@media (max-width: 300px) {\n    h5 {\n        margin: 0;\n    }\n}'
     self.assertEqual(res.text().strip(), expected)
コード例 #7
0
ファイル: test_css_parser.py プロジェクト: tobby2002/zulip
 def test_media_block(self):
     # type: () -> None
     my_css = '''
         @media (max-width: 300px) {
             h5 {
                 margin: 0;
             }
         }'''
     res = parse(my_css)
     self.assertEqual(len(res.sections), 1)
     self.assertEqual(res.text(), my_css)
コード例 #8
0
 def test_same_line_comment(self) -> None:
     my_css = '''
         li.hide {
             display: none; /* comment here */
             /* Not to be confused
                with this comment */
             color: green;
         }'''
     res = parse(my_css)
     section = cast(CssSection, res.sections[0])
     block = section.declaration_block
     declaration = block.declarations[0]
     self.assertIn('/* comment here */', declaration.text())
コード例 #9
0
ファイル: test_css_parser.py プロジェクト: 284928489/zulip
 def test_same_line_comment(self) -> None:
     my_css = '''
         li.hide {
             display: none; /* comment here */
             /* Not to be confused
                with this comment */
             color: green;
         }'''
     res = parse(my_css)
     section = cast(CssSection, res.sections[0])
     block = section.declaration_block
     declaration = block.declarations[0]
     self.assertIn('/* comment here */', declaration.text())
コード例 #10
0
ファイル: test_css_parser.py プロジェクト: tobby2002/zulip
    def test_no_semicolon(self):
        # type: () -> None
        my_css = '''
            p { color: red }
        '''

        res = parse(my_css)

        self.assertEqual(res.text(), my_css)

        section = cast(CssSection, res.sections[0])

        self.assertFalse(section.declaration_block.declarations[0].semicolon)
コード例 #11
0
ファイル: test_css_parser.py プロジェクト: 284928489/zulip
    def test_no_semicolon(self) -> None:
        my_css = '''
            p { color: red }
        '''

        reformatted_css = 'p {\n    color: red;\n}'

        res = parse(my_css)

        self.assertEqual(res.text().strip(), reformatted_css)

        section = cast(CssSection, res.sections[0])

        self.assertFalse(section.declaration_block.declarations[0].semicolon)
コード例 #12
0
ファイル: test_css_parser.py プロジェクト: 284928489/zulip
 def test_basic_parse(self) -> None:
     my_selector = 'li.foo'
     my_block = '''{
             color: red;
         }'''
     my_css = my_selector + ' ' + my_block
     res = parse(my_css)
     self.assertEqual(res.text().strip(), 'li.foo {\n    color: red;\n}')
     section = cast(CssSection, res.sections[0])
     block = section.declaration_block
     self.assertEqual(block.text().strip(), '{\n    color: red;\n}')
     declaration = block.declarations[0]
     self.assertEqual(declaration.css_property, 'color')
     self.assertEqual(declaration.css_value.text().strip(), 'red')
コード例 #13
0
 def test_media_block(self):
     # type: () -> None
     my_css = '''
         @media (max-width: 300px) {
             h5 {
                 margin: 0;
             }
         }'''
     res = parse(my_css)
     self.assertEqual(len(res.sections), 1)
     self.assertEqual(
         res.text(),
         '\n            @media (max-width: 300px) {\n    h5 {\n        margin: 0;\n    }\n}'
     )
コード例 #14
0
    def test_no_semicolon(self) -> None:
        my_css = '''
            p { color: red }
        '''

        reformatted_css = 'p {\n    color: red;\n}'

        res = parse(my_css)

        self.assertEqual(res.text().strip(), reformatted_css)

        section = cast(CssSection, res.sections[0])

        self.assertFalse(section.declaration_block.declarations[0].semicolon)
コード例 #15
0
 def test_basic_parse(self) -> None:
     my_selector = 'li.foo'
     my_block = '''{
             color: red;
         }'''
     my_css = my_selector + ' ' + my_block
     res = parse(my_css)
     self.assertEqual(res.text().strip(), 'li.foo {\n    color: red;\n}')
     section = cast(CssSection, res.sections[0])
     block = section.declaration_block
     self.assertEqual(block.text().strip(), '{\n    color: red;\n}')
     declaration = block.declarations[0]
     self.assertEqual(declaration.css_property, 'color')
     self.assertEqual(declaration.css_value.text().strip(), 'red')
コード例 #16
0
    def test_comment_at_end(self):
        # type: () -> None
        '''
        This test verifies the current behavior, which is to
        attach comments to the preceding rule, but we should
        probably change it so the comments gets attached to
        the next block, if possible.
        '''
        my_css = '''
            p {
                color: black;
            }

            /* comment at the end of the text */
            '''
        res = parse(my_css)
        self.assertEqual(len(res.sections), 1)
        section = res.sections[0]
        self.assertIn('comment at the end', section.post_fluff)
コード例 #17
0
ファイル: test_css_parser.py プロジェクト: tobby2002/zulip
    def test_comment_at_end(self):
        # type: () -> None
        '''
        This test verifies the current behavior, which is to
        attach comments to the preceding rule, but we should
        probably change it so the comments gets attached to
        the next block, if possible.
        '''
        my_css = '''
            p {
                color: black;
            }

            /* comment at the end of the text */
            '''
        res = parse(my_css)
        self.assertEqual(len(res.sections), 1)
        section = res.sections[0]
        self.assertIn('comment at the end', section.post_fluff)
コード例 #18
0
 def _assert_error(self, my_css, error):
     # type: (str, str) -> None
     with self.assertRaisesRegex(CssParserException, error):
         parse(my_css)
コード例 #19
0
ファイル: test_css_parser.py プロジェクト: 284928489/zulip
 def _assert_error(self, my_css: str, error: str) -> None:
     with self.assertRaisesRegex(CssParserException, error):
         parse(my_css)
コード例 #20
0
ファイル: test_css_parser.py プロジェクト: joydeep1701/zulip
 def _assert_error(self, my_css, error):
     # type: (str, str) -> None
     with self.assertRaisesRegex(CssParserException, error):
         parse(my_css)
コード例 #21
0
ファイル: test_css_parser.py プロジェクト: tobby2002/zulip
 def _assert_error(self, my_css, error):
     # type: (str, str) -> None
     with self.assertRaisesRegexp(CssParserException, error): # type: ignore # See https://github.com/python/typeshed/issues/372
         parse(my_css)
コード例 #22
0
 def _assert_error(self, my_css: str, error: str) -> None:
     with self.assertRaisesRegex(CssParserException, error):
         parse(my_css)