Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/builder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_end_root_context(self):

def test_end_nested_context(self):
self.builder.begin_context('testsuite', 'name')
nested = self.builder.current_context()
self.builder.current_context()

self.assertTrue(self.builder.end_context())

Expand Down Expand Up @@ -187,7 +187,7 @@ def test_append_invalid_unicode_cdata_section(self):
self.assertEqual(cdata.data, self.invalid_chars_replace)

def test_append_cdata_closing_tags_into_cdata_section(self):
self.builder.append_cdata_section('tag',']]>')
self.builder.append_cdata_section('tag', ']]>')
self.builder.end_context()
root_child = self.doc.childNodes[0]
cdata_container = root_child.childNodes[0]
Expand Down
2 changes: 1 addition & 1 deletion tests/django_example/app/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.contrib import admin
from django.contrib import admin # NOQA

# Register your models here.
2 changes: 1 addition & 1 deletion tests/django_example/app/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.db import models
from django.db import models # NOQA

# Create your models here.
3 changes: 2 additions & 1 deletion tests/django_example/app/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.test import TestCase


# Create your tests here.
class DummyTestCase(TestCase):
def test_pass(self):
pass
pass
2 changes: 1 addition & 1 deletion tests/django_example/app/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.shortcuts import render
from django.shortcuts import render # NOQA

# Create your views here.
2 changes: 1 addition & 1 deletion tests/django_example/app2/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.contrib import admin
from django.contrib import admin # NOQA

# Register your models here.
2 changes: 1 addition & 1 deletion tests/django_example/app2/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.db import models
from django.db import models # NOQA

# Create your models here.
1 change: 1 addition & 0 deletions tests/django_example/app2/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.test import TestCase


