nti.testing 4.2.0__py3-none-any.whl
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.
- nti/__init__.py +0 -0
- nti/testing/__init__.py +107 -0
- nti/testing/base.py +574 -0
- nti/testing/layers/__init__.py +53 -0
- nti/testing/layers/cleanup.py +106 -0
- nti/testing/layers/postgres.py +693 -0
- nti/testing/layers/tests/__init__.py +0 -0
- nti/testing/layers/tests/test_postgres.py +17 -0
- nti/testing/layers/zope.py +122 -0
- nti/testing/matchers.py +370 -0
- nti/testing/mock.py +22 -0
- nti/testing/tests/__init__.py +0 -0
- nti/testing/tests/test_base.py +160 -0
- nti/testing/tests/test_component_cleanup_broken.txt +137 -0
- nti/testing/tests/test_layers.py +56 -0
- nti/testing/tests/test_main.py +47 -0
- nti/testing/tests/test_matchers.py +237 -0
- nti/testing/tests/test_time.py +157 -0
- nti/testing/tests/test_zodb.py +326 -0
- nti/testing/time.py +179 -0
- nti/testing/zodb.py +245 -0
- nti.testing-4.2.0.dist-info/LICENSE +11 -0
- nti.testing-4.2.0.dist-info/METADATA +423 -0
- nti.testing-4.2.0.dist-info/RECORD +27 -0
- nti.testing-4.2.0.dist-info/WHEEL +5 -0
- nti.testing-4.2.0.dist-info/top_level.txt +1 -0
- nti.testing-4.2.0.dist-info/zip-safe +1 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Test layer support.
|
|
5
|
+
|
|
6
|
+
.. versionchanged:: 4.0.0
|
|
7
|
+
|
|
8
|
+
This is now a package with sub-modules. Existing imports continue
|
|
9
|
+
to work.
|
|
10
|
+
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import sys
|
|
14
|
+
import unittest
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
from .cleanup import GCLayerMixin
|
|
18
|
+
from .cleanup import SharedCleanupLayer
|
|
19
|
+
from .zope import ZopeComponentLayer
|
|
20
|
+
from .zope import ConfiguringLayerMixin
|
|
21
|
+
|
|
22
|
+
def find_test():
|
|
23
|
+
"""
|
|
24
|
+
The layer support in :class:`nose2.plugins.layers.Layers`
|
|
25
|
+
optionally supplies the test case object to ``testSetUp``
|
|
26
|
+
and ``testTearDown``, but ``zope.testrunner`` does not do
|
|
27
|
+
this. If you need access to the test, you can use an idiom like this::
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def testSetUp(cls, test=None):
|
|
31
|
+
test = test or find_test()
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
i = 2
|
|
35
|
+
while True:
|
|
36
|
+
try:
|
|
37
|
+
frame = sys._getframe(i) # pylint:disable=protected-access
|
|
38
|
+
i += 1
|
|
39
|
+
except ValueError: # pragma: no cover
|
|
40
|
+
return None
|
|
41
|
+
|
|
42
|
+
if isinstance(frame.f_locals.get('self'), unittest.TestCase):
|
|
43
|
+
return frame.f_locals['self']
|
|
44
|
+
if isinstance(frame.f_locals.get('test'), unittest.TestCase):
|
|
45
|
+
return frame.f_locals['test']
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
'GCLayerMixin',
|
|
49
|
+
'SharedCleanupLayer',
|
|
50
|
+
'ZopeComponentLayer',
|
|
51
|
+
'ConfiguringLayerMixin',
|
|
52
|
+
'find_test',
|
|
53
|
+
]
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Support for cleaning up:
|
|
5
|
+
|
|
6
|
+
- Garbage collection
|
|
7
|
+
- Registered cleanups.
|
|
8
|
+
|
|
9
|
+
.. versionadded:: 4.0.0
|
|
10
|
+
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import gc
|
|
14
|
+
|
|
15
|
+
import zope.testing.cleanup
|
|
16
|
+
|
|
17
|
+
from ..base import sharedCleanup
|
|
18
|
+
|
|
19
|
+
from hamcrest import assert_that
|
|
20
|
+
from hamcrest import is_
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
logger = __import__('logging').getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
class GCLayerMixin(object):
|
|
26
|
+
"""
|
|
27
|
+
Mixin this layer class and call :meth:`setUpGC` from
|
|
28
|
+
your layer `setUp` method and likewise for the teardowns
|
|
29
|
+
when you want to do GC.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
@classmethod
|
|
33
|
+
def setUp(cls):
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
@classmethod
|
|
37
|
+
def tearDown(cls):
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
def testSetUp(cls):
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
def testTearDown(cls):
|
|
46
|
+
# Must implement
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
@classmethod
|
|
50
|
+
def setUpGC(cls):
|
|
51
|
+
"""
|
|
52
|
+
This method disables GC until :meth:`tearDownGC` is called.
|
|
53
|
+
You should call it from your layer ``setUp`` method.
|
|
54
|
+
|
|
55
|
+
It also cleans up the zope.testing state.
|
|
56
|
+
"""
|
|
57
|
+
zope.testing.cleanup.cleanUp()
|
|
58
|
+
cls.__isenabled = gc.isenabled()
|
|
59
|
+
gc.disable()
|
|
60
|
+
|
|
61
|
+
@classmethod
|
|
62
|
+
def tearDownGC(cls):
|
|
63
|
+
"""
|
|
64
|
+
This method executes zope.testing's cleanup and then renables
|
|
65
|
+
GC. You should call if from your layer ``tearDown`` method.
|
|
66
|
+
"""
|
|
67
|
+
zope.testing.cleanup.cleanUp()
|
|
68
|
+
|
|
69
|
+
if cls.__isenabled:
|
|
70
|
+
gc.enable()
|
|
71
|
+
|
|
72
|
+
gc.collect(0) # collect one generation now to clean up weak refs
|
|
73
|
+
assert_that(gc.garbage, is_([]))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class SharedCleanupLayer(object):
|
|
77
|
+
"""
|
|
78
|
+
Mixin this layer when you need cleanup functions
|
|
79
|
+
that run for every test.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def setUp(cls):
|
|
84
|
+
# You MUST implement this, otherwise zope.testrunner
|
|
85
|
+
# will call the super-class again
|
|
86
|
+
zope.testing.cleanup.cleanUp()
|
|
87
|
+
|
|
88
|
+
@classmethod
|
|
89
|
+
def tearDown(cls):
|
|
90
|
+
# You MUST implement this, otherwise zope.testrunner
|
|
91
|
+
# will call the super-class again
|
|
92
|
+
zope.testing.cleanup.cleanUp()
|
|
93
|
+
|
|
94
|
+
@classmethod
|
|
95
|
+
def testSetUp(cls):
|
|
96
|
+
"""
|
|
97
|
+
Calls :func:`~.sharedCleanup` for every test.
|
|
98
|
+
"""
|
|
99
|
+
sharedCleanup()
|
|
100
|
+
|
|
101
|
+
@classmethod
|
|
102
|
+
def testTearDown(cls):
|
|
103
|
+
"""
|
|
104
|
+
Calls :func:`~.sharedCleanup` for every test.
|
|
105
|
+
"""
|
|
106
|
+
sharedCleanup()
|