testtools 2.8.3__tar.gz → 2.8.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {testtools-2.8.3 → testtools-2.8.5}/.github/workflows/publish.yml +3 -1
- {testtools-2.8.3 → testtools-2.8.5}/NEWS +34 -0
- {testtools-2.8.3 → testtools-2.8.5}/PKG-INFO +3 -2
- {testtools-2.8.3 → testtools-2.8.5}/doc/twisted-support.rst +14 -0
- {testtools-2.8.3 → testtools-2.8.5}/pyproject.toml +4 -1
- {testtools-2.8.3 → testtools-2.8.5}/tests/matchers/test_basic.py +1 -1
- {testtools-2.8.3 → testtools-2.8.5}/tests/matchers/test_const.py +1 -2
- {testtools-2.8.3 → testtools-2.8.5}/tests/matchers/test_datastructures.py +1 -1
- {testtools-2.8.3 → testtools-2.8.5}/tests/matchers/test_dict.py +1 -2
- {testtools-2.8.3 → testtools-2.8.5}/tests/matchers/test_doctest.py +1 -1
- {testtools-2.8.3 → testtools-2.8.5}/tests/matchers/test_exception.py +1 -1
- {testtools-2.8.3 → testtools-2.8.5}/tests/matchers/test_higherorder.py +1 -1
- {testtools-2.8.3 → testtools-2.8.5}/tests/matchers/test_warnings.py +1 -1
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_compat.py +39 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_testresult.py +142 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/_version.py +2 -2
- {testtools-2.8.3 → testtools-2.8.5}/testtools/compat.py +37 -1
- {testtools-2.8.3 → testtools-2.8.5}/testtools/matchers/_higherorder.py +6 -5
- {testtools-2.8.3 → testtools-2.8.5}/testtools/testcase.py +14 -18
- {testtools-2.8.3 → testtools-2.8.5}/testtools/testresult/real.py +61 -0
- testtools-2.8.5/testtools/tests/__init__.py +0 -0
- testtools-2.8.5/testtools/tests/helpers.py +166 -0
- testtools-2.8.5/testtools/tests/matchers/__init__.py +0 -0
- testtools-2.8.5/testtools/tests/matchers/helpers.py +15 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/twistedsupport/__init__.py +7 -0
- {testtools-2.8.3 → testtools-2.8.5}/.git-blame-ignore-revs +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/.github/dependabot.yaml +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/.github/workflows/test.yml +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/.gitignore +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/.gitreview +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/.testr.conf +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/LICENSE +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/MANIFEST.in +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/Makefile +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/README.rst +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/disperse.conf +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/doc/Makefile +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/doc/_static/placeholder.txt +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/doc/_templates/placeholder.txt +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/doc/api.rst +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/doc/conf.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/doc/for-framework-folk.rst +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/doc/for-test-authors.rst +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/doc/hacking.rst +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/doc/index.rst +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/doc/make.bat +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/doc/news.rst +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/doc/overview.rst +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/readthedocs-requirements.txt +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/requirements.txt +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/scripts/README +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/scripts/all-pythons +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/scripts/update-rtfd +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/__init__.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/helpers.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/matchers/__init__.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/matchers/test_filesystem.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/matchers/test_impl.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/samplecases.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_assert_that.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_content.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_content_type.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_fixturesupport.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_helpers.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_monkey.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_run.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_runtest.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_tags.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_testcase.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_testsuite.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/test_with_with.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/twistedsupport/__init__.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/twistedsupport/_helpers.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/twistedsupport/test_deferred.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/twistedsupport/test_matchers.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/twistedsupport/test_runtest.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tests/twistedsupport/test_spinner.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/__init__.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/_version.pyi +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/assertions.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/content.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/content_type.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/helpers.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/matchers/__init__.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/matchers/_basic.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/matchers/_const.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/matchers/_datastructures.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/matchers/_dict.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/matchers/_doctest.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/matchers/_exception.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/matchers/_filesystem.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/matchers/_impl.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/matchers/_warnings.py +0 -0
- /testtools-2.8.3/tests/matchers/helpers.py → /testtools-2.8.5/testtools/matchers/test.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/monkey.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/py.typed +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/run.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/runtest.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/tags.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/testresult/__init__.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/testresult/doubles.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/testsuite.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/twistedsupport/_deferred.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/twistedsupport/_deferreddebug.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/twistedsupport/_matchers.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/twistedsupport/_runtest.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/testtools/twistedsupport/_spinner.py +0 -0
- {testtools-2.8.3 → testtools-2.8.5}/tox.ini +0 -0
|
@@ -5,6 +5,8 @@ name: Publish to PyPI
|
|
|
5
5
|
push:
|
|
6
6
|
branches:
|
|
7
7
|
- 'master'
|
|
8
|
+
tags:
|
|
9
|
+
- '*'
|
|
8
10
|
workflow_dispatch:
|
|
9
11
|
|
|
10
12
|
permissions:
|
|
@@ -34,4 +36,4 @@ jobs:
|
|
|
34
36
|
run: hatch build
|
|
35
37
|
- name: Publish package distributions to PyPI
|
|
36
38
|
uses: pypa/gh-action-pypi-publish@release/v1
|
|
37
|
-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/
|
|
39
|
+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/2')
|
|
@@ -3,6 +3,40 @@ testtools NEWS
|
|
|
3
3
|
|
|
4
4
|
Changes and improvements to testtools_, grouped by release.
|
|
5
5
|
|
|
6
|
+
2.8.4
|
|
7
|
+
~~~~~
|
|
8
|
+
|
|
9
|
+
Improvements
|
|
10
|
+
------------
|
|
11
|
+
* Clear ``force_failure`` in ``_reset()`` so that re-running a test
|
|
12
|
+
after an ``expectThat`` failure can succeed if successful conditions are met again.
|
|
13
|
+
(OumarCamara, #563)
|
|
14
|
+
|
|
15
|
+
* Make ``extract_result()`` and ``DeferredNotFired`` public APIs in
|
|
16
|
+
``testtools.twistedsupport``. These utilities are useful for extracting
|
|
17
|
+
results from synchronous Deferreds in tests.
|
|
18
|
+
(Jelmer Vernooij, #546)
|
|
19
|
+
|
|
20
|
+
* Add support for ``unittest.TestCase.subTest``. Failures are reported
|
|
21
|
+
individually while the entire test method is still treated as a single test.
|
|
22
|
+
(Stephen Finucane, #567)
|
|
23
|
+
|
|
24
|
+
* Add ``testtools.matchers.test`` module providing a test harness for
|
|
25
|
+
users who write their own custom matchers.
|
|
26
|
+
(Stephen Finucane)
|
|
27
|
+
|
|
28
|
+
Changes
|
|
29
|
+
-------
|
|
30
|
+
|
|
31
|
+
* Re-add compat helpers and helper modules that were accidentally removed
|
|
32
|
+
in a patch release, breaking API compatibility. These are now deprecated
|
|
33
|
+
and will be removed in a future major release.
|
|
34
|
+
(Stephen Finucane, #566)
|
|
35
|
+
|
|
36
|
+
* ``typing-extensions`` is no longer required at runtime; it is only needed
|
|
37
|
+
for type checking.
|
|
38
|
+
(Jelmer Vernooij, Takashi Kajinami, #569, #571)
|
|
39
|
+
|
|
6
40
|
2.8.3
|
|
7
41
|
~~~~~
|
|
8
42
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: testtools
|
|
3
|
-
Version: 2.8.
|
|
3
|
+
Version: 2.8.5
|
|
4
4
|
Summary: Extensions to the Python standard library unit testing framework
|
|
5
5
|
Project-URL: Homepage, https://github.com/testing-cabal/testtools
|
|
6
6
|
Author-email: "Jonathan M. Lange" <jml+testtools@mumak.net>
|
|
@@ -26,7 +26,8 @@ Classifier: Typing :: Typed
|
|
|
26
26
|
Requires-Python: >=3.10
|
|
27
27
|
Provides-Extra: dev
|
|
28
28
|
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
29
|
-
Requires-Dist: ruff==0.
|
|
29
|
+
Requires-Dist: ruff==0.15.2; extra == 'dev'
|
|
30
|
+
Requires-Dist: typing-extensions; (python_version < '3.11') and extra == 'dev'
|
|
30
31
|
Provides-Extra: test
|
|
31
32
|
Requires-Dist: testresources; extra == 'test'
|
|
32
33
|
Requires-Dist: testscenarios; extra == 'test'
|
|
@@ -38,6 +38,20 @@ See also `Testing Deferreds without the reactor`_ and the `Deferred howto`_.
|
|
|
38
38
|
:noindex:
|
|
39
39
|
|
|
40
40
|
|
|
41
|
+
Extracting results from Deferreds
|
|
42
|
+
----------------------------------
|
|
43
|
+
|
|
44
|
+
When testing code that returns synchronous
|
|
45
|
+
:py:class:`~twisted.internet.defer.Deferred`\s for compatibility reasons, you
|
|
46
|
+
may want to extract the result directly instead of using matchers.
|
|
47
|
+
|
|
48
|
+
.. autofunction:: testtools.twistedsupport.extract_result
|
|
49
|
+
:noindex:
|
|
50
|
+
|
|
51
|
+
.. autoexception:: testtools.twistedsupport.DeferredNotFired
|
|
52
|
+
:noindex:
|
|
53
|
+
|
|
54
|
+
|
|
41
55
|
Running tests in the reactor
|
|
42
56
|
----------------------------
|
|
43
57
|
|
|
@@ -37,8 +37,9 @@ Homepage = "https://github.com/testing-cabal/testtools"
|
|
|
37
37
|
test = ["testscenarios", "testresources"]
|
|
38
38
|
twisted = ["Twisted", "fixtures"]
|
|
39
39
|
dev = [
|
|
40
|
-
"ruff==0.
|
|
40
|
+
"ruff==0.15.2",
|
|
41
41
|
"mypy>=1.0.0",
|
|
42
|
+
"typing-extensions;python_version<'3.11'",
|
|
42
43
|
]
|
|
43
44
|
|
|
44
45
|
[tool.hatch.version]
|
|
@@ -82,6 +83,8 @@ module = [
|
|
|
82
83
|
# except tests (we're not sadists)
|
|
83
84
|
"testtools.twistedsupport.*",
|
|
84
85
|
"tests.*",
|
|
86
|
+
# NOTE(stephenfin): These are deprecated so we're not going to type them
|
|
87
|
+
"testtools.tests.helpers",
|
|
85
88
|
]
|
|
86
89
|
disallow_untyped_calls = false
|
|
87
90
|
disallow_untyped_defs = false
|
|
@@ -24,9 +24,9 @@ from testtools.matchers._basic import (
|
|
|
24
24
|
_BinaryMismatch,
|
|
25
25
|
_NotNearlyEqual,
|
|
26
26
|
)
|
|
27
|
+
from testtools.matchers.test import TestMatchersInterface
|
|
27
28
|
|
|
28
29
|
from ..helpers import FullStackRunTest
|
|
29
|
-
from ..matchers.helpers import TestMatchersInterface
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
class Test_BinaryMismatch(TestCase):
|
|
@@ -4,8 +4,7 @@ from typing import ClassVar
|
|
|
4
4
|
|
|
5
5
|
from testtools import TestCase
|
|
6
6
|
from testtools.matchers import Always, Never
|
|
7
|
-
|
|
8
|
-
from ..matchers.helpers import TestMatchersInterface
|
|
7
|
+
from testtools.matchers.test import TestMatchersInterface
|
|
9
8
|
|
|
10
9
|
|
|
11
10
|
class TestAlwaysInterface(TestMatchersInterface, TestCase):
|
|
@@ -20,9 +20,9 @@ from testtools.matchers._datastructures import (
|
|
|
20
20
|
MatchesSetwise,
|
|
21
21
|
MatchesStructure,
|
|
22
22
|
)
|
|
23
|
+
from testtools.matchers.test import TestMatchersInterface
|
|
23
24
|
|
|
24
25
|
from ..helpers import FullStackRunTest
|
|
25
|
-
from ..matchers.helpers import TestMatchersInterface
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
def run_doctest(obj, name):
|
|
@@ -14,8 +14,7 @@ from testtools.matchers._dict import (
|
|
|
14
14
|
MatchesDict,
|
|
15
15
|
_SubDictOf,
|
|
16
16
|
)
|
|
17
|
-
|
|
18
|
-
from ..matchers.helpers import TestMatchersInterface
|
|
17
|
+
from testtools.matchers.test import TestMatchersInterface
|
|
19
18
|
|
|
20
19
|
|
|
21
20
|
class TestMatchesAllDictInterface(TestCase, TestMatchersInterface):
|
|
@@ -5,9 +5,9 @@ from typing import ClassVar
|
|
|
5
5
|
|
|
6
6
|
from testtools import TestCase
|
|
7
7
|
from testtools.matchers._doctest import DocTestMatches
|
|
8
|
+
from testtools.matchers.test import TestMatchersInterface
|
|
8
9
|
|
|
9
10
|
from ..helpers import FullStackRunTest
|
|
10
|
-
from ..matchers.helpers import TestMatchersInterface
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class TestDocTestMatchesInterface(TestCase, TestMatchersInterface):
|
|
@@ -13,9 +13,9 @@ from testtools.matchers._exception import (
|
|
|
13
13
|
Raises,
|
|
14
14
|
raises,
|
|
15
15
|
)
|
|
16
|
+
from testtools.matchers.test import TestMatchersInterface
|
|
16
17
|
|
|
17
18
|
from ..helpers import FullStackRunTest
|
|
18
|
-
from ..matchers.helpers import TestMatchersInterface
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def make_error(type, *args, **kwargs):
|
|
@@ -23,9 +23,9 @@ from testtools.matchers._higherorder import (
|
|
|
23
23
|
MatchesPredicateWithParams,
|
|
24
24
|
Not,
|
|
25
25
|
)
|
|
26
|
+
from testtools.matchers.test import TestMatchersInterface
|
|
26
27
|
|
|
27
28
|
from ..helpers import FullStackRunTest
|
|
28
|
-
from ..matchers.helpers import TestMatchersInterface
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
class TestAllMatch(TestCase, TestMatchersInterface):
|
|
@@ -13,9 +13,9 @@ from testtools.matchers import (
|
|
|
13
13
|
MatchesStructure,
|
|
14
14
|
)
|
|
15
15
|
from testtools.matchers._warnings import IsDeprecated, WarningMessage, Warnings
|
|
16
|
+
from testtools.matchers.test import TestMatchersInterface
|
|
16
17
|
|
|
17
18
|
from ..helpers import FullStackRunTest
|
|
18
|
-
from ..matchers.helpers import TestMatchersInterface
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def make_warning(warning_type, message):
|
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
import ast
|
|
6
6
|
import io
|
|
7
7
|
import sys
|
|
8
|
+
import traceback
|
|
8
9
|
|
|
9
10
|
import testtools
|
|
10
11
|
from testtools.compat import (
|
|
12
|
+
reraise,
|
|
11
13
|
text_repr,
|
|
12
14
|
unicode_output_stream,
|
|
13
15
|
)
|
|
@@ -216,6 +218,43 @@ class TestTextRepr(testtools.TestCase):
|
|
|
216
218
|
self.assertEqual(ast.literal_eval(actual), u)
|
|
217
219
|
|
|
218
220
|
|
|
221
|
+
class TestReraise(testtools.TestCase):
|
|
222
|
+
"""Tests for trivial reraise wrapper needed for Python 2/3 changes"""
|
|
223
|
+
|
|
224
|
+
def test_exc_info(self):
|
|
225
|
+
"""After reraise exc_info matches plus some extra traceback"""
|
|
226
|
+
try:
|
|
227
|
+
raise ValueError("Bad value")
|
|
228
|
+
except ValueError:
|
|
229
|
+
_exc_info = sys.exc_info()
|
|
230
|
+
try:
|
|
231
|
+
reraise(*_exc_info)
|
|
232
|
+
except ValueError:
|
|
233
|
+
_new_exc_info = sys.exc_info()
|
|
234
|
+
self.assertIs(_exc_info[0], _new_exc_info[0])
|
|
235
|
+
self.assertIs(_exc_info[1], _new_exc_info[1])
|
|
236
|
+
expected_tb = traceback.extract_tb(_exc_info[2])
|
|
237
|
+
self.assertEqual(
|
|
238
|
+
expected_tb, traceback.extract_tb(_new_exc_info[2])[-len(expected_tb) :]
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
def test_custom_exception_no_args(self):
|
|
242
|
+
"""Reraising does not require args attribute to contain params"""
|
|
243
|
+
|
|
244
|
+
class CustomException(Exception):
|
|
245
|
+
"""Exception that expects and sets attrs but not args"""
|
|
246
|
+
|
|
247
|
+
def __init__(self, value):
|
|
248
|
+
Exception.__init__(self)
|
|
249
|
+
self.value = value
|
|
250
|
+
|
|
251
|
+
try:
|
|
252
|
+
raise CustomException("Some value")
|
|
253
|
+
except CustomException:
|
|
254
|
+
_exc_info = sys.exc_info()
|
|
255
|
+
self.assertRaises(CustomException, reraise, *_exc_info)
|
|
256
|
+
|
|
257
|
+
|
|
219
258
|
def test_suite():
|
|
220
259
|
from unittest import TestLoader
|
|
221
260
|
|
|
@@ -1314,6 +1314,148 @@ class TestExtendedToStreamDecorator(TestCase):
|
|
|
1314
1314
|
log._events,
|
|
1315
1315
|
)
|
|
1316
1316
|
|
|
1317
|
+
def test_subtest_failure(self):
|
|
1318
|
+
# Test that addSubTest collects failures and reports them in stopTest
|
|
1319
|
+
|
|
1320
|
+
# Create a mock subtest that mimics unittest's _SubTest
|
|
1321
|
+
class MockSubTest:
|
|
1322
|
+
def __init__(self, parent, description):
|
|
1323
|
+
self._parent = parent
|
|
1324
|
+
self._description = description
|
|
1325
|
+
|
|
1326
|
+
def id(self):
|
|
1327
|
+
return f"{self._parent.id()} {self._description}"
|
|
1328
|
+
|
|
1329
|
+
def _subDescription(self):
|
|
1330
|
+
return self._description
|
|
1331
|
+
|
|
1332
|
+
log = LoggingStreamResult()
|
|
1333
|
+
result = ExtendedToStreamDecorator(log)
|
|
1334
|
+
result.startTestRun()
|
|
1335
|
+
now = datetime.datetime.now(utc)
|
|
1336
|
+
result.time(now)
|
|
1337
|
+
result.startTest(self)
|
|
1338
|
+
|
|
1339
|
+
# Simulate a failing subtest
|
|
1340
|
+
subtest = MockSubTest(self, "(i=1)")
|
|
1341
|
+
try:
|
|
1342
|
+
raise AssertionError("subtest failed")
|
|
1343
|
+
except AssertionError:
|
|
1344
|
+
err = sys.exc_info()
|
|
1345
|
+
result.addSubTest(self, subtest, err)
|
|
1346
|
+
|
|
1347
|
+
result.stopTest(self)
|
|
1348
|
+
result.stopTestRun()
|
|
1349
|
+
|
|
1350
|
+
# Filter events to check structure
|
|
1351
|
+
test_id = self.id()
|
|
1352
|
+
events = log._events
|
|
1353
|
+
|
|
1354
|
+
# Should have: startTestRun, inprogress, traceback attachment, fail, stopTestRun
|
|
1355
|
+
self.assertEqual(events[0], ("startTestRun",))
|
|
1356
|
+
self.assertEqual(events[1].test_id, test_id)
|
|
1357
|
+
self.assertEqual(events[1].test_status, "inprogress")
|
|
1358
|
+
|
|
1359
|
+
# The traceback attachment for the subtest
|
|
1360
|
+
self.assertEqual(events[2].test_id, test_id)
|
|
1361
|
+
self.assertEqual(events[2].file_name, "traceback (i=1)")
|
|
1362
|
+
self.assertIn(b"AssertionError: subtest failed", events[2].file_bytes)
|
|
1363
|
+
|
|
1364
|
+
# The final fail status
|
|
1365
|
+
self.assertEqual(events[3].test_id, test_id)
|
|
1366
|
+
self.assertEqual(events[3].test_status, "fail")
|
|
1367
|
+
|
|
1368
|
+
self.assertEqual(events[4], ("stopTestRun",))
|
|
1369
|
+
|
|
1370
|
+
def test_subtest_success_no_events(self):
|
|
1371
|
+
# Test that successful subtests don't generate events
|
|
1372
|
+
class MockSubTest:
|
|
1373
|
+
def __init__(self, parent, description):
|
|
1374
|
+
self._parent = parent
|
|
1375
|
+
self._description = description
|
|
1376
|
+
|
|
1377
|
+
def id(self):
|
|
1378
|
+
return f"{self._parent.id()} {self._description}"
|
|
1379
|
+
|
|
1380
|
+
def _subDescription(self):
|
|
1381
|
+
return self._description
|
|
1382
|
+
|
|
1383
|
+
log = LoggingStreamResult()
|
|
1384
|
+
result = ExtendedToStreamDecorator(log)
|
|
1385
|
+
result.startTestRun()
|
|
1386
|
+
now = datetime.datetime.now(utc)
|
|
1387
|
+
result.time(now)
|
|
1388
|
+
result.startTest(self)
|
|
1389
|
+
|
|
1390
|
+
# Simulate a passing subtest (err=None)
|
|
1391
|
+
subtest = MockSubTest(self, "(i=0)")
|
|
1392
|
+
result.addSubTest(self, subtest, None)
|
|
1393
|
+
|
|
1394
|
+
# Simulate the success callback that unittest sends when all subtests pass
|
|
1395
|
+
result.addSuccess(self)
|
|
1396
|
+
result.stopTest(self)
|
|
1397
|
+
result.stopTestRun()
|
|
1398
|
+
|
|
1399
|
+
test_id = self.id()
|
|
1400
|
+
events = log._events
|
|
1401
|
+
|
|
1402
|
+
# Should have: startTestRun, inprogress, success, stopTestRun
|
|
1403
|
+
# No subtest-specific events since it passed
|
|
1404
|
+
self.assertEqual(events[0], ("startTestRun",))
|
|
1405
|
+
self.assertEqual(events[1].test_id, test_id)
|
|
1406
|
+
self.assertEqual(events[1].test_status, "inprogress")
|
|
1407
|
+
self.assertEqual(events[2].test_id, test_id)
|
|
1408
|
+
self.assertEqual(events[2].test_status, "success")
|
|
1409
|
+
self.assertEqual(events[3], ("stopTestRun",))
|
|
1410
|
+
|
|
1411
|
+
def test_multiple_subtest_failures(self):
|
|
1412
|
+
# Test that multiple subtest failures are all reported
|
|
1413
|
+
class MockSubTest:
|
|
1414
|
+
def __init__(self, parent, description):
|
|
1415
|
+
self._parent = parent
|
|
1416
|
+
self._description = description
|
|
1417
|
+
|
|
1418
|
+
def id(self):
|
|
1419
|
+
return f"{self._parent.id()} {self._description}"
|
|
1420
|
+
|
|
1421
|
+
def _subDescription(self):
|
|
1422
|
+
return self._description
|
|
1423
|
+
|
|
1424
|
+
log = LoggingStreamResult()
|
|
1425
|
+
result = ExtendedToStreamDecorator(log)
|
|
1426
|
+
result.startTestRun()
|
|
1427
|
+
now = datetime.datetime.now(utc)
|
|
1428
|
+
result.time(now)
|
|
1429
|
+
result.startTest(self)
|
|
1430
|
+
|
|
1431
|
+
# Simulate two failing subtests
|
|
1432
|
+
for i in [1, 2]:
|
|
1433
|
+
subtest = MockSubTest(self, f"(i={i})")
|
|
1434
|
+
try:
|
|
1435
|
+
raise AssertionError(f"subtest {i} failed")
|
|
1436
|
+
except AssertionError:
|
|
1437
|
+
err = sys.exc_info()
|
|
1438
|
+
result.addSubTest(self, subtest, err)
|
|
1439
|
+
|
|
1440
|
+
result.stopTest(self)
|
|
1441
|
+
result.stopTestRun()
|
|
1442
|
+
|
|
1443
|
+
events = log._events
|
|
1444
|
+
|
|
1445
|
+
# Should have: startTestRun, inprogress, 2x traceback, fail, stopTestRun
|
|
1446
|
+
self.assertEqual(events[0], ("startTestRun",))
|
|
1447
|
+
self.assertEqual(events[1].test_status, "inprogress")
|
|
1448
|
+
|
|
1449
|
+
# Two traceback attachments
|
|
1450
|
+
self.assertEqual(events[2].file_name, "traceback (i=1)")
|
|
1451
|
+
self.assertIn(b"subtest 1 failed", events[2].file_bytes)
|
|
1452
|
+
self.assertEqual(events[3].file_name, "traceback (i=2)")
|
|
1453
|
+
self.assertIn(b"subtest 2 failed", events[3].file_bytes)
|
|
1454
|
+
|
|
1455
|
+
# Final fail status
|
|
1456
|
+
self.assertEqual(events[4].test_status, "fail")
|
|
1457
|
+
self.assertEqual(events[5], ("stopTestRun",))
|
|
1458
|
+
|
|
1317
1459
|
|
|
1318
1460
|
class TestResourcedToStreamDecorator(TestCase):
|
|
1319
1461
|
def setUp(self):
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
# This file is automatically generated by hatch.
|
|
2
|
-
version = '2.8.
|
|
3
|
-
__version__ = (2, 8,
|
|
2
|
+
version = '2.8.5'
|
|
3
|
+
__version__ = (2, 8, 5)
|
|
@@ -12,9 +12,45 @@ __all__ = [
|
|
|
12
12
|
import codecs
|
|
13
13
|
import io
|
|
14
14
|
import sys
|
|
15
|
+
import types
|
|
15
16
|
import unicodedata
|
|
17
|
+
import warnings
|
|
16
18
|
from io import BytesIO, StringIO # for backwards-compat
|
|
17
|
-
from typing import IO
|
|
19
|
+
from typing import IO, Any, NoReturn
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def reraise(
|
|
23
|
+
exc_class: type[BaseException],
|
|
24
|
+
exc_obj: BaseException,
|
|
25
|
+
exc_tb: types.TracebackType,
|
|
26
|
+
_marker: Any = object(),
|
|
27
|
+
) -> NoReturn:
|
|
28
|
+
"""Re-raise an exception received from sys.exc_info() or similar."""
|
|
29
|
+
warnings.warn(
|
|
30
|
+
"This is not necessary in Python 3.",
|
|
31
|
+
DeprecationWarning,
|
|
32
|
+
stacklevel=2,
|
|
33
|
+
)
|
|
34
|
+
raise exc_obj.with_traceback(exc_tb)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _u(s: str) -> str:
|
|
38
|
+
warnings.warn(
|
|
39
|
+
"This is not necessary in Python 3.",
|
|
40
|
+
DeprecationWarning,
|
|
41
|
+
stacklevel=2,
|
|
42
|
+
)
|
|
43
|
+
return s
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _b(s: str) -> bytes:
|
|
47
|
+
"""A byte literal."""
|
|
48
|
+
warnings.warn(
|
|
49
|
+
"This is not necessary in Python 3.",
|
|
50
|
+
DeprecationWarning,
|
|
51
|
+
stacklevel=2,
|
|
52
|
+
)
|
|
53
|
+
return s.encode("latin-1")
|
|
18
54
|
|
|
19
55
|
|
|
20
56
|
def _slow_escape(text: str) -> str:
|
|
@@ -13,12 +13,13 @@ __all__ = [
|
|
|
13
13
|
import sys
|
|
14
14
|
import types
|
|
15
15
|
from collections.abc import Callable, Iterable
|
|
16
|
-
from typing import Any, Generic, TypedDict, TypeVar
|
|
16
|
+
from typing import TYPE_CHECKING, Any, Generic, TypedDict, TypeVar
|
|
17
17
|
|
|
18
|
-
if
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
if sys.version_info >= (3, 11):
|
|
20
|
+
from typing import Unpack
|
|
21
|
+
else:
|
|
22
|
+
from typing_extensions import Unpack
|
|
22
23
|
|
|
23
24
|
from ._impl import (
|
|
24
25
|
Matcher,
|
|
@@ -23,7 +23,7 @@ import sys
|
|
|
23
23
|
import types
|
|
24
24
|
import unittest
|
|
25
25
|
from collections.abc import Callable, Iterator
|
|
26
|
-
from typing import
|
|
26
|
+
from typing import TypeVar, cast
|
|
27
27
|
from unittest.case import SkipTest
|
|
28
28
|
|
|
29
29
|
T = TypeVar("T")
|
|
@@ -56,6 +56,14 @@ from testtools.testresult import (
|
|
|
56
56
|
TestResult,
|
|
57
57
|
)
|
|
58
58
|
|
|
59
|
+
# Circular import: fixtures imports gather_details from here, we import
|
|
60
|
+
# fixtures, leading to gather_details not being available and fixtures being
|
|
61
|
+
# unable to import it.
|
|
62
|
+
try:
|
|
63
|
+
import fixtures
|
|
64
|
+
except ImportError:
|
|
65
|
+
fixtures = None # type: ignore
|
|
66
|
+
|
|
59
67
|
|
|
60
68
|
class _UnexpectedSuccess(Exception):
|
|
61
69
|
"""An unexpected success was raised.
|
|
@@ -183,22 +191,7 @@ def gather_details(source_dict: DetailsDict, target_dict: DetailsDict) -> None:
|
|
|
183
191
|
target_dict[name] = _copy_content(content_object)
|
|
184
192
|
|
|
185
193
|
|
|
186
|
-
|
|
187
|
-
# fixtures, leading to gather_details not being available and fixtures being
|
|
188
|
-
# unable to import it.
|
|
189
|
-
try:
|
|
190
|
-
import fixtures
|
|
191
|
-
except ImportError:
|
|
192
|
-
fixtures = None # type: ignore
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
class UseFixtureProtocol(Protocol):
|
|
196
|
-
def setUp(self) -> None: ...
|
|
197
|
-
def cleanUp(self) -> None: ...
|
|
198
|
-
def getDetails(self) -> DetailsDict: ...
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
UseFixtureT = TypeVar("UseFixtureT", bound=UseFixtureProtocol)
|
|
194
|
+
FixtureT = TypeVar("FixtureT", bound="fixtures.Fixture")
|
|
202
195
|
|
|
203
196
|
|
|
204
197
|
def _mods(i: int, mod: int) -> Iterator[int]:
|
|
@@ -307,6 +300,9 @@ class TestCase(unittest.TestCase):
|
|
|
307
300
|
# __details is lazy-initialized so that a constructed-but-not-run
|
|
308
301
|
# TestCase is safe to use with clone_test_with_new_id.
|
|
309
302
|
self.__details: DetailsDict | None = None
|
|
303
|
+
# force_failure is set by expectThat() on mismatch; must be
|
|
304
|
+
# cleared so re-runs of the same test can succeed.
|
|
305
|
+
self.force_failure: bool | None = None
|
|
310
306
|
|
|
311
307
|
def __eq__(self, other: object) -> bool:
|
|
312
308
|
eq = getattr(unittest.TestCase, "__eq__", None)
|
|
@@ -889,7 +885,7 @@ class TestCase(unittest.TestCase):
|
|
|
889
885
|
"""
|
|
890
886
|
return self._get_test_method()()
|
|
891
887
|
|
|
892
|
-
def useFixture(self, fixture:
|
|
888
|
+
def useFixture(self, fixture: "FixtureT") -> "FixtureT":
|
|
893
889
|
"""Use fixture in a test case.
|
|
894
890
|
|
|
895
891
|
The fixture will be setUp, and self.addCleanup(fixture.cleanUp) called.
|
|
@@ -2226,6 +2226,7 @@ class ExtendedToStreamDecorator(CopyStreamResult, StreamSummary, TestControl):
|
|
|
2226
2226
|
self._started = False
|
|
2227
2227
|
self._tags: TagContext | None = None
|
|
2228
2228
|
self.__now: datetime.datetime | None = None
|
|
2229
|
+
self._subtest_failures: list[tuple[unittest.TestCase, ExcInfo]] = []
|
|
2229
2230
|
|
|
2230
2231
|
def _get_failfast(self) -> bool:
|
|
2231
2232
|
return len(self.targets) == 2
|
|
@@ -2245,11 +2246,43 @@ class ExtendedToStreamDecorator(CopyStreamResult, StreamSummary, TestControl):
|
|
|
2245
2246
|
self.startTestRun()
|
|
2246
2247
|
self.status(test_id=test.id(), test_status="inprogress", timestamp=self._now())
|
|
2247
2248
|
self._tags = TagContext(self._tags)
|
|
2249
|
+
self._subtest_failures = []
|
|
2248
2250
|
|
|
2249
2251
|
def stopTest(self, test: unittest.TestCase) -> None:
|
|
2250
2252
|
# NOTE: In Python 3.12.1 skipped tests may not call startTest()
|
|
2251
2253
|
if self._tags is not None:
|
|
2252
2254
|
self._tags = self._tags.parent
|
|
2255
|
+
# If any subtests failed, emit the failure details and a fail status
|
|
2256
|
+
# for the parent test. When all subtests pass, unittest calls
|
|
2257
|
+
# addSuccess for the parent, so we don't need to emit a status here.
|
|
2258
|
+
if self._subtest_failures:
|
|
2259
|
+
test_id = test.id()
|
|
2260
|
+
now = self._now()
|
|
2261
|
+
# Emit traceback for each failed subtest as a file attachment
|
|
2262
|
+
for subtest, err in self._subtest_failures:
|
|
2263
|
+
# Use subtest description to create unique attachment name
|
|
2264
|
+
subtest_desc = subtest._subDescription() # type: ignore[attr-defined]
|
|
2265
|
+
attachment_name = f"traceback {subtest_desc}"
|
|
2266
|
+
content = TracebackContent(err, subtest)
|
|
2267
|
+
mime_type = repr(content.content_type)
|
|
2268
|
+
file_bytes = b"".join(content.iter_bytes())
|
|
2269
|
+
self.status(
|
|
2270
|
+
file_name=attachment_name,
|
|
2271
|
+
file_bytes=file_bytes,
|
|
2272
|
+
eof=True,
|
|
2273
|
+
mime_type=mime_type,
|
|
2274
|
+
test_id=test_id,
|
|
2275
|
+
timestamp=now,
|
|
2276
|
+
)
|
|
2277
|
+
# Emit final fail status for the parent test
|
|
2278
|
+
self.status(
|
|
2279
|
+
test_id=test_id,
|
|
2280
|
+
test_status="fail",
|
|
2281
|
+
test_tags=self.current_tags,
|
|
2282
|
+
timestamp=now,
|
|
2283
|
+
)
|
|
2284
|
+
# Clear subtest tracking
|
|
2285
|
+
self._subtest_failures = []
|
|
2253
2286
|
|
|
2254
2287
|
def addError(
|
|
2255
2288
|
self,
|
|
@@ -2345,6 +2378,26 @@ class ExtendedToStreamDecorator(CopyStreamResult, StreamSummary, TestControl):
|
|
|
2345
2378
|
) -> None:
|
|
2346
2379
|
self._convert(test, None, details, "success")
|
|
2347
2380
|
|
|
2381
|
+
def addSubTest(
|
|
2382
|
+
self,
|
|
2383
|
+
test: unittest.TestCase,
|
|
2384
|
+
subtest: unittest.TestCase,
|
|
2385
|
+
err: ExcInfo | None,
|
|
2386
|
+
) -> None:
|
|
2387
|
+
"""Handle a subtest result.
|
|
2388
|
+
|
|
2389
|
+
This is called by unittest when a subtest completes. Subtest failures
|
|
2390
|
+
are collected and reported as attachments to the parent test, so the
|
|
2391
|
+
test count reflects only the parent test (matching unittest behavior).
|
|
2392
|
+
|
|
2393
|
+
:param test: The original test case.
|
|
2394
|
+
:param subtest: The subtest instance (has its own id() method).
|
|
2395
|
+
:param err: None if successful, exc_info tuple if failed.
|
|
2396
|
+
"""
|
|
2397
|
+
# Collect failures to report when the parent test completes
|
|
2398
|
+
if err is not None:
|
|
2399
|
+
self._subtest_failures.append((subtest, err))
|
|
2400
|
+
|
|
2348
2401
|
def _check_args(self, err: ExcInfo | None, details: DetailsDict | None) -> None:
|
|
2349
2402
|
param_count = 0
|
|
2350
2403
|
if err is not None:
|
|
@@ -2700,6 +2753,14 @@ class TestResultDecorator:
|
|
|
2700
2753
|
) -> None:
|
|
2701
2754
|
self.decorated.addUnexpectedSuccess(test, details=details)
|
|
2702
2755
|
|
|
2756
|
+
def addSubTest(
|
|
2757
|
+
self,
|
|
2758
|
+
test: unittest.TestCase,
|
|
2759
|
+
subtest: unittest.TestCase,
|
|
2760
|
+
err: ExcInfo | None,
|
|
2761
|
+
) -> None:
|
|
2762
|
+
self.decorated.addSubTest(test, subtest, err) # type: ignore[arg-type]
|
|
2763
|
+
|
|
2703
2764
|
def addDuration(self, test: unittest.TestCase, duration: float) -> None:
|
|
2704
2765
|
self.decorated.addDuration(test, duration)
|
|
2705
2766
|
|
|
File without changes
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Copyright (c) 2008-2016 testtools developers. See LICENSE for details.
|
|
2
|
+
|
|
3
|
+
"""Helpers for tests."""
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"LoggingResult",
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
import sys
|
|
10
|
+
import warnings
|
|
11
|
+
|
|
12
|
+
from testtools import TestResult, runtest
|
|
13
|
+
from testtools.content import StackLinesContent
|
|
14
|
+
from testtools.matchers import (
|
|
15
|
+
AfterPreprocessing,
|
|
16
|
+
Equals,
|
|
17
|
+
MatchesDict,
|
|
18
|
+
MatchesListwise,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
warnings.warn(
|
|
22
|
+
"This module is deprecated for removal",
|
|
23
|
+
DeprecationWarning,
|
|
24
|
+
stacklevel=2,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# GZ 2010-08-12: Don't do this, pointlessly creates an exc_info cycle
|
|
29
|
+
try:
|
|
30
|
+
raise Exception
|
|
31
|
+
except Exception:
|
|
32
|
+
an_exc_info = sys.exc_info()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# Deprecated: This classes attributes are somewhat non deterministic which
|
|
36
|
+
# leads to hard to predict tests (because Python upstream are changing things.
|
|
37
|
+
class LoggingResult(TestResult):
|
|
38
|
+
"""TestResult that logs its event to a list."""
|
|
39
|
+
|
|
40
|
+
def __init__(self, log):
|
|
41
|
+
self._events = log
|
|
42
|
+
super().__init__()
|
|
43
|
+
|
|
44
|
+
def startTest(self, test):
|
|
45
|
+
self._events.append(("startTest", test))
|
|
46
|
+
super().startTest(test)
|
|
47
|
+
|
|
48
|
+
def stop(self):
|
|
49
|
+
self._events.append("stop")
|
|
50
|
+
super().stop()
|
|
51
|
+
|
|
52
|
+
def stopTest(self, test):
|
|
53
|
+
self._events.append(("stopTest", test))
|
|
54
|
+
super().stopTest(test)
|
|
55
|
+
|
|
56
|
+
def addFailure(self, test, err=None, details=None):
|
|
57
|
+
self._events.append(("addFailure", test, err))
|
|
58
|
+
super().addFailure(test, err, details)
|
|
59
|
+
|
|
60
|
+
def addError(self, test, err=None, details=None):
|
|
61
|
+
self._events.append(("addError", test, err))
|
|
62
|
+
super().addError(test, err, details)
|
|
63
|
+
|
|
64
|
+
def addSkip(self, test, reason=None, details=None):
|
|
65
|
+
# Extract reason from details if not provided directly
|
|
66
|
+
if reason is None and details and "reason" in details:
|
|
67
|
+
reason = details["reason"].as_text()
|
|
68
|
+
self._events.append(("addSkip", test, reason))
|
|
69
|
+
super().addSkip(test, reason, details)
|
|
70
|
+
|
|
71
|
+
def addSuccess(self, test, details=None):
|
|
72
|
+
self._events.append(("addSuccess", test))
|
|
73
|
+
super().addSuccess(test, details)
|
|
74
|
+
|
|
75
|
+
def startTestRun(self):
|
|
76
|
+
self._events.append("startTestRun")
|
|
77
|
+
super().startTestRun()
|
|
78
|
+
|
|
79
|
+
def stopTestRun(self):
|
|
80
|
+
self._events.append("stopTestRun")
|
|
81
|
+
super().stopTestRun()
|
|
82
|
+
|
|
83
|
+
def done(self):
|
|
84
|
+
self._events.append("done")
|
|
85
|
+
super().done()
|
|
86
|
+
|
|
87
|
+
def tags(self, new_tags, gone_tags):
|
|
88
|
+
self._events.append(("tags", new_tags, gone_tags))
|
|
89
|
+
super().tags(new_tags, gone_tags)
|
|
90
|
+
|
|
91
|
+
def time(self, a_datetime):
|
|
92
|
+
self._events.append(("time", a_datetime))
|
|
93
|
+
super().time(a_datetime)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def is_stack_hidden():
|
|
97
|
+
return StackLinesContent.HIDE_INTERNAL_STACK
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def hide_testtools_stack(should_hide=True):
|
|
101
|
+
result = StackLinesContent.HIDE_INTERNAL_STACK
|
|
102
|
+
StackLinesContent.HIDE_INTERNAL_STACK = should_hide
|
|
103
|
+
return result
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def run_with_stack_hidden(should_hide, f, *args, **kwargs):
|
|
107
|
+
old_should_hide = hide_testtools_stack(should_hide)
|
|
108
|
+
try:
|
|
109
|
+
return f(*args, **kwargs)
|
|
110
|
+
finally:
|
|
111
|
+
hide_testtools_stack(old_should_hide)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class FullStackRunTest(runtest.RunTest):
|
|
115
|
+
def _run_user(self, fn, *args, **kwargs):
|
|
116
|
+
return run_with_stack_hidden(False, super()._run_user, fn, *args, **kwargs)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class MatchesEvents:
|
|
120
|
+
"""Match a list of test result events.
|
|
121
|
+
|
|
122
|
+
Specify events as a data structure. Ordinary Python objects within this
|
|
123
|
+
structure will be compared exactly, but you can also use matchers at any
|
|
124
|
+
point.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
def __init__(self, *expected):
|
|
128
|
+
self._expected = expected
|
|
129
|
+
|
|
130
|
+
def _make_matcher(self, obj):
|
|
131
|
+
# This isn't very safe for general use, but is good enough to make
|
|
132
|
+
# some tests in this module more readable.
|
|
133
|
+
if hasattr(obj, "match"):
|
|
134
|
+
return obj
|
|
135
|
+
elif isinstance(obj, tuple) or isinstance(obj, list):
|
|
136
|
+
return MatchesListwise([self._make_matcher(item) for item in obj])
|
|
137
|
+
elif isinstance(obj, dict):
|
|
138
|
+
return MatchesDict(
|
|
139
|
+
{key: self._make_matcher(value) for key, value in obj.items()}
|
|
140
|
+
)
|
|
141
|
+
else:
|
|
142
|
+
return Equals(obj)
|
|
143
|
+
|
|
144
|
+
def match(self, observed):
|
|
145
|
+
matcher = self._make_matcher(self._expected)
|
|
146
|
+
return matcher.match(observed)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class AsText(AfterPreprocessing):
|
|
150
|
+
"""Match the text of a Content instance."""
|
|
151
|
+
|
|
152
|
+
def __init__(self, matcher, annotate=True):
|
|
153
|
+
super().__init__(lambda log: log.as_text(), matcher, annotate=annotate)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def raise_(exception):
|
|
157
|
+
"""Raise ``exception``.
|
|
158
|
+
|
|
159
|
+
Useful for raising exceptions when it is inconvenient to use a statement
|
|
160
|
+
(e.g. in a lambda).
|
|
161
|
+
|
|
162
|
+
:param Exception exception: An exception to raise.
|
|
163
|
+
:raises: Whatever exception is
|
|
164
|
+
|
|
165
|
+
"""
|
|
166
|
+
raise exception
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright (c) 2008-2012 testtools developers. See LICENSE for details.
|
|
2
|
+
|
|
3
|
+
import warnings
|
|
4
|
+
|
|
5
|
+
from testtools.matchers.test import TestMatchersInterface
|
|
6
|
+
|
|
7
|
+
warnings.warn(
|
|
8
|
+
"This module is deprecated for removal",
|
|
9
|
+
DeprecationWarning,
|
|
10
|
+
stacklevel=2,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"TestMatchersInterface",
|
|
15
|
+
]
|
|
@@ -7,8 +7,11 @@ __all__ = [
|
|
|
7
7
|
"AsynchronousDeferredRunTest",
|
|
8
8
|
"AsynchronousDeferredRunTestForBrokenTwisted",
|
|
9
9
|
"CaptureTwistedLogs",
|
|
10
|
+
# Deferred utilities
|
|
11
|
+
"DeferredNotFired",
|
|
10
12
|
"SynchronousDeferredRunTest",
|
|
11
13
|
"assert_fails_with",
|
|
14
|
+
"extract_result",
|
|
12
15
|
"failed",
|
|
13
16
|
"flush_logged_errors",
|
|
14
17
|
"has_no_result",
|
|
@@ -16,6 +19,10 @@ __all__ = [
|
|
|
16
19
|
"succeeded",
|
|
17
20
|
]
|
|
18
21
|
|
|
22
|
+
from ._deferred import (
|
|
23
|
+
DeferredNotFired,
|
|
24
|
+
extract_result,
|
|
25
|
+
)
|
|
19
26
|
from ._matchers import (
|
|
20
27
|
failed,
|
|
21
28
|
has_no_result,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|