# Create your tests here.
class DummyTestCase(TestCase):
def test_pass(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/django_example/app2/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.shortcuts import render
from django.shortcuts import render # NOQA

# Create your views here.
13 changes: 7 additions & 6 deletions tests/django_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from xmlrunner.unittest import unittest

import sys
import os
from os import path, chdir, getcwd

try:
Expand All @@ -13,8 +12,10 @@

TESTS_DIR = path.dirname(__file__)


@unittest.skipIf(django is None, 'django not found')
class DjangoTest(unittest.TestCase):

def setUp(self):
self._old_cwd = getcwd()
self.project_dir = path.abspath(path.join(TESTS_DIR, 'django_example'))
Expand All @@ -27,30 +28,30 @@ def tearDown(self):
chdir(self._old_cwd)

def _check_runner(self, runner):
suite = runner.build_suite(test_labels=['app2','app'])
test_ids = [ test.id() for test in suite ]
suite = runner.build_suite(test_labels=['app2', 'app'])
test_ids = [test.id() for test in suite]
self.assertEqual(test_ids, [
'app2.tests.DummyTestCase.test_pass',
'app.tests.DummyTestCase.test_pass',
])
suite = runner.build_suite(test_labels=[])
test_ids = [ test.id() for test in suite ]
test_ids = [test.id() for test in suite]
self.assertEqual(set(test_ids), set([
'app.tests.DummyTestCase.test_pass',
'app2.tests.DummyTestCase.test_pass',
]))

def test_django_runner(self):
from django.conf import settings
settings.configure(INSTALLED_APPS=['app','app2'])
settings.configure(INSTALLED_APPS=['app', 'app2'])
runner_class = get_runner(settings)
runner = runner_class()
self._check_runner(runner)

def test_django_xmlrunner(self):
from django.conf import settings
settings.configure(
INSTALLED_APPS=['app','app2'],
INSTALLED_APPS=['app', 'app2'],
TEST_RUNNER='xmlrunner.extra.djangotestrunner.XMLTestRunner')
runner_class = get_runner(settings)
runner = runner_class()
Expand Down
80 changes: 56 additions & 24 deletions tests/testsuite.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,75 @@


class DoctestTest(unittest.TestCase):

def test_doctest_example(self):
suite = doctest.DocTestSuite(tests.doctest_example)
outdir = BytesIO()
stream = StringIO()
runner = xmlrunner.XMLTestRunner(stream=stream, output=outdir, verbosity=0)
runner = xmlrunner.XMLTestRunner(
stream=stream, output=outdir, verbosity=0)
runner.run(suite)
outdir.seek(0)
output = outdir.read()
self.assertIn('classname="tests.doctest_example.Multiplicator" name="threetimes"'
.encode('utf8'), output)
self.assertIn('classname="tests.doctest_example" name="twice"'
.encode('utf8'), output)
self.assertIn('classname="tests.doctest_example.Multiplicator" '
'name="threetimes"'.encode('utf8'), output)
self.assertIn('classname="tests.doctest_example" '
'name="twice"'.encode('utf8'), output)


class XMLTestRunnerTestCase(unittest.TestCase):
"""
XMLTestRunner test case.
"""
class DummyTest(unittest.TestCase):

@unittest.skip("demonstrating skipping")
def test_skip(self):
pass # pragma: no cover

@unittest.skip(u"demonstrating non-ascii skipping: éçà")
def test_non_ascii_skip(self):
pass # pragma: no cover

def test_pass(self):
pass

def test_fail(self):
self.assertTrue(False)

@unittest.expectedFailure
def test_expected_failure(self):
self.assertTrue(False)

@unittest.expectedFailure
def test_unexpected_success(self):
pass

def test_error(self):
1 / 0

def test_cdata_section(self):
print('<![CDATA[content]]>')

def test_non_ascii_error(self):
self.assertEqual(u"éçà", 42)

def test_unsafe_unicode(self):
print(u"A\x00B\x08C\x0BD\x0C")

def test_runner_buffer_output_pass(self):
print('should not be printed')

def test_runner_buffer_output_fail(self):
print('should be printed')
self.fail('expected to fail')

def test_non_ascii_runner_buffer_output_fail(self):
print(u'Where is the café ?')
self.fail(u'The café could not be found')

class DummySubTest(unittest.TestCase):

def test_subTest_pass(self):
for i in range(2):
with self.subTest(i=i):
Expand All @@ -82,13 +98,16 @@ def test_subTest_fail(self):
self.fail('this is a subtest.')

class DummyErrorInCallTest(unittest.TestCase):

def __call__(self, result):
try:
raise Exception('Massive fail')
except Exception:
result.addError(self, sys.exc_info())
return
super(DummyErrorInCallTest, self).__call__(result)
super(XMLTestRunnerTestCase.DummyErrorInCallTest, self)\
.__call__(result)

def test_pass(self):
pass

Expand All @@ -107,7 +126,7 @@ def _test_xmlrunner(self, suite, runner=None):
if runner is None:
runner = xmlrunner.XMLTestRunner(
stream=stream, output=outdir, verbosity=verbosity,
**self.runner_kwargs)
**runner_kwargs)
self.assertEqual(0, len(glob(os.path.join(outdir, '*xml'))))
runner.run(suite)
self.assertEqual(1, len(glob(os.path.join(outdir, '*xml'))))
Expand All @@ -129,14 +148,17 @@ def test_classnames(self):
suite.addTest(self.DummySubTest('test_subTest_pass'))
outdir = BytesIO()
stream = StringIO()
runner = xmlrunner.XMLTestRunner(stream=stream, output=outdir, verbosity=0)
runner = xmlrunner.XMLTestRunner(
stream=stream, output=outdir, verbosity=0)
runner.run(suite)
outdir.seek(0)
output = outdir.read()
self.assertIn('classname="tests.testsuite.DummyTest" name="test_pass"'
.encode('utf8'), output)
self.assertIn('classname="tests.testsuite.DummySubTest" name="test_subTest_pass"'
.encode('utf8'), output)
self.assertIn('classname="tests.testsuite.DummyTest" '
'name="test_pass"'.encode('utf8'),
output)
self.assertIn('classname="tests.testsuite.DummySubTest" '
'name="test_subTest_pass"'.encode('utf8'),
output)

def test_xmlrunner_non_ascii(self):
suite = unittest.TestSuite()
Expand All @@ -150,7 +172,8 @@ def test_xmlrunner_non_ascii(self):
outdir.seek(0)
output = outdir.read()
self.assertIn(
u'<skipped message="demonstrating non-ascii skipping: éçà" type="skip"/>'.encode('utf8'),
u'<skipped message="demonstrating non-ascii skipping: éçà" '
u'type="skip"/>'.encode('utf8'),
output)

