2009-12-14 01:08:36 +08:00
|
|
|
"""
|
|
|
|
Tests for django test runner
|
|
|
|
"""
|
|
|
|
import StringIO
|
2010-10-11 20:55:17 +08:00
|
|
|
|
2010-12-05 08:44:34 +08:00
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
2009-12-22 14:00:57 +08:00
|
|
|
from django.test import simple
|
2010-10-11 20:55:17 +08:00
|
|
|
from django.utils import unittest
|
2009-12-22 14:00:57 +08:00
|
|
|
|
|
|
|
class DjangoTestRunnerTests(unittest.TestCase):
|
2009-12-14 01:08:36 +08:00
|
|
|
|
|
|
|
def test_failfast(self):
|
2009-12-22 14:00:57 +08:00
|
|
|
class MockTestOne(unittest.TestCase):
|
2009-12-14 01:08:36 +08:00
|
|
|
def runTest(self):
|
|
|
|
assert False
|
2009-12-22 14:00:57 +08:00
|
|
|
class MockTestTwo(unittest.TestCase):
|
2009-12-14 01:08:36 +08:00
|
|
|
def runTest(self):
|
|
|
|
assert False
|
2009-12-22 14:00:57 +08:00
|
|
|
|
2009-12-14 01:08:36 +08:00
|
|
|
suite = unittest.TestSuite([MockTestOne(), MockTestTwo()])
|
|
|
|
mock_stream = StringIO.StringIO()
|
|
|
|
dtr = simple.DjangoTestRunner(verbosity=0, failfast=False, stream=mock_stream)
|
|
|
|
result = dtr.run(suite)
|
|
|
|
self.assertEqual(2, result.testsRun)
|
|
|
|
self.assertEqual(2, len(result.failures))
|
2009-12-22 14:00:57 +08:00
|
|
|
|
2009-12-14 01:08:36 +08:00
|
|
|
dtr = simple.DjangoTestRunner(verbosity=0, failfast=True, stream=mock_stream)
|
|
|
|
result = dtr.run(suite)
|
|
|
|
self.assertEqual(1, result.testsRun)
|
|
|
|
self.assertEqual(1, len(result.failures))
|
2010-12-05 08:44:34 +08:00
|
|
|
|
|
|
|
class DependencyOrderingTests(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_simple_dependencies(self):
|
|
|
|
raw = [
|
|
|
|
('s1', ['alpha']),
|
|
|
|
('s2', ['bravo']),
|
|
|
|
('s3', ['charlie']),
|
|
|
|
]
|
|
|
|
dependencies = {
|
|
|
|
'alpha': ['charlie'],
|
|
|
|
'bravo': ['charlie'],
|
|
|
|
}
|
|
|
|
|
|
|
|
ordered = simple.dependency_ordered(raw, dependencies=dependencies)
|
|
|
|
ordered_sigs = [sig for sig,aliases in ordered]
|
|
|
|
|
|
|
|
self.assertIn('s1', ordered_sigs)
|
|
|
|
self.assertIn('s2', ordered_sigs)
|
|
|
|
self.assertIn('s3', ordered_sigs)
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s1'))
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s2'))
|
|
|
|
|
|
|
|
def test_chained_dependencies(self):
|
|
|
|
raw = [
|
|
|
|
('s1', ['alpha']),
|
|
|
|
('s2', ['bravo']),
|
|
|
|
('s3', ['charlie']),
|
|
|
|
]
|
|
|
|
dependencies = {
|
|
|
|
'alpha': ['bravo'],
|
|
|
|
'bravo': ['charlie'],
|
|
|
|
}
|
|
|
|
|
|
|
|
ordered = simple.dependency_ordered(raw, dependencies=dependencies)
|
|
|
|
ordered_sigs = [sig for sig,aliases in ordered]
|
|
|
|
|
|
|
|
self.assertIn('s1', ordered_sigs)
|
|
|
|
self.assertIn('s2', ordered_sigs)
|
|
|
|
self.assertIn('s3', ordered_sigs)
|
|
|
|
|
|
|
|
# Explicit dependencies
|
|
|
|
self.assertLess(ordered_sigs.index('s2'), ordered_sigs.index('s1'))
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s2'))
|
|
|
|
|
|
|
|
# Implied dependencies
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s1'))
|
|
|
|
|
|
|
|
def test_multiple_dependencies(self):
|
|
|
|
raw = [
|
|
|
|
('s1', ['alpha']),
|
|
|
|
('s2', ['bravo']),
|
|
|
|
('s3', ['charlie']),
|
|
|
|
('s4', ['delta']),
|
|
|
|
]
|
|
|
|
dependencies = {
|
|
|
|
'alpha': ['bravo','delta'],
|
|
|
|
'bravo': ['charlie'],
|
|
|
|
'delta': ['charlie'],
|
|
|
|
}
|
|
|
|
|
|
|
|
ordered = simple.dependency_ordered(raw, dependencies=dependencies)
|
|
|
|
ordered_sigs = [sig for sig,aliases in ordered]
|
|
|
|
|
|
|
|
self.assertIn('s1', ordered_sigs)
|
|
|
|
self.assertIn('s2', ordered_sigs)
|
|
|
|
self.assertIn('s3', ordered_sigs)
|
|
|
|
self.assertIn('s4', ordered_sigs)
|
|
|
|
|
|
|
|
# Explicit dependencies
|
|
|
|
self.assertLess(ordered_sigs.index('s2'), ordered_sigs.index('s1'))
|
|
|
|
self.assertLess(ordered_sigs.index('s4'), ordered_sigs.index('s1'))
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s2'))
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s4'))
|
|
|
|
|
|
|
|
# Implicit dependencies
|
|
|
|
self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s1'))
|
|
|
|
|
|
|
|
def test_circular_dependencies(self):
|
|
|
|
raw = [
|
|
|
|
('s1', ['alpha']),
|
|
|
|
('s2', ['bravo']),
|
|
|
|
]
|
|
|
|
dependencies = {
|
|
|
|
'bravo': ['alpha'],
|
|
|
|
'alpha': ['bravo'],
|
|
|
|
}
|
|
|
|
|
|
|
|
self.assertRaises(ImproperlyConfigured, simple.dependency_ordered, raw, dependencies=dependencies)
|
|
|
|
|