Example #1
0
 def test_toxml_must_escape_its_content(self):
     ts_origin = 1401278400
     test_a = Report(
         '<a-test>', start_ts=ts_origin+0, end_ts=ts_origin+1, src_location='<"world">'
     )
     test_a.errors.append('<a solid piece of "content">')
     test_b = Report(
         '<b-test>', start_ts=ts_origin+0, end_ts=ts_origin+1, src_location='<"world">'
     )
     test_b.errors.append('<a "solid" piece of content>')
     xunit_result = toxml([test_a, test_b], 'escape-tests', 'test-hostname')
     validate_schema(xunit_result)
Example #2
0
    def test_toxml(self):
        ts_origin = 1401278400
        test_a = Report(
            'a-test', start_ts=ts_origin+0, end_ts=ts_origin+1, src_location='foo'
        )
        test_b = Report(
            'b-test', start_ts=ts_origin+3, end_ts=ts_origin+5,
            src_location=os.path.join(
                'this', 'is', 'a', 'bar').replace(os.sep, '.')
        )
        test_c = Report(
            'c-test', start_ts=ts_origin+3, end_ts=ts_origin+5,
            src_location=os.path.join(
                'this', 'is', 'a', 'baz').replace(os.sep, '.')
        )

        test_a.errors.append('this is an error')
        test_a.failures.append('this is a failure')
        test_b.errors.append('this is an error 2')
        test_b.errors.append('this is another error in the same test')

        test_reports = [test_a, test_b, test_c]

        xunit_reference = """<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite errors="2" failures="1" hostname="test-hostname" id="0" name="tests" package="pkg" tests="3" time="5.000000" timestamp="%s">
        <testcase classname="foo" name="a-test" time="1.000000">
            <failure message="this is a failure" type="exception" />
        </testcase>
        <testcase classname="this.is.a.bar" name="b-test" time="2.000000">
            <error message="this is an error 2&#10;this is another error in the same test" type="exception" />
        </testcase>
        <testcase classname="this.is.a.baz" name="c-test" time="2.000000"/>
    </testsuite>
</testsuites>
""" % datetime.fromtimestamp(ts_origin+0).isoformat()

        def xmlnorm(xmlstring):
            et = ET.fromstring(xmlstring)
            for e in [et] + et.findall('.//'):
                if e.tail is not None:
                    e.tail = e.tail.strip(' \t\n\r')
                if e.text is not None:
                    e.text = e.text.strip(' \t\n\r')

            return ET.tostring(et)

        xunit_result = toxml(
            test_reports, 'tests', hostname='test-hostname', package_name='pkg',
        )
        print(xunit_result)
        self.assertEquals(xmlnorm(xunit_reference), xmlnorm(xunit_result))
        validate_schema(xunit_result)
Example #3
0
 def test_toxml_can_accept_absent_package_name(self):
     ts_origin = 1401278400
     test_a = Report(
         '<a-test>', start_ts=ts_origin+0, end_ts=ts_origin+1, src_location=''
     )
     xunit_result = toxml([test_a], 'unicode-tests', 'test-hostname', package_name=None)
     validate_schema(xunit_result)
Example #4
0
 def test_toxml_must_accept_unicode(self):
     ts_origin = 1401278400
     test_a = Report(
         '<a-test>', start_ts=ts_origin+0, end_ts=ts_origin+1, src_location=u'\u4e16\u754c'
     )
     xunit_result = toxml([test_a], 'unicode-tests', 'test-hostname')
     validate_schema(xunit_result)
 def test_write_reports(self):
     ts_origin = 1401278400
     path = self.destination.write_reports(
         'hello', 'a-suite',
         [Report('a-case', start_ts=ts_origin + 0, end_ts=ts_origin + 0)])
     assert os.path.isfile(path)
     self.destination.check()
     self.assertRaises(ValueError, self.destination.reserve_file, 'hello')
Example #6
0
    def test_toxml_has_optional_parameters(self):
        reports = [Report('a-test', start_ts=0, end_ts=1, src_location='foo')]

        xunit_result = toxml(
            reports,
            'suite-name',
        )
        validate_schema(xunit_result)