Major test cleanup
This commit is contained in:
Родитель
da7698c397
Коммит
06a80114da
|
@ -1,22 +1,11 @@
|
|||
import os
|
||||
import validator.testcases.scripting
|
||||
from js_helper import _do_test
|
||||
|
||||
def _do_test(path):
|
||||
"Performs a test on a JS file"
|
||||
|
||||
script = open(path).read()
|
||||
|
||||
err = validator.testcases.scripting.traverser.MockBundler()
|
||||
validator.testcases.scripting.test_js_file(err, path, script)
|
||||
|
||||
return err
|
||||
|
||||
def test_redefinition():
|
||||
"Tests that global objects can't be redefined"
|
||||
|
||||
"""Test that global objects can't be redefined."""
|
||||
|
||||
err = _do_test("tests/resources/bug_538016.js")
|
||||
# There should be eight errors.
|
||||
print err.message_count
|
||||
assert err.message_count == 8
|
||||
|
||||
|
||||
|
|
|
@ -1,17 +1,8 @@
|
|||
import os
|
||||
import validator.testcases.scripting
|
||||
from js_helper import _do_test
|
||||
|
||||
def _do_test(path):
|
||||
"Performs a test on a JS file"
|
||||
script = open(path).read()
|
||||
|
||||
err = validator.testcases.scripting.traverser.MockBundler()
|
||||
validator.testcases.scripting.test_js_file(err, path, script)
|
||||
|
||||
return err
|
||||
|
||||
def test_double_escaped():
|
||||
"Tests that escaped characters don't result in errors"
|
||||
"""Test that escaped characters don't result in errors."""
|
||||
|
||||
err = _do_test("tests/resources/bug_626878.js")
|
||||
assert not err.message_count
|
||||
|
|
|
@ -1,52 +1,56 @@
|
|||
from validator.chromemanifest import ChromeManifest
|
||||
|
||||
|
||||
def test_open():
|
||||
"Open a chrome file and ensure that data can be pulled from it."
|
||||
"""Open a chrome file and ensure that data can be pulled from it."""
|
||||
|
||||
chrome = open("tests/resources/chromemanifest/chrome.manifest")
|
||||
chrome_data = chrome.read()
|
||||
|
||||
manifest = ChromeManifest(chrome_data)
|
||||
assert manifest is not None
|
||||
|
||||
|
||||
assert manifest.get_value("locale", "basta")["object"] == "resource"
|
||||
|
||||
|
||||
g_obj = list(manifest.get_objects("subject", "predicate"))
|
||||
|
||||
|
||||
assert len(g_obj) == 1
|
||||
assert g_obj[0] == "object"
|
||||
|
||||
|
||||
obj_resource = list(manifest.get_triples(None, None, "resource"))
|
||||
assert len(obj_resource) == 2
|
||||
|
||||
|
||||
pred_pred = list(manifest.get_triples(None, "predicate", None))
|
||||
assert len(pred_pred) == 2
|
||||
|
||||
|
||||
sub_locale = list(manifest.get_triples("locale", None, None))
|
||||
assert len(sub_locale) == 2
|
||||
|
||||
|
||||
def test_lines():
|
||||
"Tests that the correct line numbers are given in a chrome.manifest"
|
||||
"""Test that the correct line numbers are given in a chrome.manifest."""
|
||||
|
||||
c = ChromeManifest("""zero foo bar
|
||||
one bar foo
|
||||
two abc def
|
||||
#comment
|
||||
four def abc""")
|
||||
|
||||
|
||||
assert list(c.get_triples(subject="zero"))[0]["line"] == 1
|
||||
assert list(c.get_triples(subject="one"))[0]["line"] == 2
|
||||
assert list(c.get_triples(subject="two"))[0]["line"] == 3
|
||||
assert list(c.get_triples(subject="four"))[0]["line"] == 5
|
||||
|
||||
|
||||
def test_incomplete_triplets():
|
||||
"Tests that incomplete triplets are ignored"
|
||||
"""Test that incomplete triplets are ignored."""
|
||||
|
||||
c = ChromeManifest("foo\nbar")
|
||||
assert not c.triples
|
||||
|
||||
|
||||
def test_duplicate_subjects():
|
||||
"Tests that two triplets with the same subject can be retrieved"
|
||||
"""Test that two triplets with the same subject can be retrieved."""
|
||||
|
||||
c = ChromeManifest("""
|
||||
foo bar abc
|
||||
|
|
|
@ -2,8 +2,10 @@ import validator.testcases.chromemanifest as tc_chromemanifest
|
|||
from validator.errorbundler import ErrorBundle
|
||||
from validator.chromemanifest import ChromeManifest
|
||||
|
||||
|
||||
def test_pass():
|
||||
"Tests that standard category subjects pass"
|
||||
"""Test that standard category subjects pass."""
|
||||
|
||||
c = ChromeManifest("category foo bar")
|
||||
err = ErrorBundle()
|
||||
err.save_resource("chrome.manifest", c)
|
||||
|
@ -11,14 +13,18 @@ def test_pass():
|
|||
tc_chromemanifest.test_categories(err)
|
||||
assert not err.failed()
|
||||
|
||||
|
||||
def test_no_chromemanifest():
|
||||
"Chrome manifest tests should not be run if there is no chrome manifest"
|
||||
"""
|
||||
Chrome manifest tests should not be run if there is no chrome manifest.
|
||||
"""
|
||||
err = ErrorBundle()
|
||||
assert tc_chromemanifest.test_categories(err) is None
|
||||
assert not err.failed()
|
||||
|
||||
|
||||
def test_js_categories_gecko2():
|
||||
"Tests that JS categories raise problems for hyphenated values"
|
||||
"""Test that JS categories raise problems for hyphenated values."""
|
||||
c = ChromeManifest("category JavaScript-DOM-class foo bar")
|
||||
err = ErrorBundle()
|
||||
err.save_resource("chrome.manifest", c)
|
||||
|
@ -26,8 +32,9 @@ def test_js_categories_gecko2():
|
|||
tc_chromemanifest.test_categories(err)
|
||||
assert err.failed()
|
||||
|
||||
|
||||
def test_js_categories_gecko1():
|
||||
"Tests that JS categories raise problems for space-delimited values"
|
||||
"""Test that JS categories raise problems for space-delimited values."""
|
||||
c = ChromeManifest("category JavaScript global foo bar")
|
||||
err = ErrorBundle()
|
||||
err.save_resource("chrome.manifest", c)
|
||||
|
@ -35,6 +42,7 @@ def test_js_categories_gecko1():
|
|||
tc_chromemanifest.test_categories(err)
|
||||
assert err.failed()
|
||||
|
||||
|
||||
def test_fail_resourcemodules():
|
||||
"""'resource modules' should fail validation."""
|
||||
c = ChromeManifest("resource modules foo")
|
||||
|
|
|
@ -3,6 +3,7 @@ import validator.testcases.compatibility as compatibility
|
|||
import validator.testcases.scripting as scripting
|
||||
from validator.errorbundler import ErrorBundle
|
||||
|
||||
|
||||
def test_compat_test():
|
||||
"""Test that basic compatibility is supported"""
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import os
|
||||
|
||||
import validator.decorator as decorator
|
||||
import validator.testcases as testcases
|
||||
import validator.testcases.conduit as conduit
|
||||
|
@ -9,9 +7,10 @@ from validator.rdf import RDFParser
|
|||
from helper import _do_test
|
||||
from validator.constants import *
|
||||
|
||||
|
||||
def test_invalid_package_type():
|
||||
"No such thing as a Conduit theme."
|
||||
|
||||
"""Assert that conduit toolbars can only be extensions."""
|
||||
|
||||
err = ErrorBundle(None, True)
|
||||
err.detected_type = PACKAGE_ANY
|
||||
assert conduit.test_conduittoolbar(err) is None
|
||||
|
@ -19,62 +18,76 @@ def test_invalid_package_type():
|
|||
assert conduit.test_conduittoolbar(err) is None
|
||||
err.detected_type = PACKAGE_SEARCHPROV
|
||||
assert conduit.test_conduittoolbar(err) is None
|
||||
|
||||
|
||||
|
||||
def test_outright():
|
||||
"Tests the Conduit detector against an outright toolbar."
|
||||
|
||||
"""Test the Conduit detector against an outright toolbar."""
|
||||
|
||||
_do_test("tests/resources/conduit/basta_bar.xpi",
|
||||
conduit.test_conduittoolbar,
|
||||
failure=True,
|
||||
require_install=True,
|
||||
set_type=PACKAGE_EXTENSION)
|
||||
|
||||
|
||||
|
||||
def test_white():
|
||||
"Tests a non-Conduit addon against the library."
|
||||
|
||||
"""Test a non-Conduit addon against the library."""
|
||||
|
||||
_do_test("tests/resources/conduit/pass.xpi",
|
||||
conduit.test_conduittoolbar,
|
||||
failure=False,
|
||||
require_install=True,
|
||||
set_type=PACKAGE_EXTENSION)
|
||||
|
||||
|
||||
|
||||
def test_params():
|
||||
"""Tests the Conduit detector against a toolbar with parameters in
|
||||
the install.rdf file that indiciate Conduit-ion."""
|
||||
|
||||
"""
|
||||
Tests the Conduit detector against a toolbar with parameters in the
|
||||
install.rdf file that indiciate Conduit-ion.
|
||||
"""
|
||||
|
||||
_do_test("tests/resources/conduit/conduit_params.xpi",
|
||||
conduit.test_conduittoolbar,
|
||||
failure=True,
|
||||
require_install=True,
|
||||
set_type=PACKAGE_EXTENSION)
|
||||
|
||||
|
||||
|
||||
def test_updateurl():
|
||||
"""Tests the Conduit detector against a toolbar with its updateURL
|
||||
parameter set to that of a Conduit Toolbar's."""
|
||||
|
||||
"""
|
||||
Test the Conduit detector against a toolbar with its updateURL parameter
|
||||
set to that of a Conduit Toolbar's.
|
||||
"""
|
||||
|
||||
_do_test("tests/resources/conduit/conduit_updateurl.xpi",
|
||||
conduit.test_conduittoolbar,
|
||||
failure=True,
|
||||
require_install=True,
|
||||
set_type=PACKAGE_EXTENSION)
|
||||
|
||||
|
||||
|
||||
def test_structure():
|
||||
"""Tests the Conduit detector against a toolbar with files and
|
||||
folders which resemble those of a Conduit toolbar."""
|
||||
|
||||
"""
|
||||
Test the Conduit detector against a toolbar with files and folders which
|
||||
resemble those of a Conduit toolbar.
|
||||
"""
|
||||
|
||||
_do_test("tests/resources/conduit/conduit_structure.xpi",
|
||||
conduit.test_conduittoolbar,
|
||||
failure=True,
|
||||
require_install=True,
|
||||
set_type=PACKAGE_EXTENSION)
|
||||
|
||||
|
||||
|
||||
def test_chrome():
|
||||
"""Tests the Conduit detector against a toolbar with
|
||||
chrome.manifest entries that indicate a Conduit toolbar."""
|
||||
|
||||
"""
|
||||
Test the Conduit detector against a toolbar with chrome.manifest entries
|
||||
that indicate a Conduit toolbar.
|
||||
"""
|
||||
|
||||
_do_test("tests/resources/conduit/conduit_chrome.xpi",
|
||||
conduit.test_conduittoolbar,
|
||||
failure=True,
|
||||
require_install=True,
|
||||
set_type=PACKAGE_EXTENSION)
|
||||
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
import os
|
||||
from StringIO import StringIO
|
||||
|
||||
from js_helper import _do_test_raw
|
||||
|
||||
import validator.xpi as xpi
|
||||
import validator.testcases.content as content
|
||||
from validator.errorbundler import ErrorBundle
|
||||
from validator.chromemanifest import ChromeManifest
|
||||
from helper import _do_test
|
||||
from validator.constants import *
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import os
|
||||
from validator.contextgenerator import ContextGenerator
|
||||
|
||||
|
||||
def test_load_data():
|
||||
"Tests that data is loaded properly into the CG."
|
||||
"""Test that data is loaded properly into the CG."""
|
||||
|
||||
d = """abc
|
||||
def
|
||||
|
@ -16,8 +16,9 @@ def test_load_data():
|
|||
assert c.data[0].strip() == "abc"
|
||||
assert c.data[1].strip() == "def"
|
||||
|
||||
|
||||
def test_get_context():
|
||||
"Tests that contexts are generated properly."
|
||||
"""Test that contexts are generated properly."""
|
||||
|
||||
d = open("tests/resources/contextgenerator/data.txt").read()
|
||||
c = ContextGenerator(d)
|
||||
|
@ -32,7 +33,7 @@ def test_get_context():
|
|||
assert c_start[0] == None
|
||||
assert len(c_end) == 3
|
||||
assert c_end[2] == None
|
||||
|
||||
|
||||
assert c_start[1] == "0123456789"
|
||||
assert c_end[0] == "9012345678"
|
||||
assert c_end[1] == ""
|
||||
|
@ -42,9 +43,12 @@ def test_get_context():
|
|||
assert c_mid[0] == "3456789012"
|
||||
assert c_mid[2] == "5678901234"
|
||||
print c_mid
|
||||
|
||||
|
||||
|
||||
def test_get_context_trimming():
|
||||
"Tests that contexts are generated properly when lines are >140 characters"
|
||||
"""
|
||||
Test that contexts are generated properly when lines are >140 characters.
|
||||
"""
|
||||
|
||||
d = open("tests/resources/contextgenerator/longdata.txt").read()
|
||||
c = ContextGenerator(d)
|
||||
|
@ -58,9 +62,12 @@ def test_get_context_trimming():
|
|||
for i in range(3):
|
||||
assert len(trimmed[i]) == proper_lengths[i]
|
||||
|
||||
|
||||
def test_get_context_trimming_inverse():
|
||||
"""Tests that surrounding lines are trimmed properly; the error line is
|
||||
ignored if it is less than 140 characters."""
|
||||
"""
|
||||
Tests that surrounding lines are trimmed properly; the error line is
|
||||
ignored if it is less than 140 characters.
|
||||
"""
|
||||
|
||||
d = open("tests/resources/contextgenerator/longdata.txt").read()
|
||||
c = ContextGenerator(d)
|
||||
|
@ -73,13 +80,14 @@ def test_get_context_trimming_inverse():
|
|||
assert trimmed[0][0] != "X"
|
||||
assert trimmed[2][-1] != "X"
|
||||
|
||||
|
||||
def test_get_line():
|
||||
"Tests that the context generator returns the proper line"
|
||||
|
||||
"""Test that the context generator returns the proper line."""
|
||||
|
||||
d = open("tests/resources/contextgenerator/data.txt").read()
|
||||
c = ContextGenerator(d)
|
||||
print c.data
|
||||
|
||||
|
||||
print c.get_line(30)
|
||||
assert c.get_line(30) == 3
|
||||
print c.get_line(11)
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
import os
|
||||
|
||||
import validator.unicodehelper
|
||||
import validator.testcases.scripting
|
||||
|
||||
# Originated from bug 626496
|
||||
|
||||
# Originated from bug 626496
|
||||
def _do_test(path):
|
||||
"Performs a test on a JS file"
|
||||
script = validator.unicodehelper.decode(open(path, "rb").read())
|
||||
print script.encode("ascii", "replace")
|
||||
|
||||
|
@ -14,32 +11,39 @@ def _do_test(path):
|
|||
validator.testcases.scripting.test_js_file(err, path, script)
|
||||
|
||||
print err.ids
|
||||
|
||||
return err
|
||||
|
||||
|
||||
def test_controlchars_ascii_ok():
|
||||
"""Tests that multi-byte characters are decoded properly (utf-8)"""
|
||||
"""Test that multi-byte characters are decoded properly (utf-8)."""
|
||||
|
||||
errs = _do_test("tests/resources/controlchars/controlchars_ascii_ok.js")
|
||||
assert len(errs.ids) == 0
|
||||
|
||||
|
||||
def test_controlchars_ascii_warn():
|
||||
"""Tests that multi-byte characters are decoded properly (utf-8)
|
||||
but remaining non ascii characters raise warnings"""
|
||||
"""
|
||||
Test that multi-byte characters are decoded properly (utf-8) but remaining
|
||||
non ascii characters raise warnings.
|
||||
"""
|
||||
|
||||
errs = _do_test("tests/resources/controlchars/controlchars_ascii_warn.js")
|
||||
assert len(errs.ids) == 1
|
||||
assert errs.ids[0][2] == "syntax_error"
|
||||
|
||||
|
||||
def test_controlchars_utf8_ok():
|
||||
"""Tests that multi-byte characters are decoded properly (utf-8)"""
|
||||
"""Test that multi-byte characters are decoded properly (utf-8)."""
|
||||
|
||||
errs = _do_test("tests/resources/controlchars/controlchars_utf-8_ok.js")
|
||||
assert len(errs.ids) == 0
|
||||
|
||||
|
||||
def test_controlchars_utf8_warn():
|
||||
"""Tests that multi-byte characters are decoded properly (utf-8)
|
||||
but remaining non ascii characters raise warnings"""
|
||||
"""
|
||||
Tests that multi-byte characters are decoded properly (utf-8) but remaining
|
||||
non-ascii characters raise warnings.
|
||||
"""
|
||||
|
||||
errs = _do_test("tests/resources/controlchars/controlchars_utf-8_warn.js")
|
||||
assert len(errs.ids) == 1
|
||||
|
|
|
@ -1,51 +1,60 @@
|
|||
import validator.decorator as decorator
|
||||
|
||||
|
||||
def test_tiers():
|
||||
"""Tests to make sure that the decorator module is properly
|
||||
registering test functions."""
|
||||
|
||||
"""
|
||||
Tests to make sure that the decorator module is properly registering test
|
||||
functions.
|
||||
"""
|
||||
|
||||
dtt = decorator.TEST_TIERS
|
||||
decorator.TEST_TIERS = {}
|
||||
|
||||
|
||||
decorator.register_test(tier=1)(lambda: None)
|
||||
decorator.register_test(tier=2, expected_type=5)(lambda: None)
|
||||
decorator.register_test(tier=2)(lambda: None)
|
||||
decorator.register_test(tier=2, simple=True)(lambda: None)
|
||||
|
||||
|
||||
tiers = decorator.get_tiers()
|
||||
print tiers
|
||||
assert len(tiers) == 2
|
||||
decorator.TEST_TIERS = dtt
|
||||
|
||||
|
||||
|
||||
def test_specifictype():
|
||||
"""Tests to make sure that the decorator module can return a test
|
||||
of a specific type."""
|
||||
|
||||
"""
|
||||
Test to make sure that the decorator module can return a test of a
|
||||
specific type.
|
||||
"""
|
||||
|
||||
dtt = decorator.TEST_TIERS
|
||||
decorator.TEST_TIERS = {}
|
||||
|
||||
|
||||
decorator.register_test(tier=1)(lambda: None)
|
||||
decorator.register_test(tier=2, expected_type=5)(lambda: None)
|
||||
decorator.register_test(tier=2)(lambda: None)
|
||||
decorator.register_test(tier=2, simple=True)(lambda: None)
|
||||
|
||||
|
||||
tests = list(decorator.get_tests(2, 1))
|
||||
assert len(tests) == 2
|
||||
decorator.TEST_TIERS = dtt
|
||||
|
||||
|
||||
|
||||
def test_assumedtype():
|
||||
"""Tests to see if the decorator module can find tests for generic
|
||||
as well as specific types"""
|
||||
|
||||
"""
|
||||
Test to see if the decorator module can find tests for generic as well as
|
||||
specific types.
|
||||
"""
|
||||
|
||||
dtt = decorator.TEST_TIERS
|
||||
decorator.TEST_TIERS = {}
|
||||
|
||||
|
||||
decorator.register_test(tier=1)(lambda: None)
|
||||
decorator.register_test(tier=2, expected_type=5)(lambda: None)
|
||||
decorator.register_test(tier=2)(lambda: None)
|
||||
decorator.register_test(tier=2, simple=True)(lambda: None)
|
||||
|
||||
|
||||
tests = list(decorator.get_tests(2, 5))
|
||||
assert len(tests) == 3
|
||||
decorator.TEST_TIERS = dtt
|
||||
|
||||
|
||||
|
|
|
@ -7,8 +7,9 @@ import validator.errorbundler as errorbundler
|
|||
from validator.errorbundler import ErrorBundle
|
||||
from validator.contextgenerator import ContextGenerator
|
||||
|
||||
|
||||
def test_json():
|
||||
"Tests the JSON output capability of the error bundler."
|
||||
"""Test the JSON output capability of the error bundler."""
|
||||
|
||||
# Use the StringIO as an output buffer.
|
||||
bundle = ErrorBundle() # No color since no output
|
||||
|
@ -29,8 +30,9 @@ def test_json():
|
|||
assert not results["success"]
|
||||
assert results["ending_tier"] == 4
|
||||
|
||||
|
||||
def test_boring():
|
||||
"Tests that boring output strips out color sequences."
|
||||
"""Test that boring output strips out color sequences."""
|
||||
|
||||
stdout = sys.stdout
|
||||
sys.stdout = StringIO()
|
||||
|
@ -46,17 +48,20 @@ def test_boring():
|
|||
|
||||
assert outbuffer.getvalue().count("<<GREEN>>") == 0
|
||||
|
||||
|
||||
def test_type():
|
||||
"""Tests that detected type is being stored properly in the error
|
||||
bundle."""
|
||||
"""
|
||||
Test that detected type is being stored properly in the error bundle.
|
||||
"""
|
||||
|
||||
bundle = ErrorBundle()
|
||||
|
||||
bundle.set_type(5)
|
||||
assert bundle.detected_type == 5
|
||||
|
||||
|
||||
def test_states():
|
||||
"""Tests that detected type is preserved, even in subpackages."""
|
||||
"""Test that detected type is preserved, even in subpackages."""
|
||||
|
||||
# Use the StringIO as an output buffer.
|
||||
bundle = ErrorBundle()
|
||||
|
@ -121,8 +126,10 @@ def test_states():
|
|||
|
||||
|
||||
def test_file_structure():
|
||||
"""Tests the means by which file names and line numbers are stored
|
||||
in errors, warnings, and messages."""
|
||||
"""
|
||||
Test the means by which file names and line numbers are stored in errors,
|
||||
warnings, and messages.
|
||||
"""
|
||||
|
||||
# Use the StringIO as an output buffer.
|
||||
bundle = ErrorBundle(True) # No color since no output
|
||||
|
@ -184,7 +191,7 @@ def test_file_structure():
|
|||
|
||||
|
||||
def test_notice():
|
||||
"""Tests notice-related functions of the error bundler."""
|
||||
"""Test notice-related functions of the error bundler."""
|
||||
|
||||
# Use the StringIO as an output buffer.
|
||||
bundle = ErrorBundle()
|
||||
|
@ -213,8 +220,10 @@ def test_notice():
|
|||
|
||||
|
||||
def test_notice_friendly():
|
||||
"""Tests notice-related human-friendly text output functions of the
|
||||
error bundler."""
|
||||
"""
|
||||
Test notice-related human-friendly text output functions of the error
|
||||
bundler.
|
||||
"""
|
||||
|
||||
# Use the StringIO as an output buffer.
|
||||
bundle = ErrorBundle()
|
||||
|
@ -227,8 +236,9 @@ def test_notice_friendly():
|
|||
|
||||
assert output.count("foobar")
|
||||
|
||||
|
||||
def test_initializer():
|
||||
"Tests that the __init__ paramaters are doing their jobs"
|
||||
"""Test that the __init__ paramaters are doing their jobs."""
|
||||
|
||||
e = ErrorBundle()
|
||||
assert e.determined
|
||||
|
@ -242,8 +252,9 @@ def test_initializer():
|
|||
assert e.determined
|
||||
assert not e.get_resource("listed")
|
||||
|
||||
|
||||
def test_json_constructs():
|
||||
"This tests some of the internal JSON stuff so we don't break zamboni"
|
||||
"""This tests some of the internal JSON stuff so we don't break zamboni."""
|
||||
|
||||
e = ErrorBundle()
|
||||
e.set_type(1)
|
||||
|
@ -375,7 +386,9 @@ def test_json_compatibility():
|
|||
|
||||
|
||||
def test_pushable_resources():
|
||||
"Tests that normal resources are preserved but pushable ones are pushed"
|
||||
"""
|
||||
Test that normal resources are preserved but pushable ones are pushed.
|
||||
"""
|
||||
|
||||
e = ErrorBundle()
|
||||
e.save_resource("nopush", True)
|
||||
|
@ -400,7 +413,7 @@ def test_pushable_resources():
|
|||
|
||||
|
||||
def test_forappversions():
|
||||
"""Test that app version information is passed to the JSON"""
|
||||
"""Test that app version information is passed to the JSON."""
|
||||
|
||||
app_test_data = {"guid": ["version1", "version2"]}
|
||||
|
||||
|
|
|
@ -1,31 +1,38 @@
|
|||
import fastchardet
|
||||
|
||||
def test_ascii():
|
||||
"Determines that fastchardet detects ASCII properly"
|
||||
|
||||
def test_ascii():
|
||||
"""Determines that fastchardet detects ASCII properly."""
|
||||
assert fastchardet.detect("This is plain ASCII")["encoding"] == "ascii"
|
||||
|
||||
|
||||
def test_utf8():
|
||||
"Determines that fastchardet properly detects UTF-8"
|
||||
"""Determine that fastchardet properly detects UTF-8."""
|
||||
|
||||
assert fastchardet.detect("""\xEF\xBB\xBF
|
||||
Haldo, UTF-8
|
||||
""")["encoding"] == "utf_8"
|
||||
|
||||
|
||||
def test_utfn():
|
||||
"Determines that fastchardet properly detects UTF-N"
|
||||
"""Determine that fastchardet properly detects UTF-N."""
|
||||
|
||||
assert fastchardet.detect("""\xFF\xFE\x00\x00
|
||||
Haldo, UTF-Not 8
|
||||
""")["encoding"] == "utf_n"
|
||||
|
||||
|
||||
def test_unicode():
|
||||
"For when we're silly sallies and pass unicode in"
|
||||
"""
|
||||
Make sure that things turn out right when we're silly sallies and pass
|
||||
unicode in.
|
||||
"""
|
||||
|
||||
assert fastchardet.detect(unicode("foo"))["encoding"] == "unicode"
|
||||
|
||||
|
||||
def test_esoteric():
|
||||
"Makes sure that fastchardet can detect other encodings"
|
||||
"""Make sure that fastchardet can detect other encodings."""
|
||||
|
||||
a = lambda code: fastchardet.detect(code)["encoding"]
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import validator.testcases.installrdf as installrdf
|
||||
from validator.errorbundler import ErrorBundle
|
||||
from validator.rdf import RDFParser
|
||||
from helper import _do_test
|
||||
from validator.constants import *
|
||||
|
||||
|
||||
|
|
|
@ -3,9 +3,10 @@ from validator.errorbundler import ErrorBundle
|
|||
from helper import _do_test
|
||||
from validator.constants import *
|
||||
|
||||
|
||||
def test_pass():
|
||||
"Test a package with localization that should pass validation."
|
||||
|
||||
|
||||
l10n.LOCALE_CACHE = {}
|
||||
output = _do_test("tests/resources/l10n/pass.xpi",
|
||||
l10n.test_xpi,
|
||||
|
@ -13,9 +14,10 @@ def test_pass():
|
|||
set_type=PACKAGE_EXTENSION)
|
||||
assert not output.errors
|
||||
|
||||
|
||||
def test_unlocalizable():
|
||||
"Test a package without localization data."
|
||||
|
||||
|
||||
l10n.LOCALE_CACHE = {}
|
||||
output = _do_test("tests/resources/l10n/unlocalizable.xpi",
|
||||
l10n.test_xpi,
|
||||
|
@ -23,6 +25,7 @@ def test_unlocalizable():
|
|||
set_type=PACKAGE_EXTENSION)
|
||||
assert output.notices # Should alert about lack of locales
|
||||
|
||||
|
||||
def test_localizable():
|
||||
"Tests a package with minimal localization data."
|
||||
|
||||
|
@ -33,40 +36,42 @@ def test_localizable():
|
|||
set_type=PACKAGE_EXTENSION)
|
||||
assert not output.notices
|
||||
|
||||
|
||||
def test_missing():
|
||||
"Test a package with missing localization entities."
|
||||
|
||||
|
||||
l10n.LOCALE_CACHE = {}
|
||||
_do_test("tests/resources/l10n/l10n_incomplete.xpi",
|
||||
l10n.test_xpi,
|
||||
set_type=PACKAGE_EXTENSION)
|
||||
|
||||
|
||||
def test_missingfiles():
|
||||
"Test a package with missing localization files."
|
||||
|
||||
|
||||
l10n.LOCALE_CACHE = {}
|
||||
_do_test("tests/resources/l10n/l10n_missingfiles.xpi",
|
||||
l10n.test_xpi,
|
||||
set_type=PACKAGE_EXTENSION)
|
||||
|
||||
|
||||
def test_unmodified():
|
||||
"""Test a package containing localization entities that have been
|
||||
unmodified from the reference locale (en-US)"""
|
||||
|
||||
|
||||
l10n.LOCALE_CACHE = {}
|
||||
_do_test("tests/resources/l10n/l10n_unmodified.xpi",
|
||||
l10n.test_xpi,
|
||||
set_type=PACKAGE_EXTENSION)
|
||||
|
||||
|
||||
|
||||
def test_subpackage():
|
||||
"Test a package with localization that should pass validation."
|
||||
|
||||
|
||||
err = ErrorBundle()
|
||||
err.set_type(PACKAGE_DICTIONARY)
|
||||
assert l10n.test_xpi(err, {}, None) is None
|
||||
err.set_type(PACKAGE_EXTENSION)
|
||||
err.push_state()
|
||||
assert l10n.test_xpi(err, {}, None) is None
|
||||
|
||||
|
||||
|
|
|
@ -1,53 +1,50 @@
|
|||
import os
|
||||
|
||||
from StringIO import StringIO
|
||||
|
||||
import validator.testcases.l10n.dtd as dtd
|
||||
|
||||
|
||||
def test_passing_file():
|
||||
"Tests a valid DTD file by passing in a file path."
|
||||
|
||||
"""Test a valid DTD file by passing in a file path."""
|
||||
|
||||
path = "tests/resources/l10n/dtd/valid.dtd"
|
||||
parser = dtd.DTDParser(path)
|
||||
|
||||
|
||||
_inspect_file_results(parser)
|
||||
|
||||
|
||||
|
||||
def test_passing_stream():
|
||||
"Tests a valid DTD file by passing in a data stream."
|
||||
|
||||
"""Test a valid DTD file by passing in a data stream."""
|
||||
|
||||
path = "tests/resources/l10n/dtd/valid.dtd"
|
||||
file_ = open(path)
|
||||
data = file_.read()
|
||||
file_.close()
|
||||
parser = dtd.DTDParser(StringIO(data))
|
||||
|
||||
parser = dtd.DTDParser(open(path))
|
||||
_inspect_file_results(parser)
|
||||
|
||||
|
||||
|
||||
def test_shady_file():
|
||||
"""Tests a somewhat silly DTD file that has excessive line breaks.
|
||||
This emulates the mozilla.dtd file in the reference packs."""
|
||||
|
||||
"""
|
||||
Test a somewhat silly DTD file that has excessive line breaks. This
|
||||
emulates the mozilla.dtd file in the reference packs.
|
||||
"""
|
||||
|
||||
path = "tests/resources/l10n/dtd/extra_breaks.dtd"
|
||||
parser = dtd.DTDParser(path)
|
||||
|
||||
|
||||
_inspect_file_results(parser)
|
||||
|
||||
|
||||
|
||||
def test_broken_file():
|
||||
"""Tests a DTD file that has malformed content to make sure invalid
|
||||
tags are ignored. Also, non-ENTITY declarations should be
|
||||
ignored."""
|
||||
|
||||
"""
|
||||
Tests a DTD file that has malformed content to make sure invalid tags are
|
||||
ignored. Also, non-ENTITY declarations should be ignored.
|
||||
"""
|
||||
|
||||
path = "tests/resources/l10n/dtd/malformed.dtd"
|
||||
parser = dtd.DTDParser(path)
|
||||
|
||||
|
||||
_inspect_file_results(parser)
|
||||
|
||||
|
||||
|
||||
def _inspect_file_results(parser):
|
||||
"Inspects the output of the DTD file tests."
|
||||
|
||||
"""Inspect the output of the DTD file tests."""
|
||||
|
||||
assert len(parser) == 7
|
||||
assert "foo" in parser.entities
|
||||
assert parser.entities["foo"] == "bar"
|
||||
|
@ -57,4 +54,4 @@ def _inspect_file_results(parser):
|
|||
assert parser.entities["two"] == "per"
|
||||
assert "line" in parser.entities
|
||||
assert parser.entities["line"] == "woot"
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from StringIO import StringIO
|
||||
|
||||
from validator.errorbundler import ErrorBundle
|
||||
from validator.testcases.l10ncompleteness import _get_locale_manager, \
|
||||
_list_locales, \
|
||||
|
@ -102,14 +101,15 @@ def test_get_manager():
|
|||
l10ncomp.XPIManager = xm
|
||||
|
||||
|
||||
|
||||
|
||||
class MockManager(object):
|
||||
"Represents a fake XPIManager"
|
||||
|
||||
def __init__(self, default, path=None):
|
||||
if isinstance(default, StringIO):
|
||||
default = default.getvalue()
|
||||
elif isinstance(default, file):
|
||||
default = default.read()
|
||||
|
||||
self.value = default
|
||||
self.path = path
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ from validator.testcases.l10n.dtd import DTDParser
|
|||
from validator.testcases.l10n.properties import PropertiesParser
|
||||
from validator.xpi import XPIManager
|
||||
from validator.errorbundler import ErrorBundle
|
||||
from helper import _do_test
|
||||
from validator.constants import *
|
||||
|
||||
|
||||
def test_chromemanifest():
|
||||
"Make sure it only accepts packs with chrome.manifest files."
|
||||
|
||||
|
@ -28,7 +28,7 @@ def test_parse_l10n():
|
|||
def test_results_aggregator():
|
||||
"Tests that language pack aggregation results are read properly."
|
||||
|
||||
err = ErrorBundle(None, True)
|
||||
err = ErrorBundle()
|
||||
l10n._aggregate_results(err,
|
||||
[{"type":"missing_files",
|
||||
"filename":"foo.bar"}],
|
||||
|
@ -37,7 +37,7 @@ def test_results_aggregator():
|
|||
"jarred": False})
|
||||
assert err.failed()
|
||||
|
||||
err = ErrorBundle(None, True)
|
||||
err = ErrorBundle()
|
||||
l10n._aggregate_results(err,
|
||||
[{"type":"missing_entities",
|
||||
"filename":"foo.bar",
|
||||
|
@ -47,7 +47,7 @@ def test_results_aggregator():
|
|||
"jarred": False})
|
||||
assert err.failed()
|
||||
|
||||
err = ErrorBundle(None, True)
|
||||
err = ErrorBundle()
|
||||
l10n._aggregate_results(err,
|
||||
[{"type":"unchanged_entity",
|
||||
"entities":0,
|
||||
|
@ -60,7 +60,7 @@ def test_results_aggregator():
|
|||
"jarred": False})
|
||||
assert not err.failed()
|
||||
|
||||
err = ErrorBundle(None, True)
|
||||
err = ErrorBundle()
|
||||
l10n._aggregate_results(err,
|
||||
[{"type":"unchanged_entity",
|
||||
"entities":50,
|
||||
|
@ -107,6 +107,7 @@ def test_comparer():
|
|||
assert _compare_packs(ref, mfileent) == 3
|
||||
assert _compare_packs(ref, ref) > 3
|
||||
|
||||
|
||||
def _compare_packs(reference, target):
|
||||
"Does a simple comparison and prints the output"
|
||||
|
||||
|
|
|
@ -1,44 +1,40 @@
|
|||
import os
|
||||
|
||||
from StringIO import StringIO
|
||||
|
||||
import validator.testcases.l10n.properties as properties
|
||||
|
||||
|
||||
def test_passing_file():
|
||||
"Tests a valid properties file by passing in a file path."
|
||||
|
||||
"""Test a valid properties file by passing in a file path."""
|
||||
|
||||
path = "tests/resources/l10n/properties/valid.properties"
|
||||
parser = properties.PropertiesParser(path)
|
||||
|
||||
|
||||
_inspect_file_results(parser)
|
||||
|
||||
|
||||
|
||||
def test_passing_stream():
|
||||
"Tests a valid DTD file by passing in a data stream."
|
||||
|
||||
"""Test a valid DTD file by passing in a data stream."""
|
||||
|
||||
path = "tests/resources/l10n/properties/valid.properties"
|
||||
file_ = open(path)
|
||||
data = file_.read()
|
||||
file_.close()
|
||||
parser = properties.PropertiesParser(StringIO(data))
|
||||
|
||||
parser = properties.PropertiesParser(open(path))
|
||||
|
||||
_inspect_file_results(parser)
|
||||
|
||||
|
||||
|
||||
def test_malformed_file():
|
||||
"""Tests a properties file that contains non-comment,
|
||||
non-whitespace lines without a distinct value."""
|
||||
|
||||
"""
|
||||
Tests a properties file that contains non-comment, non-whitespace lines
|
||||
without a distinct value.
|
||||
"""
|
||||
|
||||
path = "tests/resources/l10n/properties/extra_breaks.properties"
|
||||
parser = properties.PropertiesParser(path)
|
||||
assert len(parser) == 2
|
||||
assert parser.entities["foo"] == "bar"
|
||||
assert parser.entities["abc.def"] == "xyz"
|
||||
|
||||
|
||||
|
||||
def _inspect_file_results(parser):
|
||||
"Inspects the output of the properties file tests."
|
||||
|
||||
"""Inspect the output of the properties file tests."""
|
||||
|
||||
assert len(parser) == 7
|
||||
assert "foo" in parser.entities
|
||||
assert parser.entities["foo"] == "bar"
|
||||
|
@ -48,4 +44,4 @@ def _inspect_file_results(parser):
|
|||
assert parser.entities["two"] == "per"
|
||||
assert "line" in parser.entities
|
||||
assert parser.entities["line"] == "woot"
|
||||
|
||||
|
||||
|
|
|
@ -1,64 +1,68 @@
|
|||
import validator.testcases as testcases
|
||||
import validator.testcases.langpack as langpack
|
||||
from validator.chromemanifest import ChromeManifest
|
||||
from validator.errorbundler import ErrorBundle
|
||||
from helper import _do_test
|
||||
|
||||
|
||||
def test_langpack_valid():
|
||||
"Tests that a language pack has a valid chrome manifest file."
|
||||
|
||||
|
||||
_do_test("tests/resources/langpack/pass.xpi",
|
||||
langpack.test_langpack_manifest,
|
||||
False)
|
||||
|
||||
|
||||
def test_langpack_bad_subject():
|
||||
"""Tests that a language pack has an invalid subject in the
|
||||
chrome.manifest file."""
|
||||
|
||||
|
||||
_do_test("tests/resources/langpack/fail.xpi",
|
||||
langpack.test_langpack_manifest)
|
||||
|
||||
|
||||
def test_langpack_bad_uri_pred():
|
||||
"""Tests that a language pack has an invalid URI specified for its
|
||||
'override' predicates."""
|
||||
|
||||
|
||||
_do_test("tests/resources/langpack/fail_uri_pred.xpi",
|
||||
langpack.test_langpack_manifest)
|
||||
|
||||
|
||||
def test_langpack_bad_uri_obj():
|
||||
"""Tests that a language pack has an invalid URI specified for its
|
||||
'override' objects."""
|
||||
|
||||
|
||||
_do_test("tests/resources/langpack/fail_uri_obj.xpi",
|
||||
langpack.test_langpack_manifest)
|
||||
|
||||
|
||||
def test_unsafe_html():
|
||||
"Tests for unsafe HTML in obstract files."
|
||||
|
||||
|
||||
err = ErrorBundle(None, True)
|
||||
|
||||
|
||||
langpack.test_unsafe_html(err, None, """
|
||||
This is an <b>innocent</b> file.
|
||||
Nothing to <a href="#anchor">suspect</a> here.
|
||||
<img src="chrome://asdf/locale/asdf" />
|
||||
<tag href="#" />""")
|
||||
|
||||
|
||||
langpack.test_unsafe_html(err, None, "<tag href='foo' />")
|
||||
|
||||
langpack.test_unsafe_html(err, None, "<tag src='foo' />")
|
||||
langpack.test_unsafe_html(err, None, "<tag src='/foo/bar' />")
|
||||
|
||||
assert not err.failed()
|
||||
|
||||
|
||||
langpack.test_unsafe_html(err, "asdf", """
|
||||
This is not an <script>innocent</script> file.""")
|
||||
assert err.failed()
|
||||
|
||||
|
||||
err = ErrorBundle()
|
||||
langpack.test_unsafe_html(err, "asdf", """
|
||||
Nothing to <a href="http://foo.bar/">suspect</a> here.""")
|
||||
assert err.failed()
|
||||
|
||||
|
||||
err = ErrorBundle()
|
||||
langpack.test_unsafe_html(err, "asdf", "src='data:foobar")
|
||||
assert err.failed()
|
||||
|
@ -71,14 +75,16 @@ def test_unsafe_html():
|
|||
langpack.test_unsafe_html(err, "asdf", 'href="ftp://foo.bar/')
|
||||
assert err.failed()
|
||||
|
||||
|
||||
def test_has_chrome_manifest():
|
||||
"""Makes sure the module fails when a chrome.manifest file is not
|
||||
available."""
|
||||
|
||||
|
||||
assert langpack.test_langpack_manifest(ErrorBundle(),
|
||||
{},
|
||||
None) is None
|
||||
|
||||
|
||||
def test_valid_chrome_manifest():
|
||||
"Chrome manifests must only contain certain elements"
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import os
|
||||
|
||||
import validator.testcases.content as test_content
|
||||
from validator.errorbundler import ErrorBundle
|
||||
from validator.xpi import XPIManager
|
||||
|
|
|
@ -2,47 +2,40 @@ import validator.testcases.markup.csstester as csstester
|
|||
from validator.errorbundler import ErrorBundle
|
||||
|
||||
def _do_test(path, should_fail=False):
|
||||
|
||||
css_file = open(path)
|
||||
data = css_file.read()
|
||||
css_file.close()
|
||||
|
||||
err = ErrorBundle(None, True)
|
||||
|
||||
|
||||
data = open(path).read()
|
||||
err = ErrorBundle()
|
||||
|
||||
csstester.test_css_file(err, "css.css", data)
|
||||
|
||||
err.print_summary(True)
|
||||
|
||||
|
||||
if should_fail:
|
||||
assert err.failed()
|
||||
else:
|
||||
assert not err.failed()
|
||||
|
||||
|
||||
return err
|
||||
|
||||
|
||||
def test_css_file():
|
||||
"Tests a package with a valid CSS file."
|
||||
|
||||
|
||||
_do_test("tests/resources/markup/csstester/pass.css")
|
||||
|
||||
|
||||
|
||||
def test_css_moz_binding():
|
||||
"Tests that remote scripts in CSS are blocked."
|
||||
|
||||
|
||||
_do_test("tests/resources/markup/csstester/mozbinding.css", True)
|
||||
_do_test("tests/resources/markup/csstester/mozbinding-pass.css", False)
|
||||
|
||||
def test_css_unicode():
|
||||
"Tests that bad unicode is frowned upon."
|
||||
|
||||
# TODO: This test may have been made invalid by an updated version of
|
||||
# the css parser library.
|
||||
# _do_test("tests/resources/markup/csstester/unicode_ewwww.css", True)
|
||||
|
||||
|
||||
|
||||
def test_css_identitybox():
|
||||
"Tests that the identity box isn't played with."
|
||||
|
||||
|
||||
_do_test("tests/resources/markup/csstester/identity-box.css", True)
|
||||
|
||||
|
||||
def test_remote_urls():
|
||||
"Tests the Regex used to detect remote URLs"
|
||||
|
||||
|
|
|
@ -3,12 +3,14 @@ import validator.testcases.markup.markuptester as markuptester
|
|||
from validator.errorbundler import ErrorBundle
|
||||
from validator.constants import *
|
||||
|
||||
|
||||
def _do_test(path, should_fail=False, type_=None):
|
||||
return _do_test_raw(open(path).read(),
|
||||
path,
|
||||
should_fail,
|
||||
type_)
|
||||
|
||||
|
||||
def _do_test_raw(data, path, should_fail=False, type_=None):
|
||||
filename = path.split("/")[-1]
|
||||
extension = filename.split(".")[-1]
|
||||
|
@ -55,51 +57,61 @@ def test_html_file():
|
|||
|
||||
_do_test("tests/resources/markup/markuptester/pass.html")
|
||||
|
||||
|
||||
def test_xml_file():
|
||||
"Tests a package with a valid XML file."
|
||||
|
||||
_do_test("tests/resources/markup/markuptester/pass.xml")
|
||||
|
||||
|
||||
def test_xul_file():
|
||||
"Tests a package with a valid XUL file."
|
||||
|
||||
_do_test("tests/resources/markup/markuptester/pass.xul")
|
||||
|
||||
|
||||
def test_xml_bad_nesting():
|
||||
"Tests an XML file that has badly nested elements."
|
||||
|
||||
_do_test("tests/resources/markup/markuptester/bad_nesting.xml", True)
|
||||
|
||||
|
||||
def test_has_cdata():
|
||||
"Tests that CDATA is good to go."
|
||||
|
||||
_do_test("tests/resources/markup/markuptester/cdata.xml")
|
||||
|
||||
|
||||
def test_xml_overclosing():
|
||||
"Tests an XML file that has overclosed elements"
|
||||
|
||||
_do_test("tests/resources/markup/markuptester/overclose.xml", True)
|
||||
|
||||
|
||||
def test_xml_extraclosing():
|
||||
"Tests an XML file that has extraclosed elements"
|
||||
|
||||
_do_test("tests/resources/markup/markuptester/extraclose.xml", True)
|
||||
|
||||
|
||||
def test_html_ignore_comment():
|
||||
"Tests that HTML comment values are ignored"
|
||||
|
||||
_do_test("tests/resources/markup/markuptester/ignore_comments.html")
|
||||
|
||||
|
||||
def test_html_css_style():
|
||||
"Tests that CSS within an element is passed to the CSS tester"
|
||||
|
||||
_do_test("tests/resources/markup/markuptester/css_style.html", True)
|
||||
|
||||
|
||||
def test_html_css_inline():
|
||||
"Tests that inline CSS is passed to the CSS tester"
|
||||
|
||||
_do_test("tests/resources/markup/markuptester/css_inline.html", True)
|
||||
|
||||
|
||||
def test_xul_evil():
|
||||
"Tests for evil kinds of scripts and iframes in XUL."
|
||||
|
||||
|
@ -111,6 +123,7 @@ def test_xul_evil():
|
|||
"bad_iframe_remote_missing.xul",
|
||||
True)
|
||||
|
||||
|
||||
def test_lp_passing():
|
||||
"Tests a valid language pack file."
|
||||
|
||||
|
@ -118,6 +131,7 @@ def test_lp_passing():
|
|||
False,
|
||||
PACKAGE_LANGPACK)
|
||||
|
||||
|
||||
def test_lp_unsafe():
|
||||
"Tests a language pack file that contains unsafe elements."
|
||||
|
||||
|
@ -125,6 +139,7 @@ def test_lp_unsafe():
|
|||
True,
|
||||
PACKAGE_LANGPACK)
|
||||
|
||||
|
||||
def test_lp_remote():
|
||||
"Tests a language pack file that contains remote references."
|
||||
|
||||
|
@ -163,16 +178,18 @@ def test_self_closing_scripts():
|
|||
</foo>
|
||||
""", "foo.js")
|
||||
|
||||
def test_dom_mutation():
|
||||
"""Test that DOM mutation events are warned against."""
|
||||
|
||||
_do_test_raw("""
|
||||
<foo><bar onzap="" /></foo>
|
||||
""", "foo.js")
|
||||
|
||||
_do_test_raw("""
|
||||
<foo><bar ondomattrmodified="" /></foo>
|
||||
""", "foo.js", should_fail=True)
|
||||
|
||||
def test_dom_mutation():
|
||||
"""Test that DOM mutation events are warned against."""
|
||||
|
||||
_do_test_raw("""
|
||||
<foo><bar onzap="" /></foo>
|
||||
""", "foo.js")
|
||||
|
||||
_do_test_raw("""
|
||||
<foo><bar ondomattrmodified="" /></foo>
|
||||
""", "foo.js", should_fail=True)
|
||||
|
||||
|
||||
def test_dom_mutation():
|
||||
"""Test that DOM mutation events are warned against."""
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import os
|
||||
|
||||
from StringIO import StringIO
|
||||
|
||||
from validator.opensearch import detect_opensearch
|
||||
|
@ -8,14 +6,8 @@ from validator.errorbundler import ErrorBundle
|
|||
from validator.constants import *
|
||||
|
||||
def _do_test(url, failure=True, listed=False):
|
||||
|
||||
xml_file = open(url)
|
||||
data = xml_file.read()
|
||||
wrapper = StringIO(data)
|
||||
|
||||
err = ErrorBundle()
|
||||
|
||||
results = detect_opensearch(err, wrapper, listed=listed)
|
||||
results = detect_opensearch(err, open(url), listed=listed)
|
||||
|
||||
if results.failed():
|
||||
print results.print_summary()
|
||||
|
|
|
@ -31,6 +31,7 @@ def test_blacklisted_files():
|
|||
m in
|
||||
err.warnings)
|
||||
|
||||
|
||||
def test_blacklisted_magic_numbers():
|
||||
"Tests that blacklisted magic numbers are banned"
|
||||
|
||||
|
@ -56,6 +57,7 @@ def test_theme_passing():
|
|||
packagelayout.test_theme_layout,
|
||||
False)
|
||||
|
||||
|
||||
def test_extra_unimportant():
|
||||
"""Tests the layout of a theme that contains an unimportant but
|
||||
extra directory."""
|
||||
|
@ -64,6 +66,7 @@ def test_extra_unimportant():
|
|||
packagelayout.test_theme_layout,
|
||||
False)
|
||||
|
||||
|
||||
def _do_simulated_test(function, structure, failure=False, ff4=False):
|
||||
""""Performs a test on a function or set of functions without
|
||||
generating a full package."""
|
||||
|
@ -85,6 +88,7 @@ def _do_simulated_test(function, structure, failure=False, ff4=False):
|
|||
|
||||
return err
|
||||
|
||||
|
||||
def test_langpack_max():
|
||||
"""Tests the package layout module out on a simulated language pack
|
||||
containing the largest number of possible elements."""
|
||||
|
@ -102,6 +106,7 @@ def test_langpack_max():
|
|||
"chrome/asdf.xhtml",
|
||||
"chrome/asdf.css"])
|
||||
|
||||
|
||||
def test_dict_max():
|
||||
"""Tests the package layout module out on a simulated dictionary
|
||||
containing the largest number of possible elements."""
|
||||
|
@ -116,6 +121,7 @@ def test_dict_max():
|
|||
"chrome.manifest",
|
||||
"chrome/whatever.jar"])
|
||||
|
||||
|
||||
def test_unknown_file():
|
||||
"""Tests that the unknown file detection function is working."""
|
||||
|
||||
|
@ -128,6 +134,7 @@ def test_unknown_file():
|
|||
"chrome.manifest",
|
||||
"chromelist.txt"])
|
||||
|
||||
|
||||
def test_disallowed_file():
|
||||
"""Tests that outright improper files are blocked."""
|
||||
|
||||
|
@ -177,7 +184,6 @@ def test_has_installrdfs():
|
|||
mock_xpi_subpack)
|
||||
|
||||
|
||||
|
||||
class MockXPIAll:
|
||||
"Simulates an XPI package manager object"
|
||||
|
||||
|
@ -202,4 +208,3 @@ def _do_installrdfs(function, has_install_rdf=True, xpi=None):
|
|||
|
||||
return err.failed()
|
||||
|
||||
|
||||
|
|
|
@ -2,9 +2,10 @@ from validator.errorbundler import ErrorBundle
|
|||
from validator.constants import *
|
||||
import validator.testcases.packagelayout as packagelayout
|
||||
|
||||
|
||||
def _do_test(unpack=False, contents=(), set_type=0, is_ff4=False):
|
||||
"Runs the tests. Handy as hell."
|
||||
|
||||
|
||||
err = ErrorBundle(None, True)
|
||||
if set_type:
|
||||
err.set_type(set_type)
|
||||
|
@ -13,11 +14,13 @@ def _do_test(unpack=False, contents=(), set_type=0, is_ff4=False):
|
|||
packagelayout.test_emunpack(err, contents, None)
|
||||
return err
|
||||
|
||||
|
||||
def test_no_unpack():
|
||||
"Tests that packages for non-FF4 + no content + PACKAGE_ANY passes."
|
||||
|
||||
assert not _do_test().failed()
|
||||
|
||||
|
||||
def test_unpack_ff4():
|
||||
"Tests that if FF4 is not targeted, it should pass if unpack istrue."
|
||||
|
||||
|
@ -25,33 +28,36 @@ def test_unpack_ff4():
|
|||
contents=("foo.jar", ),
|
||||
is_ff4=True).failed()
|
||||
|
||||
|
||||
def test_no_unpack_ff4():
|
||||
"When FF4 is not supported and unpack is untrue, JARs should throw errors."
|
||||
|
||||
assert not _do_test(contents=("foo.jar", ),
|
||||
is_ff4=False).failed()
|
||||
|
||||
|
||||
def test_no_unpack_dict():
|
||||
"When unpack is false/unset, it should always fail for dictionaries."
|
||||
|
||||
|
||||
assert _do_test(set_type=PACKAGE_DICTIONARY).failed()
|
||||
|
||||
|
||||
def test_no_unpacked_ico():
|
||||
"Packages containing ICO files and unpack is unset/false should fail."
|
||||
|
||||
assert _do_test(contents=("chrome/icons/default/foo.png", )).failed()
|
||||
|
||||
|
||||
def test_no_unpacked_exec_safe():
|
||||
"""Packages containing executable files outside the /components/ directory
|
||||
and where unpack is unset/false should NOT fail."""
|
||||
|
||||
assert not _do_test(contents=("foo.exe", )).failed()
|
||||
|
||||
|
||||
def test_no_unpacked_exec():
|
||||
"""Packages containing executable files in the /components/ directory and
|
||||
where unpack is unset/false should fail."""
|
||||
|
||||
assert _do_test(contents=("components/foo.exe", )).failed()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,82 +1,71 @@
|
|||
import os
|
||||
|
||||
from StringIO import StringIO
|
||||
|
||||
import validator.rdf as rdf
|
||||
from validator.rdf import RDFParser
|
||||
|
||||
def _load_rdf(file_):
|
||||
"Loads an RDF file into a string."
|
||||
|
||||
rdf = open(file_)
|
||||
data = rdf.read()
|
||||
rdf.close()
|
||||
return data
|
||||
|
||||
|
||||
def test_load_rdf():
|
||||
def testopen():
|
||||
"""Tests that the RDF parser is capable of loading an RDF file
|
||||
successfully."""
|
||||
|
||||
r = RDFParser(_load_rdf("tests/resources/rdf/pass.rdf"))
|
||||
|
||||
r = RDFParser(open("tests/resources/rdf/pass.rdf"))
|
||||
assert r.rdf
|
||||
|
||||
def test_load_bad():
|
||||
"""Tests that the RDF parser throws an error for invalid, damaged,
|
||||
or corrupt RDF files."""
|
||||
|
||||
r = RDFParser(_load_rdf("tests/resources/rdf/fail.rdf"))
|
||||
|
||||
r = RDFParser(open("tests/resources/rdf/fail.rdf"))
|
||||
assert not r.rdf
|
||||
|
||||
def test_load_rdf_stringio():
|
||||
"""Tests that the RDF parser is capable of loading an RDF file
|
||||
from a StringIO object successfully."""
|
||||
|
||||
sio = StringIO(_load_rdf("tests/resources/rdf/pass.rdf"))
|
||||
|
||||
|
||||
sio = StringIO(open("tests/resources/rdf/pass.rdf").read())
|
||||
r = RDFParser(sio)
|
||||
assert r.rdf
|
||||
|
||||
def test_namespacing():
|
||||
"""Tests that the RDF parser successfully creates namespaces."""
|
||||
|
||||
r = RDFParser(_load_rdf("tests/resources/rdf/pass.rdf"), "foo")
|
||||
|
||||
|
||||
r = RDFParser(open("tests/resources/rdf/pass.rdf"), "foo")
|
||||
|
||||
assert r.namespace == "foo"
|
||||
assert str(r.uri("bar")) == "foo#bar"
|
||||
assert str(r.uri("bar", "abc")) == "abc#bar"
|
||||
|
||||
def test_namespacing():
|
||||
"""Tests that the RDF parser successfully creates namespaces."""
|
||||
|
||||
r = RDFParser(_load_rdf("tests/resources/rdf/pass.rdf"), "foo")
|
||||
|
||||
|
||||
r = RDFParser(open("tests/resources/rdf/pass.rdf"), "foo")
|
||||
|
||||
assert r.namespace == "foo"
|
||||
assert str(r.uri("bar")) == "foo#bar"
|
||||
assert str(r.uri("bar", "abc")) == "abc#bar"
|
||||
|
||||
def test_get_root_subject():
|
||||
"Tests the integrity of the get_root_subject() function"
|
||||
|
||||
r = RDFParser(_load_rdf("tests/resources/rdf/pass.rdf"))
|
||||
|
||||
r = RDFParser(open("tests/resources/rdf/pass.rdf"))
|
||||
type_uri = r.uri("type")
|
||||
|
||||
|
||||
emtype = r.get_object(None, type_uri)
|
||||
assert emtype is not None
|
||||
|
||||
|
||||
emtype = r.get_object(r.get_root_subject(), type_uri)
|
||||
assert emtype is not None
|
||||
|
||||
def test_get_object():
|
||||
""""Tests the integrity of the get_object() and get_objects()
|
||||
functions."""
|
||||
|
||||
r = RDFParser(_load_rdf("tests/resources/rdf/pass.rdf"))
|
||||
|
||||
r = RDFParser(open("tests/resources/rdf/pass.rdf"))
|
||||
test_uri = r.uri("test")
|
||||
|
||||
|
||||
emtest = r.get_object(None, test_uri)
|
||||
assert emtest is not None
|
||||
|
||||
|
||||
emtests = r.get_objects(None, test_uri)
|
||||
assert len(emtests) == 3
|
||||
assert emtests[0] == emtest
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import os
|
||||
|
||||
import validator.submain as submain
|
||||
from validator.errorbundler import ErrorBundle
|
||||
from validator.chromemanifest import ChromeManifest
|
||||
from validator.constants import *
|
||||
|
||||
|
||||
def test_prepare_package():
|
||||
"Tests that the prepare_package function passes for valid data"
|
||||
|
||||
|
@ -15,6 +14,7 @@ def test_prepare_package():
|
|||
assert submain.prepare_package(err, "tests/resources/main/foo.xpi") == True
|
||||
submain.test_package = tp
|
||||
|
||||
|
||||
def test_prepare_package_extension():
|
||||
"Tests that bad extensions get outright rejections"
|
||||
|
||||
|
@ -25,6 +25,7 @@ def test_prepare_package_extension():
|
|||
assert submain.prepare_package(None, "foo/bar/test.xml") == True
|
||||
submain.test_search = ts
|
||||
|
||||
|
||||
def test_prepare_package_missing():
|
||||
"Tests that the prepare_package function fails when file is not found"
|
||||
|
||||
|
@ -33,6 +34,7 @@ def test_prepare_package_missing():
|
|||
|
||||
assert err.failed()
|
||||
|
||||
|
||||
def test_prepare_package_bad_file():
|
||||
"Tests that the prepare_package function fails for unknown files"
|
||||
|
||||
|
@ -41,6 +43,7 @@ def test_prepare_package_bad_file():
|
|||
|
||||
assert err.failed()
|
||||
|
||||
|
||||
def test_prepare_package_xml():
|
||||
"Tests that the prepare_package function passes with search providers"
|
||||
|
||||
|
@ -73,6 +76,7 @@ def test_test_inner_package():
|
|||
assert not err.failed()
|
||||
submain.decorator = smd
|
||||
|
||||
|
||||
def test_test_inner_package_failtier():
|
||||
"Tests that the test_inner_package function fails at a failed tier"
|
||||
|
||||
|
@ -123,6 +127,7 @@ def test_test_inner_package_determined():
|
|||
assert decorator.last_tier == 5
|
||||
submain.decorator = smd
|
||||
|
||||
|
||||
def test_test_inner_package_failtier():
|
||||
"Tests the test_inner_package function in determined mode while failing"
|
||||
|
||||
|
@ -137,6 +142,7 @@ def test_test_inner_package_failtier():
|
|||
assert decorator.last_tier == 5
|
||||
submain.decorator = smd
|
||||
|
||||
|
||||
class MockDecorator:
|
||||
|
||||
def __init__(self, fail_tier=None, determined=False):
|
||||
|
@ -190,6 +196,7 @@ class MockDecorator:
|
|||
print self.fail_tier
|
||||
assert self.on_tier == self.fail_tier
|
||||
|
||||
|
||||
class MockErrorHandler:
|
||||
|
||||
def __init__(self, mock_decorator, determined=False):
|
||||
|
@ -229,6 +236,7 @@ class MockErrorHandler:
|
|||
"Simple accessor because the standard error handler has one"
|
||||
return self.has_failed
|
||||
|
||||
|
||||
class MockXPIPackage:
|
||||
"A class that pretends to be an add-on package"
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import os
|
||||
|
||||
import validator.submain as submain
|
||||
from validator.errorbundler import ErrorBundle
|
||||
from validator.xpi import XPIManager
|
||||
from validator.constants import *
|
||||
|
||||
|
||||
# TODO: This should someday be replaced with helper._do_test
|
||||
def _run_test(filename, expectation, should_fail=True):
|
||||
|
||||
name = "tests/resources/submain/%s" % filename
|
||||
|
@ -66,6 +66,7 @@ def test_load_irdf_expectation():
|
|||
_run_test("install_rdf.xpi", PACKAGE_EXTENSION, True)
|
||||
submain.detect_type = dt
|
||||
|
||||
|
||||
def test_doctype():
|
||||
"Asserts that install.rdf files with doctypes break validation"
|
||||
|
||||
|
@ -77,6 +78,7 @@ def test_doctype():
|
|||
assert not err.get_resource("has_install_rdf")
|
||||
assert not err.get_resource("install_rdf")
|
||||
|
||||
|
||||
class MockXPIManager(object):
|
||||
"Pretends to be a simple XPI manager"
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import os
|
||||
|
||||
import validator.submain as submain
|
||||
from validator.errorbundler import ErrorBundle
|
||||
from validator.constants import *
|
||||
|
||||
|
||||
def test_package_pass():
|
||||
"Tests the test_package function with simple data"
|
||||
|
||||
|
@ -90,4 +89,3 @@ def test_package_extension_bad_expectation():
|
|||
|
||||
assert err.failed()
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import validator.submain
|
|||
from validator import decorator
|
||||
from validator.errorbundler import ErrorBundle
|
||||
|
||||
|
||||
def test_version_decorators_accepted():
|
||||
"""
|
||||
Test that decorators that specify versions to target accept the proper
|
||||
|
@ -27,6 +28,7 @@ def test_version_decorators_accepted():
|
|||
assert err.get_resource("executed")
|
||||
decorator.TEST_TIERS = tests
|
||||
|
||||
|
||||
def test_version_decorators_denied_guid():
|
||||
"""
|
||||
Test that decorators that specify versions to target deny add-ons that do
|
||||
|
@ -49,6 +51,7 @@ def test_version_decorators_denied_guid():
|
|||
validator.submain.test_inner_package(err, {}, None)
|
||||
decorator.TEST_TIERS = tests
|
||||
|
||||
|
||||
def test_version_decorators_denied_version():
|
||||
"""
|
||||
Test that decorators that specify versions to target deny add-ons that do
|
||||
|
@ -71,6 +74,7 @@ def test_version_decorators_denied_version():
|
|||
validator.submain.test_inner_package(err, {}, None)
|
||||
decorator.TEST_TIERS = tests
|
||||
|
||||
|
||||
def test_version_forappversions_accepted():
|
||||
"""
|
||||
Test that for_appversions targets application versions properly.
|
||||
|
@ -97,6 +101,7 @@ def test_version_forappversions_accepted():
|
|||
assert err.get_resource("executed")
|
||||
decorator.TEST_TIERS = tests
|
||||
|
||||
|
||||
def test_version_forappversions_denied():
|
||||
"""
|
||||
Test that for_appversions denies target application versions properly.
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import json
|
||||
from StringIO import StringIO
|
||||
|
||||
import validator.testcases.targetapplication as targetapp
|
||||
from validator.constants import *
|
||||
from validator.errorbundler import ErrorBundle
|
||||
|
@ -15,7 +13,7 @@ targetapp.APPROVED_APPLICATIONS = \
|
|||
def _do_test_raw(rdf, listed=True, overrides=None):
|
||||
err = ErrorBundle(listed=listed)
|
||||
err.overrides = overrides
|
||||
rdf = RDFParser(StringIO(rdf.strip()))
|
||||
rdf = RDFParser(rdf.strip())
|
||||
err.save_resource("has_install_rdf", True)
|
||||
err.save_resource("install_rdf", rdf)
|
||||
|
||||
|
@ -69,6 +67,7 @@ def test_bad_order():
|
|||
True,
|
||||
True)
|
||||
|
||||
|
||||
def test_dup_targets():
|
||||
"""Tests that there are no duplicate targetAppication elements."""
|
||||
|
||||
|
@ -77,6 +76,7 @@ def test_dup_targets():
|
|||
True,
|
||||
True)
|
||||
|
||||
|
||||
def test_has_installrdfs():
|
||||
"""Tests that install.rdf files are present."""
|
||||
|
||||
|
@ -85,6 +85,7 @@ def test_has_installrdfs():
|
|||
# Test package to make sure has_install_rdf is set to True.
|
||||
assert targetapp.test_targetedapplications(err, {}, None) is None
|
||||
|
||||
|
||||
def test_is_ff4():
|
||||
"""Tests a passing install.rdf package for whether it's built for
|
||||
Firefox 4. This doesn't pass or fail a package, but it is used for
|
||||
|
@ -196,7 +197,6 @@ def test_overrides():
|
|||
{"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": "3.6"}}
|
||||
).failed()
|
||||
|
||||
|
||||
# Make sure a test can be forced to fail.
|
||||
assert _do_test_raw("""
|
||||
<?xml version="1.0"?>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import validator.textfilter as textfilter
|
||||
|
||||
|
||||
def test_is_ctrl_char():
|
||||
"Tests whether a character is a control character"
|
||||
|
||||
|
@ -10,6 +11,7 @@ def test_is_ctrl_char():
|
|||
# Test ordinal override
|
||||
assert not textfilter.is_ctrl_char(chr(3), 50)
|
||||
|
||||
|
||||
def test_is_standard_ascii():
|
||||
"Tests the is_standard_ascii function"
|
||||
|
||||
|
@ -18,6 +20,7 @@ def test_is_standard_ascii():
|
|||
assert not textfilter.is_standard_ascii(chr(127))
|
||||
assert not textfilter.is_standard_ascii(chr(200))
|
||||
|
||||
|
||||
def test_filter_ascii():
|
||||
"Tests the filter_ascii function"
|
||||
|
||||
|
|
|
@ -2,20 +2,24 @@ import validator.testcases.themes as themes
|
|||
from validator.errorbundler import ErrorBundle
|
||||
from helper import _do_test
|
||||
|
||||
|
||||
def test_theme_chrome_manifest():
|
||||
"Tests that a theme has a valid chrome manifest file."
|
||||
|
||||
|
||||
_do_test("tests/resources/themes/pass.jar",
|
||||
themes.test_theme_manifest,
|
||||
False)
|
||||
|
||||
|
||||
def test_theme_bad_chrome_manifest():
|
||||
"Tests that a theme has an invalid chrome manifest file."
|
||||
|
||||
|
||||
_do_test("tests/resources/themes/fail.jar",
|
||||
themes.test_theme_manifest)
|
||||
|
||||
|
||||
def test_no_chrome_manifest():
|
||||
"Tests that validation is skipped if there is no chrome manifest."
|
||||
|
||||
|
||||
assert themes.test_theme_manifest(ErrorBundle(), {}, None) is None
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import os
|
||||
|
||||
from validator.errorbundler import ErrorBundle
|
||||
from validator.rdf import RDFParser
|
||||
from validator.xpi import XPIManager
|
||||
|
@ -77,6 +75,7 @@ def test_langpack():
|
|||
_test_type("tests/resources/typedetection/td_langpack.xpi",
|
||||
PACKAGE_LANGPACK)
|
||||
|
||||
|
||||
def test_bad_emtype():
|
||||
"""Tests for a bad <em:type> value."""
|
||||
|
||||
|
@ -84,6 +83,7 @@ def test_bad_emtype():
|
|||
None,
|
||||
True)
|
||||
|
||||
|
||||
def test_strange():
|
||||
"""Tests that in install.rdf-less package is listed as being a
|
||||
dictionary type if it has an XPI extension and otherwise passes
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import nose
|
||||
import os
|
||||
import validator.unicodehelper as unicodehelper
|
||||
|
||||
|
||||
COMPARISON = "täst".decode("utf-8")
|
||||
|
||||
def _do_test(path):
|
||||
|
@ -14,30 +14,38 @@ def _do_test(path):
|
|||
print utext.encode("ascii", "backslashreplace")
|
||||
nose.tools.eq_(utext, COMPARISON)
|
||||
|
||||
|
||||
def test_latin1():
|
||||
"Tests utf-8 encoding is properly decoded"
|
||||
_do_test("tests/resources/unicodehelper/latin_1.txt")
|
||||
|
||||
|
||||
def test_utf8():
|
||||
"Tests utf-8 w/o BOM encoding is properly decoded"
|
||||
_do_test("tests/resources/unicodehelper/utf-8.txt")
|
||||
|
||||
|
||||
def test_utf8():
|
||||
"Tests utf-8 with BOM encoding is properly decoded"
|
||||
_do_test("tests/resources/unicodehelper/utf-8-bom.txt")
|
||||
|
||||
|
||||
def test_utf16le():
|
||||
"Tests utf-16 Little Endian encoding is properly decoded"
|
||||
_do_test("tests/resources/unicodehelper/utf-16le.txt")
|
||||
|
||||
|
||||
def test_utf16be():
|
||||
"Tests utf-16 Big Endian encoding is properly decoded"
|
||||
_do_test("tests/resources/unicodehelper/utf-16be.txt")
|
||||
|
||||
|
||||
def test_utf32le():
|
||||
"Tests utf-32 Little Endian encoding is properly decoded"
|
||||
_do_test("tests/resources/unicodehelper/utf-32le.txt")
|
||||
|
||||
|
||||
def test_utf32be():
|
||||
"Tests utf-32 Big Endian encoding is properly decoded"
|
||||
_do_test("tests/resources/unicodehelper/utf-32be.txt")
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ from validator.errorbundler import ErrorBundle
|
|||
import validator.constants
|
||||
import validator.testcases.targetapplication as targetapp
|
||||
|
||||
|
||||
def test_validate():
|
||||
output = validate(path="tests/resources/packagelayout/theme.jar")
|
||||
j = json.loads(output)
|
||||
|
@ -40,6 +41,7 @@ def test_validate():
|
|||
format=None)
|
||||
assert output.overrides == "foo"
|
||||
|
||||
|
||||
def test_app_versions():
|
||||
"Tests that the validate function properly loads app_versions.json"
|
||||
validate(path="tests/resources/junk.xpi",
|
||||
|
|
|
@ -1,41 +1,46 @@
|
|||
import zipfile
|
||||
from zipfile import ZipFile
|
||||
|
||||
from validator.xpi import XPIManager
|
||||
|
||||
|
||||
def test_open():
|
||||
"Test that the manager will open the package"
|
||||
z = XPIManager("tests/resources/xpi/install_rdf_only.xpi")
|
||||
assert z is not None
|
||||
|
||||
|
||||
|
||||
def test_get_list():
|
||||
"Test that the manager can read the file listing"
|
||||
z = XPIManager("tests/resources/xpi/install_rdf_only.xpi")
|
||||
assert z.get_file_data()
|
||||
|
||||
|
||||
|
||||
def test_valid_name():
|
||||
"Test that the manager can retrieve the correct file name"
|
||||
z = XPIManager("tests/resources/xpi/install_rdf_only.xpi")
|
||||
contents = z.get_file_data()
|
||||
assert "install.rdf" in contents
|
||||
assert z.test() == False
|
||||
|
||||
|
||||
|
||||
def test_read_file():
|
||||
"Test that a file can be read from the package"
|
||||
z = XPIManager("tests/resources/xpi/install_rdf_only.xpi")
|
||||
assert z.read("install.rdf") is not None
|
||||
|
||||
|
||||
def test_bad_file():
|
||||
"Tests that the XPI manager correctly reports a bad XPI file."
|
||||
|
||||
|
||||
x = XPIManager("tests/resources/junk.xpi")
|
||||
assert not x.zf
|
||||
|
||||
|
||||
x = XPIManager("tests/resources/corrupt.xpi")
|
||||
assert x.test()
|
||||
|
||||
|
||||
def test_missing_file():
|
||||
"Tests that the XPI manager correctly reports a missing XPI file."
|
||||
|
||||
|
||||
x = XPIManager("tests/resources/foo.bar")
|
||||
assert not x.zf
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import rdflib
|
||||
import types
|
||||
from rdflib import URIRef
|
||||
from StringIO import StringIO
|
||||
|
||||
|
@ -17,13 +18,11 @@ class RDFParser(object):
|
|||
self.namespace = namespace
|
||||
|
||||
# Try it!
|
||||
if not isinstance(data, StringIO):
|
||||
pseudo_file = StringIO(data) # Wrap data in a pseudo-file
|
||||
else:
|
||||
pseudo_file = data
|
||||
if isinstance(data, types.StringTypes):
|
||||
data = StringIO(data) # Wrap data in a pseudo-file
|
||||
|
||||
try:
|
||||
graph.parse(pseudo_file, format="xml")
|
||||
graph.parse(data, format="xml")
|
||||
except Exception as error:
|
||||
self.rdf = None
|
||||
return
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
import types
|
||||
from StringIO import StringIO
|
||||
from validator.contextgenerator import ContextGenerator
|
||||
|
||||
try:
|
||||
|
@ -20,11 +21,13 @@ class DTDParser(object):
|
|||
self.entities = {}
|
||||
self.items = []
|
||||
|
||||
if isinstance(dtd, str):
|
||||
dtd_instance = open(dtd)
|
||||
data = dtd_instance.read()
|
||||
dtd_instance.close()
|
||||
else:
|
||||
data = ""
|
||||
if isinstance(dtd, types.StringTypes):
|
||||
with open(dtd) as dtd_instance:
|
||||
data = dtd_instance.read()
|
||||
elif isinstance(dtd, file):
|
||||
data = dtd.read()
|
||||
elif isinstance(dtd, StringIO):
|
||||
data = dtd.getvalue()
|
||||
|
||||
self._parse(data)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import types
|
||||
from StringIO import StringIO
|
||||
from validator.contextgenerator import ContextGenerator
|
||||
|
||||
|
||||
|
@ -17,10 +19,12 @@ class PropertiesParser(object):
|
|||
self.entities = {}
|
||||
self.items = []
|
||||
|
||||
if isinstance(dtd, str):
|
||||
if isinstance(dtd, types.StringTypes):
|
||||
data = open(dtd).read()
|
||||
else:
|
||||
elif isinstance(dtd, StringIO):
|
||||
data = dtd.getvalue()
|
||||
elif isinstance(dtd, file):
|
||||
data = dtd.read()
|
||||
|
||||
# Create a context!
|
||||
self.context = ContextGenerator(data)
|
||||
|
|
Загрузка…
Ссылка в новой задаче