pytest-regtest 2.2.0a2__py2.py3-none-any.whl → 2.2.1__py2.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.
@@ -2,13 +2,22 @@ from importlib.metadata import version as _version
2
2
 
3
3
  import pytest
4
4
 
5
- from . import register_third_party_handlers # noqa: F401
6
- from .pytest_regtest import PytestRegtestPlugin # noqa: F401
7
- from .pytest_regtest import RegtestStream # noqa: F401
8
5
  from .pytest_regtest import clear_converters # noqa: F401
9
6
  from .pytest_regtest import patch_terminal_size # noqa: F401
10
7
  from .pytest_regtest import register_converter_post # noqa: F401
11
8
  from .pytest_regtest import register_converter_pre # noqa: F401
9
+ from .pytest_regtest import (
10
+ PytestRegtestCommonHooks,
11
+ PytestRegtestPlugin,
12
+ RegtestStream,
13
+ Snapshot,
14
+ SnapshotPlugin,
15
+ )
16
+ from .register_third_party_handlers import (
17
+ register_numpy_handler,
18
+ register_pandas_handler,
19
+ )
20
+ from .snapshot_handler import register_python_object_handler
12
21
 
13
22
  __version__ = _version(__package__)
14
23
 
@@ -43,12 +52,17 @@ def pytest_addoption(parser):
43
52
  "--regtest-disable-stdconv",
44
53
  action="store_true",
45
54
  default=False,
46
- help="do not apply standard output converters to clean up indeterministic output",
55
+ help=(
56
+ "do not apply standard output converters to clean up indeterministic output"
57
+ ),
47
58
  )
48
59
 
49
60
 
50
61
  def pytest_configure(config):
51
- config.pluginmanager.register(PytestRegtestPlugin())
62
+ common = PytestRegtestCommonHooks()
63
+ config.pluginmanager.register(common)
64
+ config.pluginmanager.register(PytestRegtestPlugin(common))
65
+ config.pluginmanager.register(SnapshotPlugin(common))
52
66
 
53
67
 
54
68
  @pytest.fixture
@@ -56,7 +70,9 @@ def regtest(request):
56
70
  yield RegtestStream(request)
57
71
 
58
72
 
59
- snapshot = regtest
73
+ @pytest.fixture
74
+ def snapshot(request):
75
+ yield Snapshot(request)
60
76
 
61
77
 
62
78
  @pytest.fixture
@@ -65,3 +81,19 @@ def regtest_all(regtest):
65
81
 
66
82
 
67
83
  snapshot_all_output = regtest_all
84
+
85
+ register_python_object_handler()
86
+
87
+ try:
88
+ import pandas # noqa: F401
89
+
90
+ register_pandas_handler()
91
+ except ImportError:
92
+ pass
93
+
94
+ try:
95
+ import numpy # noqa: F401
96
+
97
+ register_numpy_handler()
98
+ except ImportError:
99
+ pass
@@ -148,6 +148,7 @@ class NumpyHandler(BaseSnapshotHandler):
148
148
  self, current_obj, current_as_text, recorded_obj, recorded_as_text, has_markup
149
149
  ):
150
150
  sub_diff = []
151
+
151
152
  for i, (l1, l2, r1, r2) in enumerate(
152
153
  zip(current_as_text, recorded_as_text, current_obj, recorded_obj)
153
154
  ):
@@ -193,4 +194,16 @@ class NumpyHandler(BaseSnapshotHandler):
193
194
  sub_diff.append(f"row {i:3d}: {l1}")
194
195
  sub_diff.append(f" {l2}")
195
196
 
197
+ missing = len(current_as_text) - len(recorded_as_text)
198
+ if missing > 0:
199
+ for i, row in enumerate(current_as_text[-missing:], len(recorded_as_text)):
200
+ # remove duplicate brackets
201
+ row = row.rstrip("]") + "]"
202
+ sub_diff.append(f"row {i:3d}: -{row.lstrip()}")
203
+ if missing < 0:
204
+ for i, row in enumerate(recorded_as_text[missing:], len(current_as_text)):
205
+ # remove duplicate brackets
206
+ row = row.rstrip("]") + "]"
207
+ sub_diff.append(f"row {i:3d}: +{row.lstrip()}")
208
+
196
209
  return sub_diff