Beispiel #1
0
def buildTestSuite():
    sys.stdout.write('Testing tree walkers ' +
                     " ".join(list(treeTypes.keys())) + "\n")

    for treeName, treeCls in treeTypes.items():
        files = html5lib_test_files('tree-construction')
        files = [
            f for f in files
            if not f.split(".")[-2][-2:] in ("s9", "10", "11", "12")
        ]  #skip namespace tests for now
        for filename in files:
            testName = os.path.basename(filename).replace(".dat", "")
            if testName == "tests5": continue  # TODO

            tests = TestData(filename, "data")

            for index, test in enumerate(tests):
                (input, errors, innerHTML, expected) = [
                    test[key] for key in ("data", "errors",
                                          "document-fragment", "document")
                ]

                def testFunc(self,
                             innerHTML=innerHTML,
                             input=input,
                             expected=expected,
                             errors=errors,
                             treeCls=treeCls):
                    self.runTest(innerHTML, input, expected, errors, treeCls)

                setattr(TestCase,
                        "test_%s_%d_%s" % (testName, index + 1, treeName),
                        testFunc)

    return unittest.TestLoader().loadTestsFromTestCase(TestCase)
Beispiel #2
0
def buildTestSuite():
    sys.stdout.write('Testing tree builders '+ " ".join(treeTypes.keys()) + "\n")

    for treeName, treeCls in treeTypes.iteritems():
        files = html5lib_test_files('tree-construction')
        files = [f for f in files if 
                 not f.split(".")[-2][-2:] in ("s9", "10", "11", "12")] #skip namespace tests for now
        for filename in files:
            testName = os.path.basename(filename).replace(".dat","")

            tests = TestData(filename, "data")

            for index, test in enumerate(tests):
                input, errors, innerHTML, expected = [test[key] for key in
                                                      'data', 'errors',
                                                      'document-fragment',
                                                      'document']
                if errors:
                    errors = errors.split("\n")
                def testFunc(self, innerHTML=innerHTML, input=input,
                    expected=expected, errors=errors, treeCls=treeCls): 
                    return self.runParserTest(innerHTML, input, expected, errors, treeCls)
                setattr(TestCase, "test_%s_%d_%s" % (testName,index+1,treeName),
                     testFunc)

    return unittest.TestLoader().loadTestsFromTestCase(TestCase)
Beispiel #3
0
def buildTestSuite():
    for filename in html5lib_test_files("encoding"):
        test_name = os.path.basename(filename).replace('.dat',''). \
            replace('-','')
        tests = TestData(filename, "data")
        for idx, test in enumerate(tests):
            def encodingTest(self, data=test['data'], 
                             encoding=test['encoding']):
                p = HTMLParser()
                t = p.parse(data, useChardet=False)
                
                errorMessage = ("Input:\n%s\nExpected:\n%s\nRecieved\n%s\n"%
                                (data, repr(encoding.lower()), 
                                 repr(p.tokenizer.stream.charEncoding)))
                self.assertEquals(encoding.lower(),
                                  p.tokenizer.stream.charEncoding[0], 
                                  errorMessage)
            setattr(Html5EncodingTestCase, 'test_%s_%d' % (test_name, idx+1),
                encodingTest)

    try:
        import chardet
        def test_chardet(self):
            data = open(os.path.join(test_dir, "encoding" , "chardet", "test_big5.txt")).read()
            encoding = inputstream.HTMLInputStream(data).charEncoding
            assert encoding[0].lower() == "big5"
        setattr(Html5EncodingTestCase, 'test_chardet', test_chardet)
    except ImportError:
        print "chardet not found, skipping chardet tests"
        

    return unittest.defaultTestLoader.loadTestsFromName(__name__)
Beispiel #4
0
def main(out_path):
    if not os.path.exists(out_path):
        sys.stderr.write("Path %s does not exist" % out_path)
        sys.exit(1)

    for filename in support.html5lib_test_files('tokenizer', '*.test'):
        run_file(filename, out_path)
Beispiel #5
0
def buildTestSuite():
    for filename in html5lib_test_files('tokenizer', '*.test'):
        tests = simplejson.load(file(filename))
        testName = os.path.basename(filename).replace(".test", "")
        if 'tests' in tests:
            for index, test in enumerate(tests['tests']):
                #Skip tests with a self closing flag
                skip = False
                for token in test["output"]:
                    if token[0] == "StartTag" and len(token) == 4:
                        skip = True
                        break
                if skip:
                    continue
                if 'contentModelFlags' not in test:
                    test["contentModelFlags"] = ["PCDATA"]
                for contentModelFlag in test["contentModelFlags"]:
                    test["contentModelFlag"] = contentModelFlag

                    def testFunc(self, test=test):
                        self.runTokenizerTest(test)

                    testFunc.__doc__ = "\t".join(
                        [testName, test['description']])
                    setattr(TestCase, 'test_%s_%d' % (testName, index),
                            testFunc)
    return unittest.TestLoader().loadTestsFromTestCase(TestCase)
def main(out_path):
    if not os.path.exists(out_path):
        sys.stderr.write("Path %s does not exist"%out_path)
        sys.exit(1)

    for filename in support.html5lib_test_files('tokenizer', '*.test'):
        run_file(filename, out_path)
def buildTestSuite():
    sys.stdout.write('Testing tree builders '+ " ".join(treeTypes.keys()) + "\n")

    for treeName, treeCls in treeTypes.iteritems():
        files = html5lib_test_files('tree-construction')
        for filename in files:
            testName = os.path.basename(filename).replace(".dat","")

            tests = TestData(filename, "data")

            for index, test in enumerate(tests):
                input, errors, innerHTML, expected = [test[key] for key in
                                                      'data', 'errors',
                                                      'document-fragment',
                                                      'document']
                if errors:
                    errors = errors.split("\n")
                
                for namespaceHTMLElements in (True, False):
                    def testFunc(self, innerHTML=innerHTML, input=input,
                        expected=expected, errors=errors, treeCls=treeCls,
                        namespaceHTMLElements=namespaceHTMLElements): 
                        return self.runParserTest(innerHTML, input, expected,
                                                  errors, treeCls,
                                                  namespaceHTMLElements)
                    testFunc.__name__ = "test_%s_%d_%s_%s" % (testName,index+1,treeName, namespaceHTMLElements and "namespaced" or "no_html_namespace")
                    setattr(TestCase, testFunc.__name__,
                         testFunc)
                    break
        break

    return unittest.TestLoader().loadTestsFromTestCase(TestCase)
Beispiel #8
0
def buildTestSuite():
    sys.stdout.write('Testing tree builders '+ " ".join(treeTypes.keys()) + "\n")

    for treeName, treeCls in treeTypes.iteritems():
        files = html5lib_test_files('tree-construction')
        for filename in files:
            testName = os.path.basename(filename).replace(".dat","")

            tests = TestData(filename, "data")

            for index, test in enumerate(tests):
                input, errors, innerHTML, expected = [test[key] for key in
                                                      'data', 'errors',
                                                      'document-fragment',
                                                      'document']
                if errors:
                    errors = errors.split("\n")
                
                for namespaceHTMLElements in (True, False):
                    def testFunc(self, innerHTML=innerHTML, input=input,
                        expected=expected, errors=errors, treeCls=treeCls,
                        namespaceHTMLElements=namespaceHTMLElements): 
                        return self.runParserTest(innerHTML, input, expected,
                                                  errors, treeCls,
                                                  namespaceHTMLElements)
                    testFunc.__name__ = "test_%s_%d_%s_%s" % (testName,index+1,treeName, namespaceHTMLElements and "namespaced" or "no_html_namespace")
                    setattr(TestCase, testFunc.__name__,
                         testFunc)
                    break

    return unittest.TestLoader().loadTestsFromTestCase(TestCase)
Beispiel #9
0
def buildTestSuite():
    for filename in html5lib_test_files("sanitizer"):
        for test in json.load(file(filename)):
            SanitizeTest.addTest('test_' + test['name'], test['output'],
                                 test['input'])

    return unittest.TestLoader().loadTestsFromTestCase(SanitizeTest)
def buildTestSuite():
    for filename in html5lib_test_files("sanitizer"):
        for test in simplejson.load(file(filename)):
            SanitizeTest.addTest("test_" + test["name"], test["output"], test["input"])
        for test in simplejson.load(file(filename)):
            SanitizeTest.addTest("test_strip_" + test["name"], test["stripped"], test["input"], strip=True)

    return unittest.TestLoader().loadTestsFromTestCase(SanitizeTest)
Beispiel #11
0
def test_serializer():
    for filename in html5lib_test_files('serializer', '*.test'):
        tests = json.load(file(filename))
        test_name = os.path.basename(filename).replace('.test','')
        for index, test in enumerate(tests['tests']):
            xhtml = test.get("xhtml", test["expected"])
            if test_name == 'optionaltags': 
                xhtml = None
            yield make_test, test["input"], test["expected"], xhtml, test.get("options", {})
