Skip to content

Commit c3b32e2

Browse files
committed
test: switch from pytest-cache-assert to syrupy
1 parent ae793b8 commit c3b32e2

File tree

11 files changed

+165
-73
lines changed

11 files changed

+165
-73
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ repos:
3232
- id: detect-private-key
3333
- id: double-quote-string-fixer
3434
- id: end-of-file-fixer
35-
exclude: \.copier-answers\.yml
35+
exclude: \.copier-answers\.yml|__snapshots__/.*\.ambr
3636
- id: fix-byte-order-marker
3737
- id: fix-encoding-pragma
3838
args: [--remove]
3939
- id: forbid-new-submodules
4040
- id: mixed-line-ending
4141
args: [--fix=auto]
4242
- id: trailing-whitespace
43+
exclude: __snapshots__/.*\.ambr
4344
- repo: https://github.com/commitizen-tools/commitizen
4445
rev: 3.6.0
4546
hooks:
@@ -64,7 +65,7 @@ repos:
6465
# Note: this version must be the same as the hook revision
6566
6667
- "prettier-plugin-sh"
67-
exclude: \.copier-answers\.yml|tests/.*/cassettes/.*\.yaml|tests/.*assert-cache.*/.+\.json
68+
exclude: \.copier-answers\.yml|tests/.*/cassettes/.*\.yaml
6869
types_or: [html, javascript, json, shell, yaml]
6970
- repo: https://github.com/adrienverge/yamllint.git
7071
rev: v1.32.0

poetry.lock

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ dotted-notation = ">=0.9.2"
3535

3636
[tool.poetry.group.dev.dependencies]
3737
calcipy = {extras = ["doc", "lint", "nox", "stale", "tags", "test", "types"], version = ">=1.6.3"}
38-
pytest-cache-assert = ">=3.0.8"
3938
pytest-pretty = ">=1.0.1"
39+
syrupy = ">=4.4.0"
4040
tomli-w = ">=1.0.0"
4141

