app-validator/tests/test_markup_csstester.py

47 строки
1.1 KiB
Python
Исходник Обычный вид История

2012-08-02 02:43:36 +04:00
import appvalidator.testcases.markup.csstester as csstester
from appvalidator.errorbundle import ErrorBundle
2012-08-02 02:43:36 +04:00
2010-06-16 22:03:31 +04:00
def _do_test(path, should_fail=False):
2011-05-19 11:21:26 +04:00
data = open(path).read()
err = ErrorBundle()
csstester.test_css_file(err, "css.css", data)
2010-08-19 01:03:51 +04:00
err.print_summary(True)
2011-05-19 11:21:26 +04:00
2010-06-16 22:03:31 +04:00
if should_fail:
assert err.failed()
else:
assert not err.failed()
2011-05-19 11:21:26 +04:00
2010-08-19 01:03:51 +04:00
return err
2010-06-16 22:03:31 +04:00
2011-05-19 11:21:26 +04:00
2010-06-16 22:03:31 +04:00
def test_css_file():
"Tests a package with a valid CSS file."
2011-05-19 11:21:26 +04:00
2010-06-16 22:03:31 +04:00
_do_test("tests/resources/markup/csstester/pass.css")
2011-05-19 11:21:26 +04:00
def test_remote_urls():
"Tests the Regex used to detect remote URLs"
t = lambda s:csstester.BAD_URL.match(s) is not None
assert not t("url(foo/bar.abc)")
assert not t('url("foo/bar.abc")')
assert not t("url('foo/bar.abc')")
assert not t("url(chrome://foo/bar)")
assert not t("url(resource:asdf)")
assert t("url(http://abc.def)")
assert t("url(https://abc.def)")
assert t("url(ftp://abc.def)")
assert t("url(//abcdef)")
assert not t("url(/abc.def)")
assert not t("UrL(/abc.def)")
assert t("url(HTTP://foo.bar/)")