예제 #1
0
 def testReadMultisuite(self):
     result = junitxml.read(self.mockresults["multisuite"].filename, "fooname")
     self.assert_(result is not None)
     self.assertEquals(3.0, result.time)
     self.assertEquals(3, result.num_tests)
     self.assertEquals(1, result.num_errors)
     self.assertEquals(1, result.num_failures)
예제 #2
0
def clean_results(test_results_dir, output_dir, filter):
    """
    Read results from test_results_dir and write them into output_dir.
    """
    for d in os.listdir(test_results_dir):
        if filter and d in filter:
            continue
        print("looking at", d)
        test_dir = os.path.join(test_results_dir, d)
        if not os.path.isdir(test_dir):
            continue
        base_test_name = os.path.basename(test_dir)
        # for each test result that a package generated, read it, then
        # rewrite it to our output directory. This will invoke our
        # cleaning rules on the XML that protect the result from Hudson
        # issues.
        for file in os.listdir(test_dir):
            if file.endswith('.xml'):
                test_name = base_test_name + '.' + file[:-4]
            file = os.path.join(test_dir, file)
            try:
                result = junitxml.read(file, test_name)
                output_path = os.path.join(output_dir, "%s.xml"%test_name)
                with open(output_path, 'w') as f:
                    print("re-writing", output_path)
                    f.write(result.xml().encode('utf-8'))
            except Exception as e:
                sys.stderr.write("ignoring [%s]: %s\n"%(file, e))
예제 #3
0
 def testReadNoSuites(self):
     result = junitxml.read(self.mockresults["empty"].filename, "fooname")
     self.assert_(result is not None)
     self.assertEquals(0.0, result.time)
     self.assertEquals(0, result.num_tests)
     self.assertEquals(0, result.num_errors)
     self.assertEquals(0, result.num_failures)
예제 #4
0
 def testReadFail(self):
     result = junitxml.read(self.mockresults["fail1"].filename, "fooname")
     self.assert_(result is not None)
     self.assertEquals(1.0, result.time)
     self.assertEquals(1, result.num_tests)
     self.assertEquals(0, result.num_errors)
     self.assertEquals(1, result.num_failures)
예제 #5
0
 def testReadFail(self):
     result = junitxml.read(self.mockresults['fail1'].filename, 'fooname')
     self.assert_(result is not None)
     self.assertEquals(1.0, result.time)
     self.assertEquals(1, result.num_tests)
     self.assertEquals(0, result.num_errors)
     self.assertEquals(1, result.num_failures)
예제 #6
0
 def testReadMultisuite(self):
     result = junitxml.read(self.mockresults['multisuite'].filename, 'fooname')
     self.assert_(result is not None)
     self.assertEquals(3.0, result.time)
     self.assertEquals(3, result.num_tests)
     self.assertEquals(1, result.num_errors)
     self.assertEquals(1, result.num_failures)
예제 #7
0
 def testReadError(self):
     result = junitxml.read(self.mockresults["err1"].filename, "fooname")
     self.assert_(result is not None)
     self.assertEquals(1.0, result.time)
     self.assertEquals(1, result.num_tests)
     self.assertEquals(1, result.num_errors)
     self.assertEquals(0, result.num_failures)
예제 #8
0
 def testReadNoSuites(self):
     result = junitxml.read(self.mockresults['empty'].filename, 'fooname')
     self.assert_(result is not None)
     self.assertEquals(0.0, result.time)
     self.assertEquals(0, result.num_tests)
     self.assertEquals(0, result.num_errors)
     self.assertEquals(0, result.num_failures)
예제 #9
0
def clean_results(test_results_dir, output_dir, filter):
    """
    Read results from test_results_dir and write them into output_dir.
    """
    for d in os.listdir(test_results_dir):
        if filter and d in filter:
            continue
        print("looking at", d)
        test_dir = os.path.join(test_results_dir, d)
        if not os.path.isdir(test_dir):
            continue
        base_test_name = os.path.basename(test_dir)
        # for each test result that a package generated, read it, then
        # rewrite it to our output directory. This will invoke our
        # cleaning rules on the XML that protect the result from Hudson
        # issues.
        for file in os.listdir(test_dir):
            if file.endswith('.xml'):
                test_name = base_test_name + '.' + file[:-4]
            file = os.path.join(test_dir, file)
            try:
                result = junitxml.read(file, test_name)
                output_path = os.path.join(output_dir, "%s.xml"%test_name)
                with open(output_path, 'w') as f:
                    print("re-writing", output_path)
                    f.write(result.xml().encode('utf-8'))
            except Exception as e:
                sys.stderr.write("ignoring [%s]: %s\n"%(file, e))
예제 #10
0
 def testReadMulticase(self):
     result = junitxml.read(self.mockresults["multicase"].filename, "fooname")
     self.assert_(result is not None)
     self.assertEquals(3.0, result.time)
     self.assertEquals(3, result.num_tests)
     self.assertEquals(1, result.num_errors)
     self.assertEquals(1, result.num_failures)
예제 #11
0
 def testReadEmptySuite(self):
     result = junitxml.read(self.mockresults["emptysuite"].filename, "fooname")
     self.assert_(result is not None)
     self.assertEquals(0.0, result.time)
     self.assertEquals(0, result.num_tests)
     self.assertEquals(0, result.num_errors)
     self.assertEquals(0, result.num_failures)
