PageRenderTime 113ms CodeModel.GetById 40ms app.highlight 13ms RepoModel.GetById 58ms app.codeStats 0ms

/tests/regressiontests/test_runner/tests.py

https://code.google.com/p/mango-py/
Python | 120 lines | 91 code | 22 blank | 7 comment | 6 complexity | 2090879282edab3543ae017670acf688 MD5 | raw file
  1"""
  2Tests for django test runner
  3"""
  4import StringIO
  5
  6from django.core.exceptions import ImproperlyConfigured
  7from django.test import simple
  8from django.utils import unittest
  9
 10class DjangoTestRunnerTests(unittest.TestCase):
 11
 12    def test_failfast(self):
 13        class MockTestOne(unittest.TestCase):
 14            def runTest(self):
 15                assert False
 16        class MockTestTwo(unittest.TestCase):
 17            def runTest(self):
 18                assert False
 19
 20        suite = unittest.TestSuite([MockTestOne(), MockTestTwo()])
 21        mock_stream = StringIO.StringIO()
 22        dtr = simple.DjangoTestRunner(verbosity=0, failfast=False, stream=mock_stream)
 23        result = dtr.run(suite)
 24        self.assertEqual(2, result.testsRun)
 25        self.assertEqual(2, len(result.failures))
 26
 27        dtr = simple.DjangoTestRunner(verbosity=0, failfast=True, stream=mock_stream)
 28        result = dtr.run(suite)
 29        self.assertEqual(1, result.testsRun)
 30        self.assertEqual(1, len(result.failures))
 31
 32class DependencyOrderingTests(unittest.TestCase):
 33
 34    def test_simple_dependencies(self):
 35        raw = [
 36            ('s1', ('s1_db', ['alpha'])),
 37            ('s2', ('s2_db', ['bravo'])),
 38            ('s3', ('s3_db', ['charlie'])),
 39        ]
 40        dependencies = {
 41            'alpha': ['charlie'],
 42            'bravo': ['charlie'],
 43        }
 44
 45        ordered = simple.dependency_ordered(raw, dependencies=dependencies)
 46        ordered_sigs = [sig for sig,value in ordered]
 47
 48        self.assertIn('s1', ordered_sigs)
 49        self.assertIn('s2', ordered_sigs)
 50        self.assertIn('s3', ordered_sigs)
 51        self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s1'))
 52        self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s2'))
 53
 54    def test_chained_dependencies(self):
 55        raw = [
 56            ('s1', ('s1_db', ['alpha'])),
 57            ('s2', ('s2_db', ['bravo'])),
 58            ('s3', ('s3_db', ['charlie'])),
 59        ]
 60        dependencies = {
 61            'alpha': ['bravo'],
 62            'bravo': ['charlie'],
 63        }
 64
 65        ordered = simple.dependency_ordered(raw, dependencies=dependencies)
 66        ordered_sigs = [sig for sig,value in ordered]
 67
 68        self.assertIn('s1', ordered_sigs)
 69        self.assertIn('s2', ordered_sigs)
 70        self.assertIn('s3', ordered_sigs)
 71
 72        # Explicit dependencies
 73        self.assertLess(ordered_sigs.index('s2'), ordered_sigs.index('s1'))
 74        self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s2'))
 75
 76        # Implied dependencies
 77        self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s1'))
 78
 79    def test_multiple_dependencies(self):
 80        raw = [
 81            ('s1', ('s1_db', ['alpha'])),
 82            ('s2', ('s2_db', ['bravo'])),
 83            ('s3', ('s3_db', ['charlie'])),
 84            ('s4', ('s4_db', ['delta'])),
 85        ]
 86        dependencies = {
 87            'alpha': ['bravo','delta'],
 88            'bravo': ['charlie'],
 89            'delta': ['charlie'],
 90        }
 91
 92        ordered = simple.dependency_ordered(raw, dependencies=dependencies)
 93        ordered_sigs = [sig for sig,aliases in ordered]
 94
 95        self.assertIn('s1', ordered_sigs)
 96        self.assertIn('s2', ordered_sigs)
 97        self.assertIn('s3', ordered_sigs)
 98        self.assertIn('s4', ordered_sigs)
 99
100        # Explicit dependencies
101        self.assertLess(ordered_sigs.index('s2'), ordered_sigs.index('s1'))
102        self.assertLess(ordered_sigs.index('s4'), ordered_sigs.index('s1'))
103        self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s2'))
104        self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s4'))
105
106        # Implicit dependencies
107        self.assertLess(ordered_sigs.index('s3'), ordered_sigs.index('s1'))
108
109    def test_circular_dependencies(self):
110        raw = [
111            ('s1', ('s1_db', ['alpha'])),
112            ('s2', ('s2_db', ['bravo'])),
113        ]
114        dependencies = {
115            'bravo': ['alpha'],
116            'alpha': ['bravo'],
117        }
118
119        self.assertRaises(ImproperlyConfigured, simple.dependency_ordered, raw, dependencies=dependencies)
120