-
-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
7828580
commit 3bf6503
Showing
2 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from unittest import TestCase | ||
|
||
from xhtml2pdf.w3c.css import CSSBuilder, CSSParser | ||
|
||
|
||
class CssMediaRuleTest(TestCase): | ||
""" | ||
Test cases for the css @media rule (https://www.w3.org/TR/css3-mediaqueries/) | ||
""" | ||
|
||
def setUp(self): | ||
""" | ||
Setup css parser for all test cases | ||
""" | ||
self.parser = CSSParser(CSSBuilder(mediumSet=["all"])) | ||
|
||
def test_media_all(self): | ||
""" | ||
Test if the rule "@media all {" works | ||
""" | ||
|
||
media_all = """ | ||
@media all { | ||
p { color: yellow; } | ||
} | ||
""" | ||
|
||
selector_media_all = self.parser.parse(media_all)[0] | ||
css_media_all = self._get_first_dict_value(selector_media_all) | ||
|
||
self.assertDictEqual(css_media_all, {"color": "yellow"}) | ||
|
||
def test_media_all_and(self): | ||
""" | ||
Test if the rule "@media all and (...) {" works | ||
""" | ||
|
||
media_all_and = """ | ||
@media all and (max-width: 500px) { | ||
p { color: yellow; } | ||
} | ||
""" | ||
|
||
selector_media_all_and = self.parser.parse(media_all_and)[0] | ||
css_media_all_and = self._get_first_dict_value(selector_media_all_and) | ||
|
||
self.assertDictEqual(css_media_all_and, {"color": "yellow"}) | ||
|
||
def test_media_all_default(self): | ||
""" | ||
Test if the rule "@media (...) {" works (no media type defaults to "all") | ||
""" | ||
|
||
media_all_default = """ | ||
@media (max-width: 500px) { | ||
p { color: yellow; } | ||
} | ||
""" | ||
|
||
selector_media_all_default = self.parser.parse(media_all_default)[0] | ||
css_media_all_default = self._get_first_dict_value(selector_media_all_default) | ||
|
||
self.assertDictEqual(css_media_all_default, {"color": "yellow"}) | ||
|
||
@staticmethod | ||
def _get_first_dict_value(dictionary): | ||
return dictionary[list(dictionary.keys())[0]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters