summaryrefslogtreecommitdiff
path: root/tests/test_discovery_sample
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-04-12 11:42:06 +0200
committerClaude Paroz <claude@2xlibre.net>2014-04-12 11:42:06 +0200
commit3e3a7372f58e005813dd1b9e61eb85a5e43c7173 (patch)
treebbd9a3b6c3bfdd42b725dd1c0db0b040c04d783d /tests/test_discovery_sample
parent476db08b1600be76adc5da539c6f7c0603d47ee5 (diff)
Fixed #22102 -- Made SimpleTestCase tests run before unittest.TestCase ones
Thanks aptiko for the reporti and Tim Graham for the review.
Diffstat (limited to 'tests/test_discovery_sample')
-rw-r--r--tests/test_discovery_sample/doctests.py45
-rw-r--r--tests/test_discovery_sample/tests_sample.py17
2 files changed, 61 insertions, 1 deletions
diff --git a/tests/test_discovery_sample/doctests.py b/tests/test_discovery_sample/doctests.py
new file mode 100644
index 0000000000..3d228c6efb
--- /dev/null
+++ b/tests/test_discovery_sample/doctests.py
@@ -0,0 +1,45 @@
+"""
+Doctest example from the official Python documentation.
+https://docs.python.org/3/library/doctest.html
+"""
+
+def factorial(n):
+ """Return the factorial of n, an exact integer >= 0.
+
+ >>> [factorial(n) for n in range(6)]
+ [1, 1, 2, 6, 24, 120]
+ >>> factorial(30)
+ 265252859812191058636308480000000
+ >>> factorial(-1)
+ Traceback (most recent call last):
+ ...
+ ValueError: n must be >= 0
+
+ Factorials of floats are OK, but the float must be an exact integer:
+ >>> factorial(30.1)
+ Traceback (most recent call last):
+ ...
+ ValueError: n must be exact integer
+ >>> factorial(30.0)
+ 265252859812191058636308480000000
+
+ It must also not be ridiculously large:
+ >>> factorial(1e100)
+ Traceback (most recent call last):
+ ...
+ OverflowError: n too large
+ """
+
+ import math
+ if not n >= 0:
+ raise ValueError("n must be >= 0")
+ if math.floor(n) != n:
+ raise ValueError("n must be exact integer")
+ if n+1 == n: # catch a value like 1e300
+ raise OverflowError("n too large")
+ result = 1
+ factor = 2
+ while factor <= n:
+ result *= factor
+ factor += 1
+ return result
diff --git a/tests/test_discovery_sample/tests_sample.py b/tests/test_discovery_sample/tests_sample.py
index d538771b0f..eb977e44fb 100644
--- a/tests/test_discovery_sample/tests_sample.py
+++ b/tests/test_discovery_sample/tests_sample.py
@@ -1,6 +1,9 @@
+import doctest
from unittest import TestCase
-from django.test import TestCase as DjangoTestCase
+from django.test import SimpleTestCase, TestCase as DjangoTestCase
+
+from . import doctests
class TestVanillaUnittest(TestCase):
@@ -15,5 +18,17 @@ class TestDjangoTestCase(DjangoTestCase):
self.assertEqual(1, 1)
+class TestZimpleTestCase(SimpleTestCase):
+ # Z is used to trick this test case to appear after Vanilla in default suite
+
+ def test_sample(self):
+ self.assertEqual(1, 1)
+
+
class EmptyTestCase(TestCase):
pass
+
+
+def load_tests(loader, tests, ignore):
+ tests.addTests(doctest.DocTestSuite(doctests))
+ return tests