Beispiel #12
0
def buildTestSuite():
    for filename in html5lib_test_files('validator', '*.test'):
        tests = simplejson.load(file(filename))
        testName = os.path.basename(filename).replace(".test","")
        for index,test in enumerate(tests['tests']):
            def testFunc(self, test=test):
                self.runValidatorTest(test)
            testFunc.__doc__ = "\t".join([testName, test['description']])
            setattr(TestCase, 'test_%s_%d' % (testName, index), testFunc)
    return unittest.TestLoader().loadTestsFromTestCase(TestCase)
Beispiel #13
0
def buildTestSuite():
    for filename in html5lib_test_files('serializer', '*.test'):
        test_name = os.path.basename(filename).replace('.test','')
        tests = simplejson.load(file(filename))
        for index, test in enumerate(tests['tests']):
            xhtml = test.get("xhtml", test["expected"])
            if test_name == 'optionaltags': xhtml = None
            TestCase.addTest('test_%s_%d' % (test_name, index+1),
                test["description"], test["input"], test["expected"], xhtml,
                test.get("options", {}))
    return unittest.TestLoader().loadTestsFromTestCase(TestCase)
Beispiel #14
0
def buildTestSuite():
    for filename in html5lib_test_files('serializer', '*.test'):
        test_name = os.path.basename(filename).replace('.test', '')
        tests = simplejson.load(file(filename))
        for index, test in enumerate(tests['tests']):
            xhtml = test.get("xhtml", test["expected"])
            if test_name == 'optionaltags': xhtml = None
            TestCase.addTest('test_%s_%d' % (test_name, index + 1),
                             test["description"], test["input"],
                             test["expected"], xhtml, test.get("options", {}))
    return unittest.TestLoader().loadTestsFromTestCase(TestCase)
Beispiel #15
0
def buildTestSuite():
    for filename in html5lib_test_files('validator', '*.test'):
        tests = simplejson.load(file(filename))
        testName = os.path.basename(filename).replace(".test", "")
        for index, test in enumerate(tests['tests']):

            def testFunc(self, test=test):
                self.runValidatorTest(test)

            testFunc.__doc__ = "\t".join([testName, test['description']])
            setattr(TestCase, 'test_%s_%d' % (testName, index), testFunc)
    return unittest.TestLoader().loadTestsFromTestCase(TestCase)
Beispiel #16
0
def test_tokenizer():
    for filename in html5lib_test_files("tokenizer", "*.test"):
        tests = json.load(file(filename))
        testName = os.path.basename(filename).replace(".test", "")
        if "tests" in tests:
            for index, test in enumerate(tests["tests"]):
                # Skip tests with a self closing flag
                skip = False
                if "initialStates" not in test:
                    test["initialStates"] = ["Data state"]
                for initialState in test["initialStates"]:
                    test["initialState"] = capitalize(initialState)
                    yield runTokenizerTest, test
Beispiel #17
0
def test_treewalker():
    sys.stdout.write('Testing tree walkers '+ " ".join(treeTypes.keys()) + "\n")

    for treeName, treeCls in treeTypes.iteritems():
        files = html5lib_test_files('tree-construction')
        for filename in files:
            testName = os.path.basename(filename).replace(".dat","")

            tests = TestData(filename, "data")

            for index, test in enumerate(tests):
                (input, errors,
                 innerHTML, expected) = [test[key] for key in ("data", "errors",
                                                               "document-fragment",
                                                               "document")]
                errors = errors.split("\n")
                yield run_test, innerHTML, input, expected, errors, treeCls
Beispiel #18
0
def test_treewalker():
    sys.stdout.write('Testing tree walkers ' + " ".join(treeTypes.keys()) +
                     "\n")

    for treeName, treeCls in treeTypes.iteritems():
        files = html5lib_test_files('tree-construction')
        for filename in files:
            testName = os.path.basename(filename).replace(".dat", "")

            tests = TestData(filename, "data")

            for index, test in enumerate(tests):
                (input, errors, innerHTML, expected) = [
                    test[key] for key in ("data", "errors",
                                          "document-fragment", "document")
                ]
                errors = errors.split("\n")
                yield run_test, innerHTML, input, expected, errors, treeCls
def buildTestSuite():
    for filename in html5lib_test_files('tokenizer', '*.test'):
        tests = json.load(file(filename))
        testName = os.path.basename(filename).replace(".test","")
        if 'tests' in tests:
            for index,test in enumerate(tests['tests']):
                #Skip tests with a self closing flag
                skip = False
                if 'initialStates' not in test:
                    test["initialStates"] = ["Data state"]
                for initialState in test["initialStates"]:
                    test["initialState"] = capitalize(initialState)
                    def testFunc(self, test=test):
                        self.runTokenizerTest(test)
                    testFunc.__doc__ = "\t".join([testName, 
                                                  test['description']])
                    setattr(TestCase, 'test_%s_%d_%s' % (testName, index, test["initialState"]), testFunc)
    return unittest.TestLoader().loadTestsFromTestCase(TestCase)
