Example #1
0
def start_test(odf_handler):
    # Create the 'results' folder
    if vfs.exists('results'):
        vfs.remove('results')
    vfs.make_folder('results')

    # Find test files
    print 'Searching for ODF files...'
    unitests = get_tests()
    unitests = list(unitests)
    nb_tests = len(unitests)
    print 'Number of files found: %d' % nb_tests

    test_number = 0
    msgs_error = []
    for odf_path, po_handler in unitests:
        # Progress bar
        test_number += 1
        progress(test_number, nb_tests)

        # Call ODF handler
        try:
            odf_sources = odf_handler(odf_path)
        except:
            print 'ERROR with test %d / "%s"' % (test_number, odf_path)
            continue

        # Post-process the results
        odf_sources = clean_sources(odf_sources)
        odf_sources = list(set(odf_sources)) # Remove duplicates
        odf_sources.sort()
        # Expected results
        po_sources = [ u''.join(x.source) for x in po_handler.get_units() ]
        po_sources = clean_sources(po_sources)
        po_sources.sort()
        # Check
        if odf_sources == po_sources:
            continue

        # Error. Create a diff report for the current test.
        test_name = odf_path.split('/')[-2]
        filename = 'test_%d_%s.txt' % (test_number, test_name)
        po_path = get_uri_path(po_handler.uri)
        write_diff_file(test_number, filename, odf_path, po_path, odf_sources,
                        po_sources)
        # Inform the user that there where failures
        msgs_error.append('results/%s\n' % filename)

    # Summurarizes the results
    print
    print 'Results:'
    print '--------'
    print '    %s Tests' % nb_tests
    print '    %s Errors' % len(msgs_error)
    print
    if msgs_error:
        stderr.write('Generated error files\n')
        stderr.write('---------------------\n')
        for msg in msgs_error:
            stderr.write(msg)
text = u'The current chapter is: '

paragraph = odf_create_paragraph(text, style=u"Standard")
body.append_element(paragraph)
paragraph.insert_variable(odf_create_chapter_variable(display='number-and-name'),
        u"is: ")


# 11- Filename
# ------------

heading = odf_create_heading(1, text=u'Filename')
body.append_element(heading)

text = u'The current file name is: '

paragraph = odf_create_paragraph(text, style=u"Standard")
body.append_element(paragraph)
paragraph._insert_between(odf_create_filename_variable(), u"The", u"is: ")




# Save
# ----

vfs.make_folder('test_output')
document.save('test_output/use_case2.odt', pretty=True)