예제 #12
0
def clean_and_copy_test_results(input_dir,
                                output_dir,
                                errors=None,
                                prefix='dummy'):
    """
    Takes all the xml-formatted Ant JUnit XML test outputs in input_dir and 
    aggregates them into output_dir. In this process, it strips any characters 
    that tend to cause Hudson/Jenkins trouble.
    """

    if os.path.exists(output_dir):
        print "deleting old test results directory", output_dir
        shutil.rmtree(output_dir)
    print "creating new test results directory", output_dir
    os.makedirs(output_dir)

    print "Copy all test results to " + output_dir
    for d in os.listdir(input_dir):
        test_dir = os.path.join(input_dir, d)
        if not os.path.isdir(test_dir):
            continue
        base_test_name = os.path.basename(test_dir)
        # for each test result that a package generated, read it, then
        # rewrite it to our output directory. This will invoke our
        # cleaning rules on the XML that protect the result from Hudson
        # issues.
        for file in os.listdir(test_dir):
            if file.endswith('.xml'):
                test_name = base_test_name + '.' + file[:-4]
            file = os.path.join(test_dir, file)
            try:
                result = junitxml.read(file, test_name)
                output_path = os.path.join(output_dir, "%s.xml" % test_name)
                with open(output_path, 'w') as f:
                    print "re-writing", output_path
                    f.write(result.xml().encode('utf-8'))
            except Exception as e:
                print "ignoring [%s]: %s\n" % (file, e)
                sys.stderr.write("ignoring [%s]: %s\n" % (file, e))

    # create dummy test if no rostest result exists in workspace_test_results_dir
    generate_dummy_test = False
    for root, dirnames, filenames in os.walk(output_dir):
        if len(filenames) == 0:
            generate_dummy_test = True
    if generate_dummy_test:
        print "No test results, so I'll create a dummy test result xml file, with errors %s" % errors
        with open(os.path.join(output_dir, 'dummy.xml'), 'w') as f:
            if errors:
                f.write(
                    '<?xml version="1.0" encoding="UTF-8"?><testsuite tests="1" failures="0" time="1" errors="1" name="%s test"> <testcase name="%s rapport" classname="Results" /><testcase classname="%s_class" name="%sFailure"><error type="%sException">%s</error></testcase></testsuite>'
                    % (prefix, prefix, prefix, prefix, prefix, errors))
            else:
                f.write(
                    '<?xml version="1.0" encoding="UTF-8"?><testsuite tests="1" failures="0" time="1" errors="0" name="dummy test"> <testcase name="dummy rapport" classname="Results" /></testsuite>'
                )
예제 #13
0
def clean_and_copy_test_results(input_dir, output_dir, errors=None, prefix='dummy'):
    """
    Takes all the xml-formatted Ant JUnit XML test outputs in input_dir and 
    aggregates them into output_dir. In this process, it strips any characters 
    that tend to cause Hudson/Jenkins trouble.
    """
    
    if os.path.exists(output_dir):
        print "deleting old test results directory", output_dir
        shutil.rmtree(output_dir)
    print "creating new test results directory", output_dir
    os.makedirs(output_dir)

    print "Copy all test results to " + output_dir
    for d in os.listdir(input_dir):
        test_dir = os.path.join(input_dir, d)
        if not os.path.isdir(test_dir):
            continue
        base_test_name = os.path.basename(test_dir)
        # for each test result that a package generated, read it, then
        # rewrite it to our output directory. This will invoke our
        # cleaning rules on the XML that protect the result from Hudson
        # issues.
        for file in os.listdir(test_dir):
            if file.endswith('.xml'):
                test_name = base_test_name + '.' + file[:-4]
            file = os.path.join(test_dir, file)
            try:
                result = junitxml.read(file, test_name)
                output_path = os.path.join(output_dir, "%s.xml"%test_name)
                with open(output_path, 'w') as f:
                    print "re-writing", output_path
                    f.write(result.xml().encode('utf-8'))
            except Exception as e:
                print "ignoring [%s]: %s\n"%(file, e)
                sys.stderr.write("ignoring [%s]: %s\n"%(file, e))

    # create dummy test if no rostest result exists in workspace_test_results_dir
    generate_dummy_test = False
    for root, dirnames, filenames in os.walk(output_dir):
        if len(filenames) == 0:
            generate_dummy_test = True
    if generate_dummy_test:
        print "No test results, so I'll create a dummy test result xml file, with errors %s" % errors
        with open(os.path.join(output_dir, 'dummy.xml'), 'w') as f:
            if errors:
                f.write('<?xml version="1.0" encoding="UTF-8"?><testsuite tests="1" failures="0" time="1" errors="1" name="%s test"> <testcase name="%s rapport" classname="Results" /><testcase classname="%s_class" name="%sFailure"><error type="%sException">%s</error></testcase></testsuite>' % (prefix, prefix, prefix, prefix, prefix, errors))
            else:
                f.write('<?xml version="1.0" encoding="UTF-8"?><testsuite tests="1" failures="0" time="1" errors="0" name="dummy test"> <testcase name="dummy rapport" classname="Results" /></testsuite>')