示例#1
0
    def test_xunit_plugin_transform(self):
        suite = unittest.TestSuite()
        suite.addTest(self.DummyTest('test_fail'))
        suite.addTest(self.DummyTest('test_pass'))
        suite.properties = None
        outdir = BytesIO()
        runner = xmlrunner.XMLTestRunner(
            stream=self.stream, output=outdir, verbosity=self.verbosity,
            **self.runner_kwargs)
        runner.run(suite)
        outdir.seek(0)
        output = outdir.read()

        validate_junit_report('14c6e39c38408b9ed6280361484a13c6f5becca7', output)
        with self.assertRaises(etree.DocumentInvalid):
            validate_junit_report('ae25da5089d4f94ac6c4669bf736e4d416cc4665', output)

        from xmlrunner.extra.xunit_plugin import transform
        transformed = transform(output)
        validate_junit_report('14c6e39c38408b9ed6280361484a13c6f5becca7', transformed)
        validate_junit_report('ae25da5089d4f94ac6c4669bf736e4d416cc4665', transformed)
        self.assertIn('test_pass'.encode('utf8'), transformed)
        self.assertIn('test_fail'.encode('utf8'), transformed)
        if not without_fastseq_opt:
            import fastseq  #pylint: disable=import-outside-toplevel
        import pytest  #pylint: disable=import-outside-toplevel
        self.prepare_env()
        os.chdir(TRANSFORMERS_PATH)
        blocked_tests_string = (' and '.join(
            [' not ' + test for test in blocked_tests]))
        exit_code = pytest.main(
            ['-sv', '-k' + blocked_tests_string, './tests/'])
        assert str(exit_code).strip() == 'ExitCode.OK'


if __name__ == "__main__":
    log_xml_dir = os.getenv('FASTSEQ_UNITTEST_LOG_XML_DIR',
                            os.path.join(os.getcwd(), 'tests', 'log_xml'))
    os.makedirs(log_xml_dir, exist_ok=True)
    suffix = '_' + time.strftime("%Y%m%d%H%M%S") + '.xml'
    log_xml_file = __file__.replace(os.sep, '_').replace('.py', suffix)
    log_xml_file = os.path.join(log_xml_dir, log_xml_file)

    out = io.BytesIO()
    unittest.main(testRunner=xmlrunner.XMLTestRunner(output=out),
                  failfast=False,
                  buffer=False,
                  catchbreak=False,
                  exit=False)
    with open(log_xml_file, 'wb') as report:
        report.write(transform(out.getvalue()))
        print("Save the log of transformers unit tests into %s" %
              (log_xml_file))