def test_xmlrunner_safe_xml_encoding_name(self):
Expand All @@ -166,29 +189,33 @@ def test_xmlrunner_safe_xml_encoding_name(self):
firstline = output.splitlines()[0]
# test for issue #74
self.assertIn('encoding="UTF-8"'.encode('utf8'), firstline)

def test_xmlrunner_check_for_valid_xml_streamout(self):
"""
This test checks if the xml document is valid if there are more than
one testsuite and the output of the report is a single stream.
"""
class DummyTestA(unittest.TestCase):

def test_pass(self):
pass

class DummyTestB(unittest.TestCase):

def test_pass(self):
pass

suite = unittest.TestSuite()
suite.addTest( unittest.TestLoader().loadTestsFromTestCase(DummyTestA) );
suite.addTest( unittest.TestLoader().loadTestsFromTestCase(DummyTestB) );
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(DummyTestA))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(DummyTestB))
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()
# Finally check if we have a valid XML document or not.
# Finally check if we have a valid XML document or not.
try:
minidom.parseString(output)
except Exception as e:
Expand All @@ -204,11 +231,13 @@ def test_xmlrunner_unsafe_unicode(self):
runner.run(suite)
outdir.seek(0)
output = outdir.read()
self.assertIn(u"<![CDATA[ABCD\n]]>".encode('utf8'), output)
self.assertIn(u"<![CDATA[ABCD\n]]>".encode('utf8'),
output)

def test_xmlrunner_non_ascii_failures(self):
suite = unittest.TestSuite()
suite.addTest(self.DummyTest('test_non_ascii_runner_buffer_output_fail'))
suite.addTest(self.DummyTest(
'test_non_ascii_runner_buffer_output_fail'))
outdir = BytesIO()
runner = xmlrunner.XMLTestRunner(
stream=self.stream, output=outdir, verbosity=self.verbosity,
Expand Down Expand Up @@ -243,8 +272,8 @@ def test_xmlrunner_buffer_output_fail(self):
testsuite_output = self.stream.getvalue()
self.assertIn('should be printed', testsuite_output)

@unittest.skipIf(not hasattr(unittest.TestCase,'subTest'),
'unittest.TestCase.subTest not present.')
@unittest.skipIf(not hasattr(unittest.TestCase, 'subTest'),
'unittest.TestCase.subTest not present.')
def test_unittest_subTest_fail(self):
# test for issue #77
outdir = BytesIO()
Expand All @@ -265,7 +294,8 @@ def test_unittest_subTest_fail(self):
b'name="test_subTest_fail (i=1)"',
output)

@unittest.skipIf(not hasattr(unittest.TestCase, 'subTest'), 'unittest.TestCase.subTest not present.')
@unittest.skipIf(not hasattr(unittest.TestCase, 'subTest'),
'unittest.TestCase.subTest not present.')
def test_unittest_subTest_pass(self):
# Test for issue #85
suite = unittest.TestSuite()
Expand All @@ -283,7 +313,8 @@ def test_xmlrunner_failfast(self):
suite.addTest(self.DummyTest('test_pass'))
outdir = BytesIO()
runner = xmlrunner.XMLTestRunner(
stream=self.stream, output=outdir, verbosity=self.verbosity, failfast=True,
stream=self.stream, output=outdir,
verbosity=self.verbosity, failfast=True,
**self.runner_kwargs)
runner.run(suite)
outdir.seek(0)
Expand Down Expand Up @@ -348,7 +379,8 @@ def test_junitxml_xsd_validation_order(self):
i_system_out = output.index('<system-out>'.encode('utf8'))
i_system_err = output.index('<system-err>'.encode('utf8'))
i_testcase = output.index('<testcase'.encode('utf8'))
self.assertTrue(i_properties < i_testcase < i_system_out < i_system_err)
self.assertTrue(i_properties < i_testcase <
i_system_out < i_system_err)

def test_junitxml_xsd_validation_empty_properties(self):
suite = unittest.TestSuite()
Expand Down