Beispiel #20
0
def buildTestSuite():
    for filename in html5lib_test_files('tokenizer', '*.test'):
        tests = simplejson.load(open(filename))
        testName = os.path.basename(filename).replace(".test","")
        if 'tests' in tests:
            for index,test in enumerate(tests['tests']):
                #Skip tests with a self closing flag
                skip = False
                if 'contentModelFlags' not in test:
                    test["contentModelFlags"] = ["PCDATA"]
                for contentModelFlag in test["contentModelFlags"]:
                    test["contentModelFlag"] = contentModelFlag
                    def testFunc(self, test=test):
                        self.runTokenizerTest(test)
                    testFunc.__doc__ = "\t".join([testName, 
                                                  test['description']])
                    setattr(TestCase, 'test_%s_%d' % (testName, index), testFunc)
    return unittest.TestLoader().loadTestsFromTestCase(TestCase)
def buildTestSuite():
    sys.stdout.write("Testing tree walkers " + " ".join(treeTypes.keys()) + "\n")

    for treeName, treeCls in treeTypes.iteritems():
        files = html5lib_test_files("tree-construction")
        for filename in files:
            testName = os.path.basename(filename).replace(".dat", "")

            tests = TestData(filename, "data")

            for index, test in enumerate(tests):
                (input, errors, innerHTML, expected) = [
                    test[key] for key in ("data", "errors", "document-fragment", "document")
                ]
                errors = errors.split("\n")

                def testFunc(self, innerHTML=innerHTML, input=input, expected=expected, errors=errors, treeCls=treeCls):
                    self.runTest(innerHTML, input, expected, errors, treeCls)

                setattr(TestCase, "test_%s_%d_%s" % (testName, index + 1, treeName), testFunc)

    return unittest.TestLoader().loadTestsFromTestCase(TestCase)
def buildTestSuite():
    for filename in html5lib_test_files('tokenizer', '*.test'):
        tests = json.load(file(filename))
        testName = os.path.basename(filename).replace(".test", "")
        if 'tests' in tests:
            for index, test in enumerate(tests['tests']):
                #Skip tests with a self closing flag
                skip = False
                if 'initialStates' not in test:
                    test["initialStates"] = ["Data state"]
                for initialState in test["initialStates"]:
                    test["initialState"] = capitalize(initialState)

                    def testFunc(self, test=test):
                        self.runTokenizerTest(test)

                    testFunc.__doc__ = "\t".join(
                        [testName, test['description']])
                    setattr(
                        TestCase, 'test_%s_%d_%s' %
                        (testName, index, test["initialState"]), testFunc)
    return unittest.TestLoader().loadTestsFromTestCase(TestCase)
Beispiel #23
0
def buildTestSuite():
    for filename in html5lib_test_files("encoding"):
        test_name = os.path.basename(filename).replace('.dat',''). \
            replace('-','')
        tests = TestData(filename, "data")
        for idx, test in enumerate(tests):

            def encodingTest(self,
                             data=test['data'],
                             encoding=test['encoding']):
                p = HTMLParser()
                t = p.parse(data, useChardet=False)

                errorMessage = ("Input:\n%s\nExpected:\n%s\nRecieved\n%s\n" %
                                (data, repr(encoding.lower()),
                                 repr(p.tokenizer.stream.charEncoding)))
                self.assertEquals(encoding.lower(),
                                  p.tokenizer.stream.charEncoding[0],
                                  errorMessage)

            setattr(Html5EncodingTestCase, 'test_%s_%d' % (test_name, idx + 1),
                    encodingTest)

    try:
        import chardet

        def test_chardet(self):
            data = open(
                os.path.join(test_dir, "encoding", "chardet",
                             "test_big5.txt")).read()
            encoding = inputstream.HTMLInputStream(data).charEncoding
            assert encoding[0].lower() == "big5"

        setattr(Html5EncodingTestCase, 'test_chardet', test_chardet)
    except ImportError:
        print "chardet not found, skipping chardet tests"

    return unittest.defaultTestLoader.loadTestsFromName(__name__)
Beispiel #24
0
def buildTestSuite():
    for filename in html5lib_test_files("sanitizer"):
        for test in json.load(file(filename)):
          SanitizeTest.addTest('test_' + test['name'], test['output'], test['input'])

    return unittest.TestLoader().loadTestsFromTestCase(SanitizeTest)