4242
[tool.poetry.scripts]
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# serializer version: 1
2+
# name: test_core[0]
3+
'''
4+
2023-01-31 06:16:00.910671-05:00 [DEBUG ] debug-level log record={'elapsed': {'repr': '0:00:00.340931', 'seconds':
5+
0.340931}, 'exception': None, 'extra': {'data': {'key1': 123}}, 'file': {'name': 'dodo.py', 'path':
6+
'/Users/kyleking/Developer/packages/tail-jsonl/dodo.py'}, 'function': '<module>', 'level': {'icon': '🐞', 'no': 10},
7+
'line': 31, 'module': 'dodo', 'name': 'dodo', 'process': {'id': 16268, 'name': 'MainProcess'}, 'thread': {'id':
8+
8821244160, 'name': 'MainThread'}, 'time': {'timestamp': 1675160160.910671}}
9+
∟ text: 2023-01-31 06:16:00.910 | DEBUG | dodo:<module>:31 - debug-level log
10+
11+
12+
'''
13+
# ---
14+
# name: test_core[1]
15+
'''
16+
2023-01-31 06:16:00.910915-05:00 [INFO ] info-level log record={'elapsed': {'repr': '0:00:00.341175', 'seconds':
17+
0.341175}, 'exception': None, 'extra': {}, 'file': {'name': 'dodo.py', 'path':
18+
'/Users/kyleking/Developer/packages/tail-jsonl/dodo.py'}, 'function': '<module>', 'level': {'icon': 'ℹ️', 'no': 20},
19+
'line': 32, 'module': 'dodo', 'name': 'dodo', 'process': {'id': 16268, 'name': 'MainProcess'}, 'thread': {'id':
20+
8821244160, 'name': 'MainThread'}, 'time': {'timestamp': 1675160160.910915}}
21+
∟ text: 2023-01-31 06:16:00.910 | INFO | dodo:<module>:32 - info-level log
22+
23+
24+
'''
25+
# ---
26+
# name: test_core[2]
27+
'''
28+
2023-01-31 06:16:00.911034-05:00 [WARNING] warning-level log record={'elapsed': {'repr': '0:00:00.341294', 'seconds':
29+
0.341294}, 'exception': None, 'extra': {}, 'file': {'name': 'dodo.py', 'path':
30+
'/Users/kyleking/Developer/packages/tail-jsonl/dodo.py'}, 'function': '<module>', 'level': {'icon': '⚠️', 'no': 30},
31+
'line': 33, 'module': 'dodo', 'name': 'dodo', 'process': {'id': 16268, 'name': 'MainProcess'}, 'thread': {'id':
32+
8821244160, 'name': 'MainThread'}, 'time': {'timestamp': 1675160160.911034}}
33+
∟ text: 2023-01-31 06:16:00.911 | WARNING | dodo:<module>:33 - warning-level log
34+
35+
36+
'''
37+
# ---
38+
# name: test_core[3]
39+
'''
40+
2023-01-31 06:16:00.911331-05:00 [ERROR ] error-level log record={'elapsed': {'repr': '0:00:00.341591', 'seconds':
41+
0.341591}, 'exception': None, 'extra': {}, 'file': {'name': 'dodo.py', 'path':
42+
'/Users/kyleking/Developer/packages/tail-jsonl/dodo.py'}, 'function': '<module>', 'level': {'icon': '❌', 'no': 40},
43+
'line': 34, 'module': 'dodo', 'name': 'dodo', 'process': {'id': 16268, 'name': 'MainProcess'}, 'thread': {'id':
44+
8821244160, 'name': 'MainThread'}, 'time': {'timestamp': 1675160160.911331}}
45+
∟ text: 2023-01-31 06:16:00.911 | ERROR | dodo:<module>:34 - error-level log
46+
47+
48+
'''
49+
# ---
50+
# name: test_core[4]
51+
'''
52+
2023-01-31 06:16:00.911499-05:00 [ERROR ] exception-level log record={'elapsed': {'repr': '0:00:00.341759', 'seconds':
53+
0.341759}, 'exception': {'type': 'ZeroDivisionError', 'value': 'integer division or modulo by zero', 'traceback': True},
54+
'extra': {}, 'file': {'name': 'dodo.py', 'path': '/Users/kyleking/Developer/packages/tail-jsonl/dodo.py'}, 'function':
55+
'<module>', 'level': {'icon': '❌', 'no': 40}, 'line': 38, 'module': 'dodo', 'name': 'dodo', 'process': {'id': 16268,
56+
'name': 'MainProcess'}, 'thread': {'id': 8821244160, 'name': 'MainThread'}, 'time': {'timestamp': 1675160160.911499}}
57+
∟ text: 2023-01-31 06:16:00.911 | ERROR | dodo:<module>:38 - exception-level log
58+
Traceback (most recent call last):
59+
60+
File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/bin/doit", line 8, in <module>
61+
sys.exit(main())
62+
│ │ └ <function main at 0x103c3a2a0>
63+
│ └ <built-in function exit>
64+
└ <module 'sys' (built-in)>
65+
File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/__main__.py", line 8, in
66+
main
67+
sys.exit(DoitMain().run(sys.argv[1:]))
68+
│ │ │ │ └ ['/Users/kyleking/Developer/packages/tail-jsonl/.venv/bin/doit', 'run', 'test']
69+
│ │ │ └ <module 'sys' (built-in)>
70+
│ │ └ <class 'doit.doit_cmd.DoitMain'>
71+
│ └ <built-in function exit>
72+
└ <module 'sys' (built-in)>
73+
File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/doit_cmd.py", line 294, in
74+
run
75+
return command.parse_execute(args)
76+
│ │ └ ['test']
77+
│ └ <function Command.parse_execute at 0x1037e0fe0>
78+
└ <doit.cmd_run.Run object at 0x103876f50>
79+
File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/cmd_base.py", line 150, in
80+
parse_execute
81+
return self.execute(params, args)
82+
│ │ │ └ ['test']
83+
│ │ └ {'dep_file': '.doit.db', 'backend': 'dbm', 'codec_cls': 'json', 'check_file_uptodate': 'md5',
84+
'dodoFile': 'dodo.py', 'cwdPath...
85+
│ └ <function DoitCmdBase.execute at 0x1037e1da0>
86+
└ <doit.cmd_run.Run object at 0x103876f50>
87+
File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/cmd_base.py", line 524, in
88+
execute
89+
self.loader.setup(params)
90+
│ │ │ └ {'dep_file': '.doit.db', 'backend': 'dbm', 'codec_cls': 'json', 'check_file_uptodate': 'md5',
91+
'dodoFile': 'dodo.py', 'cwdPath...
92+
│ │ └ <function DodoTaskLoader.setup at 0x1037e1800>
93+
│ └ <doit.cmd_base.DodoTaskLoader object at 0x102f748d0>
94+
└ <doit.cmd_run.Run object at 0x103876f50>
95+
File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/cmd_base.py", line 394, in
96+
setup
97+
self.namespace = dict(inspect.getmembers(loader.get_module(
98+
│ │ │ │ │ └ <function get_module at 0x102f6fce0>
99+
│ │ │ │ └ <module 'doit.loader' from
100+
'/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/loader.py'>
101+
│ │ │ └ <function getmembers at 0x102f1dbc0>
102+
│ │ └ <module 'inspect' from
103+
'/opt/homebrew/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/insp...
104+
│ └ None
105+
└ <doit.cmd_base.DodoTaskLoader object at 0x102f748d0>
106+
File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/loader.py", line 96, in
107+
get_module
108+
return importlib.import_module(os.path.splitext(file_name)[0])
109+
│ │ │ │ │ └ 'dodo.py'
110+
│ │ │ │ └ <function splitext at 0x102d0cea0>
111+
│ │ │ └ <module 'posixpath' (frozen)>
112+
│ │ └ <module 'os' (frozen)>
113+
│ └ <function import_module at 0x102f1cc20>
114+
└ <module 'importlib' from
115+
'/opt/homebrew/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/im...
116+
117+
File
118+
"/opt/homebrew/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py"
119+
, line 126, in import_module
120+
return _bootstrap._gcd_import(name[level:], package, level)
121+
│ │ │ │ │ └ 0
122+
│ │ │ │ └ None
123+
│ │ │ └ 0
124+
│ │ └ 'dodo'
125+
│ └ <function _gcd_import at 0x102c53d80>
126+
└ <module '_frozen_importlib' (frozen)>
127+
128+
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
129+
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
130+
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
131+
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
132+
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
133+
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
134+
135+
> File "/Users/kyleking/Developer/packages/tail-jsonl/dodo.py", line 36, in <module>
136+
1 // 0
137+
138+
ZeroDivisionError: integer division or modulo by zero
139+
140+
141+
'''
142+
# ---

tests/_private/test_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def read_logs() -> List[str]:
4545

4646

4747
@pytest.mark.parametrize('logs_index', [*range(len(LOGS))])
48-
def test_core(logs_index, assert_against_cache, console: Console):
48+
def test_core(logs_index, snapshot, console: Console):
4949
"""Smoketest core."""
5050
print_record(LOGS[logs_index], console, Config())
5151

@@ -54,7 +54,7 @@ def test_core(logs_index, assert_against_cache, console: Console):
5454
assert result.strip()
5555
assert '<no ' not in result
5656
if platform.system() != 'Windows':
57-
assert_against_cache(result)
57+
assert result == snapshot
5858

5959

6060
def test_core_no_key_matches(console: Console):

tests/assert-cache/README.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/assert-cache/_private/test_core/test_core[0].json

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/assert-cache/_private/test_core/test_core[1].json

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/assert-cache/_private/test_core/test_core[2].json

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/assert-cache/_private/test_core/test_core[3].json

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)