/functional_tests/test_xunit.py

https://bitbucket.org/jpellerin/nose/ · Python · 61 lines · 46 code · 10 blank · 5 comment · 2 complexity · a93234b7497a9617265073ed75102ecb MD5 · raw file

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