From 8e1a7dab4b98dee2c696d435ea02f56de6250aa0 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 4 Jan 2018 14:41:38 -0500 Subject: Reorganized test_runner test apps. --- tests/runtests.py | 3 +- tests/test_discovery_sample/__init__.py | 0 tests/test_discovery_sample/doctests.py | 46 -------------------- tests/test_discovery_sample/empty.py | 0 tests/test_discovery_sample/pattern_tests.py | 7 --- tests/test_discovery_sample/tests/__init__.py | 0 tests/test_discovery_sample/tests/tests.py | 7 --- tests/test_discovery_sample/tests_sample.py | 46 -------------------- tests/test_discovery_sample2/__init__.py | 0 tests/test_discovery_sample2/tests.py | 57 ------------------------- tests/test_runner/test_discover_runner.py | 42 +++++++++--------- tests/test_runner_apps/__init__.py | 0 tests/test_runner_apps/sample/__init__.py | 0 tests/test_runner_apps/sample/doctests.py | 46 ++++++++++++++++++++ tests/test_runner_apps/sample/empty.py | 0 tests/test_runner_apps/sample/pattern_tests.py | 7 +++ tests/test_runner_apps/sample/tests/__init__.py | 0 tests/test_runner_apps/sample/tests/tests.py | 7 +++ tests/test_runner_apps/sample/tests_sample.py | 34 +++++++++++++++ tests/test_runner_apps/simple/__init__.py | 0 tests/test_runner_apps/simple/tests.py | 57 +++++++++++++++++++++++++ tests/test_runner_apps/tagged/__init__.py | 0 tests/test_runner_apps/tagged/tests.py | 15 +++++++ 23 files changed, 188 insertions(+), 186 deletions(-) delete mode 100644 tests/test_discovery_sample/__init__.py delete mode 100644 tests/test_discovery_sample/doctests.py delete mode 100644 tests/test_discovery_sample/empty.py delete mode 100644 tests/test_discovery_sample/pattern_tests.py delete mode 100644 tests/test_discovery_sample/tests/__init__.py delete mode 100644 tests/test_discovery_sample/tests/tests.py delete mode 100644 tests/test_discovery_sample/tests_sample.py delete mode 100644 tests/test_discovery_sample2/__init__.py delete mode 100644 tests/test_discovery_sample2/tests.py create mode 100644 tests/test_runner_apps/__init__.py create mode 100644 tests/test_runner_apps/sample/__init__.py create mode 100644 tests/test_runner_apps/sample/doctests.py create mode 100644 tests/test_runner_apps/sample/empty.py create mode 100644 tests/test_runner_apps/sample/pattern_tests.py create mode 100644 tests/test_runner_apps/sample/tests/__init__.py create mode 100644 tests/test_runner_apps/sample/tests/tests.py create mode 100644 tests/test_runner_apps/sample/tests_sample.py create mode 100644 tests/test_runner_apps/simple/__init__.py create mode 100644 tests/test_runner_apps/simple/tests.py create mode 100644 tests/test_runner_apps/tagged/__init__.py create mode 100644 tests/test_runner_apps/tagged/tests.py diff --git a/tests/runtests.py b/tests/runtests.py index ae2d693ac2..350604fd06 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -44,8 +44,7 @@ atexit.register(shutil.rmtree, TMPDIR) SUBDIRS_TO_SKIP = [ 'data', 'import_error_package', - 'test_discovery_sample', - 'test_discovery_sample2', + 'test_runner_apps', ] ALWAYS_INSTALLED_APPS = [ diff --git a/tests/test_discovery_sample/__init__.py b/tests/test_discovery_sample/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/test_discovery_sample/doctests.py b/tests/test_discovery_sample/doctests.py deleted file mode 100644 index 6d9403442c..0000000000 --- a/tests/test_discovery_sample/doctests.py +++ /dev/null @@ -1,46 +0,0 @@ -""" -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) # doctest: +ELLIPSIS - 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) # doctest: +ELLIPSIS - 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/empty.py b/tests/test_discovery_sample/empty.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/test_discovery_sample/pattern_tests.py b/tests/test_discovery_sample/pattern_tests.py deleted file mode 100644 index f62a233d75..0000000000 --- a/tests/test_discovery_sample/pattern_tests.py +++ /dev/null @@ -1,7 +0,0 @@ -from unittest import TestCase - - -class Test(TestCase): - - def test_sample(self): - self.assertEqual(1, 1) diff --git a/tests/test_discovery_sample/tests/__init__.py b/tests/test_discovery_sample/tests/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/test_discovery_sample/tests/tests.py b/tests/test_discovery_sample/tests/tests.py deleted file mode 100644 index 58bd4e7f1e..0000000000 --- a/tests/test_discovery_sample/tests/tests.py +++ /dev/null @@ -1,7 +0,0 @@ -from unittest import TestCase - - -class Test(TestCase): - - def test_sample(self): - pass diff --git a/tests/test_discovery_sample/tests_sample.py b/tests/test_discovery_sample/tests_sample.py deleted file mode 100644 index 694b01ffd4..0000000000 --- a/tests/test_discovery_sample/tests_sample.py +++ /dev/null @@ -1,46 +0,0 @@ -import doctest -from unittest import TestCase - -from django.test import SimpleTestCase, TestCase as DjangoTestCase, tag - -from . import doctests - - -class TestVanillaUnittest(TestCase): - - def test_sample(self): - self.assertEqual(1, 1) - - -class TestDjangoTestCase(DjangoTestCase): - - def test_sample(self): - 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 - - -@tag('slow') -class TaggedTestCase(TestCase): - - @tag('fast') - def test_single_tag(self): - self.assertEqual(1, 1) - - @tag('fast', 'core') - def test_multiple_tags(self): - self.assertEqual(1, 1) - - -def load_tests(loader, tests, ignore): - tests.addTests(doctest.DocTestSuite(doctests)) - return tests diff --git a/tests/test_discovery_sample2/__init__.py b/tests/test_discovery_sample2/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/test_discovery_sample2/tests.py b/tests/test_discovery_sample2/tests.py deleted file mode 100644 index ac3e9daba0..0000000000 --- a/tests/test_discovery_sample2/tests.py +++ /dev/null @@ -1,57 +0,0 @@ -from unittest import TestCase - -from django.test import SimpleTestCase, TestCase as DjangoTestCase - - -class DjangoCase1(DjangoTestCase): - - def test_1(self): - pass - - def test_2(self): - pass - - -class DjangoCase2(DjangoTestCase): - - def test_1(self): - pass - - def test_2(self): - pass - - -class SimpleCase1(SimpleTestCase): - - def test_1(self): - pass - - def test_2(self): - pass - - -class SimpleCase2(SimpleTestCase): - - def test_1(self): - pass - - def test_2(self): - pass - - -class UnittestCase1(TestCase): - - def test_1(self): - pass - - def test_2(self): - pass - - -class UnittestCase2(TestCase): - - def test_1(self): - pass - - def test_2(self): - pass diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py index 3908f0a9da..d897344d16 100644 --- a/tests/test_runner/test_discover_runner.py +++ b/tests/test_runner/test_discover_runner.py @@ -36,28 +36,28 @@ class DiscoverRunnerTest(TestCase): def test_dotted_test_module(self): count = DiscoverRunner().build_suite( - ["test_discovery_sample.tests_sample"], + ['test_runner_apps.sample.tests_sample'], ).countTestCases() - self.assertEqual(count, 6) + self.assertEqual(count, 4) def test_dotted_test_class_vanilla_unittest(self): count = DiscoverRunner().build_suite( - ["test_discovery_sample.tests_sample.TestVanillaUnittest"], + ['test_runner_apps.sample.tests_sample.TestVanillaUnittest'], ).countTestCases() self.assertEqual(count, 1) def test_dotted_test_class_django_testcase(self): count = DiscoverRunner().build_suite( - ["test_discovery_sample.tests_sample.TestDjangoTestCase"], + ['test_runner_apps.sample.tests_sample.TestDjangoTestCase'], ).countTestCases() self.assertEqual(count, 1) def test_dotted_test_method_django_testcase(self): count = DiscoverRunner().build_suite( - ["test_discovery_sample.tests_sample.TestDjangoTestCase.test_sample"], + ['test_runner_apps.sample.tests_sample.TestDjangoTestCase.test_sample'], ).countTestCases() self.assertEqual(count, 1) @@ -65,17 +65,17 @@ class DiscoverRunnerTest(TestCase): def test_pattern(self): count = DiscoverRunner( pattern="*_tests.py", - ).build_suite(["test_discovery_sample"]).countTestCases() + ).build_suite(['test_runner_apps.sample']).countTestCases() self.assertEqual(count, 1) def test_file_path(self): with change_cwd(".."): count = DiscoverRunner().build_suite( - ["test_discovery_sample/"], + ['test_runner_apps/sample/'], ).countTestCases() - self.assertEqual(count, 7) + self.assertEqual(count, 5) def test_empty_label(self): """ @@ -91,14 +91,14 @@ class DiscoverRunnerTest(TestCase): def test_empty_test_case(self): count = DiscoverRunner().build_suite( - ["test_discovery_sample.tests_sample.EmptyTestCase"], + ['test_runner_apps.sample.tests_sample.EmptyTestCase'], ).countTestCases() self.assertEqual(count, 0) def test_discovery_on_package(self): count = DiscoverRunner().build_suite( - ["test_discovery_sample.tests"], + ['test_runner_apps.sample.tests'], ).countTestCases() self.assertEqual(count, 1) @@ -112,14 +112,14 @@ class DiscoverRunnerTest(TestCase): should not. The discover runner avoids this behavior. """ count = DiscoverRunner().build_suite( - ["test_discovery_sample.empty"], + ['test_runner_apps.sample.empty'], ).countTestCases() self.assertEqual(count, 0) def test_testcase_ordering(self): with change_cwd(".."): - suite = DiscoverRunner().build_suite(["test_discovery_sample/"]) + suite = DiscoverRunner().build_suite(['test_runner_apps/sample/']) self.assertEqual( suite._tests[0].__class__.__name__, 'TestDjangoTestCase', @@ -149,10 +149,10 @@ class DiscoverRunnerTest(TestCase): """ runner = DiscoverRunner(reverse=True) suite = runner.build_suite( - test_labels=('test_discovery_sample', 'test_discovery_sample2')) - self.assertIn('test_discovery_sample2', next(iter(suite)).id(), + test_labels=('test_runner_apps.sample', 'test_runner_apps.simple')) + self.assertIn('test_runner_apps.simple', next(iter(suite)).id(), msg="Test labels should be reversed.") - suite = runner.build_suite(test_labels=('test_discovery_sample2',)) + suite = runner.build_suite(test_labels=('test_runner_apps.simple',)) suite = tuple(suite) self.assertIn('DjangoCase', suite[0].id(), msg="Test groups should not be reversed.") @@ -185,16 +185,16 @@ class DiscoverRunnerTest(TestCase): def test_tags(self): runner = DiscoverRunner(tags=['core']) - self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 1) + self.assertEqual(runner.build_suite(['test_runner_apps.tagged.tests']).countTestCases(), 1) runner = DiscoverRunner(tags=['fast']) - self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 2) + self.assertEqual(runner.build_suite(['test_runner_apps.tagged.tests']).countTestCases(), 2) runner = DiscoverRunner(tags=['slow']) - self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 2) + self.assertEqual(runner.build_suite(['test_runner_apps.tagged.tests']).countTestCases(), 2) def test_exclude_tags(self): runner = DiscoverRunner(tags=['fast'], exclude_tags=['core']) - self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 1) + self.assertEqual(runner.build_suite(['test_runner_apps.tagged.tests']).countTestCases(), 1) runner = DiscoverRunner(tags=['fast'], exclude_tags=['slow']) - self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 0) + self.assertEqual(runner.build_suite(['test_runner_apps.tagged.tests']).countTestCases(), 0) runner = DiscoverRunner(exclude_tags=['slow']) - self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 4) + self.assertEqual(runner.build_suite(['test_runner_apps.tagged.tests']).countTestCases(), 0) diff --git a/tests/test_runner_apps/__init__.py b/tests/test_runner_apps/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/test_runner_apps/sample/__init__.py b/tests/test_runner_apps/sample/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/test_runner_apps/sample/doctests.py b/tests/test_runner_apps/sample/doctests.py new file mode 100644 index 0000000000..6d9403442c --- /dev/null +++ b/tests/test_runner_apps/sample/doctests.py @@ -0,0 +1,46 @@ +""" +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) # doctest: +ELLIPSIS + 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) # doctest: +ELLIPSIS + 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_runner_apps/sample/empty.py b/tests/test_runner_apps/sample/empty.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/test_runner_apps/sample/pattern_tests.py b/tests/test_runner_apps/sample/pattern_tests.py new file mode 100644 index 0000000000..f62a233d75 --- /dev/null +++ b/tests/test_runner_apps/sample/pattern_tests.py @@ -0,0 +1,7 @@ +from unittest import TestCase + + +class Test(TestCase): + + def test_sample(self): + self.assertEqual(1, 1) diff --git a/tests/test_runner_apps/sample/tests/__init__.py b/tests/test_runner_apps/sample/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/test_runner_apps/sample/tests/tests.py b/tests/test_runner_apps/sample/tests/tests.py new file mode 100644 index 0000000000..58bd4e7f1e --- /dev/null +++ b/tests/test_runner_apps/sample/tests/tests.py @@ -0,0 +1,7 @@ +from unittest import TestCase + + +class Test(TestCase): + + def test_sample(self): + pass diff --git a/tests/test_runner_apps/sample/tests_sample.py b/tests/test_runner_apps/sample/tests_sample.py new file mode 100644 index 0000000000..eb977e44fb --- /dev/null +++ b/tests/test_runner_apps/sample/tests_sample.py @@ -0,0 +1,34 @@ +import doctest +from unittest import TestCase + +from django.test import SimpleTestCase, TestCase as DjangoTestCase + +from . import doctests + + +class TestVanillaUnittest(TestCase): + + def test_sample(self): + self.assertEqual(1, 1) + + +class TestDjangoTestCase(DjangoTestCase): + + def test_sample(self): + 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 diff --git a/tests/test_runner_apps/simple/__init__.py b/tests/test_runner_apps/simple/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/test_runner_apps/simple/tests.py b/tests/test_runner_apps/simple/tests.py new file mode 100644 index 0000000000..ac3e9daba0 --- /dev/null +++ b/tests/test_runner_apps/simple/tests.py @@ -0,0 +1,57 @@ +from unittest import TestCase + +from django.test import SimpleTestCase, TestCase as DjangoTestCase + + +class DjangoCase1(DjangoTestCase): + + def test_1(self): + pass + + def test_2(self): + pass + + +class DjangoCase2(DjangoTestCase): + + def test_1(self): + pass + + def test_2(self): + pass + + +class SimpleCase1(SimpleTestCase): + + def test_1(self): + pass + + def test_2(self): + pass + + +class SimpleCase2(SimpleTestCase): + + def test_1(self): + pass + + def test_2(self): + pass + + +class UnittestCase1(TestCase): + + def test_1(self): + pass + + def test_2(self): + pass + + +class UnittestCase2(TestCase): + + def test_1(self): + pass + + def test_2(self): + pass diff --git a/tests/test_runner_apps/tagged/__init__.py b/tests/test_runner_apps/tagged/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/test_runner_apps/tagged/tests.py b/tests/test_runner_apps/tagged/tests.py new file mode 100644 index 0000000000..d3742b3749 --- /dev/null +++ b/tests/test_runner_apps/tagged/tests.py @@ -0,0 +1,15 @@ +from unittest import TestCase + +from django.test import tag + + +@tag('slow') +class TaggedTestCase(TestCase): + + @tag('fast') + def test_single_tag(self): + self.assertEqual(1, 1) + + @tag('fast', 'core') + def test_multiple_tags(self): + self.assertEqual(1, 1) -- cgit v1.3