/functional_tests/test_xunit.py
Python | 61 lines | 46 code | 10 blank | 5 comment | 14 complexity | a93234b7497a9617265073ed75102ecb MD5 | raw file
1# -*- coding: utf-8 -*- 2import codecs 3import os 4import sys 5import unittest 6from nose.plugins.xunit import Xunit 7from nose.plugins.skip import Skip 8from nose.plugins import PluginTester 9 10support = os.path.join(os.path.dirname(__file__), 'support') 11xml_results_filename = os.path.join(support, "xunit.xml") 12 13# the plugin is tested better in unit tests. 14# this is just here for a sanity check 15 16class TestXUnitPlugin(PluginTester, unittest.TestCase): 17 activate = '--with-xunit' 18 args = ['-v','--xunit-file=%s' % xml_results_filename] 19 plugins = [Xunit(), Skip()] 20 suitepath = os.path.join(support, 'xunit') 21 22 def runTest(self): 23 print str(self.output) 24 25 assert "ERROR: test_error" in self.output 26 assert "FAIL: test_fail" in self.output 27 assert "test_skip (test_xunit_as_suite.TestForXunit) ... SKIP: skipit" in self.output 28 assert "XML: %s" % xml_results_filename in self.output 29 30 f = codecs.open(xml_results_filename,'r', encoding='utf8') 31 result = f.read() 32 f.close() 33 print result.encode('utf8', 'replace') 34 35 assert '<?xml version="1.0" encoding="UTF-8"?>' in result 36 assert '<testsuite name="nosetests" tests="6" errors="2" failures="1" skip="1">' in result 37 assert '<testcase classname="test_xunit_as_suite.TestForXunit" name="test_error" time="' in result 38 # TODO(Kumar) think of better x-platform code here that 39 # does not confuse 2to3 40 if sys.version_info[0:2] >= (3,0): 41 assert ('<error type="%s.Exception" message="日本">' % (Exception.__module__,)) in result 42 else: 43 assert ('<error type="%s.Exception" message="日本">' % (Exception.__module__,)).decode('utf8') in result 44 assert '</testcase>' in result 45 assert '</testsuite>' in result 46 47 48class TestIssue279(PluginTester, unittest.TestCase): 49 activate = '--with-xunit' 50 args = ['-v','--xunit-file=%s' % xml_results_filename] 51 plugins = [Xunit(), Skip()] 52 suitepath = os.path.join(support, 'issue279') 53 54 def runTest(self): 55 print str(self.output) 56 f = open(xml_results_filename,'r') 57 result = f.read() 58 f.close() 59 print result 60 assert 'tests="1" errors="1" failures="0" skip="0"' in result 61 assert "Exception: I would prefer not to" in result