1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
# -*- coding: iso-8859-1 -*-
"""Testcases for css_parser.stylesheets.MediaQuery"""
from __future__ import absolute_import
from __future__ import unicode_literals
import xml.dom
import logging
from . import basetest
import css_parser.stylesheets
class MediaQueryTestCase(basetest.BaseTestCase):
def setUp(self):
super(MediaQueryTestCase, self).setUp()
self.r = css_parser.stylesheets.MediaQuery()
def test_mediaText(self):
"MediaQuery.mediaText"
tests = {
'all': None,
'braille': None,
'embossed': None,
'handheld': None,
'print': None,
'projection': None,
'screen': None,
'speech': None,
'tty': None,
'tv': None,
'ALL': None,
'a\\ll': None,
'not tv': None,
'n\\ot t\\v': None,
'only tv': None,
'\\only \\tv': None,
'PRINT': None,
'NOT PRINT': None,
'ONLY PRINT': None,
'tv and (color)': None,
'not tv and (color)': None,
'only tv and (color)': None,
'print and(color)': 'print and (color)',
'aural': None # xml.dom.SyntaxErr in cssutils
}
self.do_equal_r(tests, att='mediaText')
tests = {
'': xml.dom.SyntaxErr,
'two values': xml.dom.SyntaxErr,
'or even three': xml.dom.SyntaxErr,
'3d': xml.dom.SyntaxErr, # a dimension
}
self.do_raise_r(tests, att='_setMediaText')
def test_mediaType(self):
"MediaQuery.mediaType"
mq = css_parser.stylesheets.MediaQuery()
self.assertEqual('', mq.mediaText)
for mt in css_parser.stylesheets.MediaQuery.MEDIA_TYPES:
mq.mediaType = mt
self.assertEqual(mq.mediaType, mt)
mq.mediaType = mt.upper()
self.assertEqual(mq.mediaType, mt.upper())
mt = '3D-UNKOwn-MEDIAtype0123'
#mq.mediaType = mt
self.assertEqual(self.captureLog(logging.WARNING, mq._setMediaType, mt),
'WARNING MediaQuery: Unknown media type: "3D-UNKOwn-MEDIAtype0123".\n')
#self.assertRaises(xml.dom.InvalidCharacterErr, mq._setMediaType, mt)
def test_comments(self):
"MediaQuery.mediaText comments"
tests = {
'all': None,
'print': None,
'not print': None,
'only print': None,
'print and (color)': None,
'print and (color) and (width)': None,
'print and (color: 2)': None,
'print and (min-width: 100px)': None,
'print and (min-width: 100px) and (color: red)': None,
'not print and (min-width: 100px)': None,
'only print and (min-width: 100px)': None,
'/*1*/ tv /*2*/': None,
'/*0*/ only /*1*/ tv /*2*/': None,
'/*0* /not /*1*/ tv /*2*/': None,
'/*x*/ only /*x*/ print /*x*/ and /*x*/ (/*x*/ min-width /*x*/: /*x*/ 100px /*x*/)': None,
'print and/*1*/(color)': 'print and /*1*/ (color)'
}
self.do_equal_r(tests, att='mediaText')
def test_reprANDstr(self):
"MediaQuery.__repr__(), .__str__()"
mediaText = 'tv and (color)'
s = css_parser.stylesheets.MediaQuery(mediaText=mediaText)
self.assertIn(mediaText, str(s))
s2 = eval(repr(s))
self.assertEqual(mediaText, s2.mediaText)
self.assertIsInstance(s2, s.__class__)
if __name__ == '__main__':
import unittest
unittest.main()
|