コード例 #1
0
def run_filename(filename):
    f = open(filename)
    content = f.read()
    f.close()
    parts = re.split(r"---*", content)
    template = parts[0]
    expected = parts[1]
    if len(parts) == 3:
        data_content = parts[2].strip()
    elif len(parts) > 3:
        print parts[3:]
        assert 0, "Too many sections"
    else:
        data_content = ""
    namespace = {}
    if data_content:
        exec data_content in namespace
    data = namespace.copy()
    data["defaults"] = data.get("defaults", {})
    if data.has_key("check"):
        checker = data["check"]
        del data["check"]
    else:

        def checker(p, s):
            pass

    for name in data.keys():
        if name.startswith("_") or hasattr(__builtin__, name):
            del data[name]
    listener = htmlfill_schemabuilder.SchemaBuilder()
    p = htmlfill.FillingParser(listener=listener, **data)
    p.feed(template)
    p.close()
    output = p.text()

    def reporter(v):
        print v

    try:
        output_xml = ET.XML(output)
        expected_xml = ET.XML(expected)
    except ExpatError:
        comp = output.strip() == expected.strip()
    else:
        comp = xml_compare(output_xml, expected_xml, reporter)
    if not comp:
        print "---- Output:   ----"
        print output
        print "---- Expected: ----"
        print expected
        assert 0
    checker(p, listener.schema())
    checker(p, htmlfill_schemabuilder.parse_schema(template))
コード例 #2
0
def run_filename(filename):
    f = open(filename)
    content = f.read()
    f.close()
    parts = re.split(r'---*', content)
    template = parts[0]
    expected = parts[1]
    if len(parts) == 3:
        data_content = parts[2].strip()
    elif len(parts) > 3:
        assert False, "Too many sections: %s" % parts[3:]
    else:
        data_content = ''
    namespace = {}
    if data_content:
        exec data_content in namespace
    data = namespace.copy()
    data['defaults'] = data.get('defaults', {})
    if 'check' in data:
        checker = data.pop('check')
    else:

        def checker(p, s):
            pass

    for name in data.keys():
        if name.startswith('_') or hasattr('__builtin__', name):
            del data[name]
    listener = htmlfill_schemabuilder.SchemaBuilder()
    p = htmlfill.FillingParser(listener=listener, **data)
    p.feed(template)
    p.close()
    output = p.text()

    def reporter(v):
        print v

    try:
        output_xml = ET.XML(output)
        expected_xml = ET.XML(expected)
    except XMLParseError:
        comp = output.strip() == expected.strip()
    else:
        comp = xml_compare(output_xml, expected_xml, reporter)
    if not comp:
        print '---- Output:   ----'
        print output
        print '---- Expected: ----'
        print expected
        assert False
    checker(p, listener.schema())
    checker(p, htmlfill_schemabuilder.parse_schema(template))
コード例 #3
0
def run_filename(filename):
    f = open(filename)
    content = f.read()
    f.close()
    parts = re.split(r"---*", content)
    template = parts[0]
    expected = parts[1]
    if len(parts) == 3:
        data_content = parts[2].strip()
    elif len(parts) > 3:
        assert False, "Too many sections: %s" % parts[3:]
    else:
        data_content = ""
    namespace = {}
    if data_content:
        six.exec_(data_content, namespace)
    data = namespace.copy()
    data["defaults"] = data.get("defaults", {})
    if "check" in data:
        checker = data.pop("check")
    else:

        def checker(p, s):
            pass

    for name in list(data.keys()):
        if name.startswith("_") or hasattr("__builtin__", name):
            del data[name]
    listener = htmlfill_schemabuilder.SchemaBuilder()
    p = htmlfill.FillingParser(listener=listener, **data)
    p.feed(template)
    p.close()
    output = p.text()

    def reporter(v):
        print(v)

    try:
        output_xml = ET.XML(output)
        expected_xml = ET.XML(expected)
    except XMLParseError:
        comp = output.strip() == expected.strip()
    else:
        comp = xml_compare(output_xml, expected_xml, reporter)
    if not comp:
        print("---- Output:   ----")
        print(output)
        print("---- Expected: ----")
        print(expected)
        assert False
    checker(p, listener.schema())
    checker(p, htmlfill_schemabuilder.parse_schema(template))
コード例 #4
0
ファイル: test_htmlfill.py プロジェクト: avanov/formencode
def run_filename(filename):
    f = open(filename)
    content = f.read()
    f.close()
    parts = re.split(r'---*', content)
    template = parts[0]
    expected = parts[1]
    if len(parts) == 3:
        data_content = parts[2].strip()
    elif len(parts) > 3:
        assert False, "Too many sections: %s" % parts[3:]
    else:
        data_content = ''
    namespace = {}
    if data_content:
        exec data_content in namespace
    data = namespace.copy()
    data['defaults'] = data.get('defaults', {})
    if 'check' in data:
        checker = data.pop('check')
    else:
        def checker(p, s):
            pass
    for name in data.keys():
        if name.startswith('_') or hasattr('__builtin__', name):
            del data[name]
    listener = htmlfill_schemabuilder.SchemaBuilder()
    p = htmlfill.FillingParser(listener=listener, **data)
    p.feed(template)
    p.close()
    output = p.text()

    def reporter(v):
        print v

    try:
        output_xml = ET.XML(output)
        expected_xml = ET.XML(expected)
    except XMLParseError:
        comp = output.strip() == expected.strip()
    else:
        comp = xml_compare(output_xml, expected_xml, reporter)
    if not comp:
        print '---- Output:   ----'
        print output
        print '---- Expected: ----'
        print expected
        assert False
    checker(p, listener.schema())
    checker(p, htmlfill_schemabuilder.parse_schema(template))