Skip to content

Commit

Permalink
test: switch from pytest-cache-assert to syrupy
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing committed Aug 30, 2023
1 parent ae793b8 commit c3b32e2
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 73 deletions.
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ repos:
- id: detect-private-key
- id: double-quote-string-fixer
- id: end-of-file-fixer
exclude: \.copier-answers\.yml
exclude: \.copier-answers\.yml|__snapshots__/.*\.ambr
- id: fix-byte-order-marker
- id: fix-encoding-pragma
args: [--remove]
- id: forbid-new-submodules
- id: mixed-line-ending
args: [--fix=auto]
- id: trailing-whitespace
exclude: __snapshots__/.*\.ambr
- repo: https://github.com/commitizen-tools/commitizen
rev: 3.6.0
hooks:
Expand All @@ -64,7 +65,7 @@ repos:
# Note: this version must be the same as the hook revision
- "prettier@3.0.0"
- "prettier-plugin-sh"
exclude: \.copier-answers\.yml|tests/.*/cassettes/.*\.yaml|tests/.*assert-cache.*/.+\.json
exclude: \.copier-answers\.yml|tests/.*/cassettes/.*\.yaml
types_or: [html, javascript, json, shell, yaml]
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.32.0
Expand Down
20 changes: 17 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ dotted-notation = ">=0.9.2"

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

[tool.poetry.scripts]
Expand Down
142 changes: 142 additions & 0 deletions tests/_private/__snapshots__/test_core.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# serializer version: 1
# name: test_core[0]
'''
2023-01-31 06:16:00.910671-05:00 [DEBUG ] debug-level log record={'elapsed': {'repr': '0:00:00.340931', 'seconds':
0.340931}, 'exception': None, 'extra': {'data': {'key1': 123}}, 'file': {'name': 'dodo.py', 'path':
'/Users/kyleking/Developer/packages/tail-jsonl/dodo.py'}, 'function': '<module>', 'level': {'icon': '🐞', 'no': 10},
'line': 31, 'module': 'dodo', 'name': 'dodo', 'process': {'id': 16268, 'name': 'MainProcess'}, 'thread': {'id':
8821244160, 'name': 'MainThread'}, 'time': {'timestamp': 1675160160.910671}}
∟ text: 2023-01-31 06:16:00.910 | DEBUG | dodo:<module>:31 - debug-level log


'''
# ---
# name: test_core[1]
'''
2023-01-31 06:16:00.910915-05:00 [INFO ] info-level log record={'elapsed': {'repr': '0:00:00.341175', 'seconds':
0.341175}, 'exception': None, 'extra': {}, 'file': {'name': 'dodo.py', 'path':
'/Users/kyleking/Developer/packages/tail-jsonl/dodo.py'}, 'function': '<module>', 'level': {'icon': 'ℹ️', 'no': 20},
'line': 32, 'module': 'dodo', 'name': 'dodo', 'process': {'id': 16268, 'name': 'MainProcess'}, 'thread': {'id':
8821244160, 'name': 'MainThread'}, 'time': {'timestamp': 1675160160.910915}}
∟ text: 2023-01-31 06:16:00.910 | INFO | dodo:<module>:32 - info-level log


'''
# ---
# name: test_core[2]
'''
2023-01-31 06:16:00.911034-05:00 [WARNING] warning-level log record={'elapsed': {'repr': '0:00:00.341294', 'seconds':
0.341294}, 'exception': None, 'extra': {}, 'file': {'name': 'dodo.py', 'path':
'/Users/kyleking/Developer/packages/tail-jsonl/dodo.py'}, 'function': '<module>', 'level': {'icon': '⚠️', 'no': 30},
'line': 33, 'module': 'dodo', 'name': 'dodo', 'process': {'id': 16268, 'name': 'MainProcess'}, 'thread': {'id':
8821244160, 'name': 'MainThread'}, 'time': {'timestamp': 1675160160.911034}}
∟ text: 2023-01-31 06:16:00.911 | WARNING | dodo:<module>:33 - warning-level log


'''
# ---
# name: test_core[3]
'''
2023-01-31 06:16:00.911331-05:00 [ERROR ] error-level log record={'elapsed': {'repr': '0:00:00.341591', 'seconds':
0.341591}, 'exception': None, 'extra': {}, 'file': {'name': 'dodo.py', 'path':
'/Users/kyleking/Developer/packages/tail-jsonl/dodo.py'}, 'function': '<module>', 'level': {'icon': '❌', 'no': 40},
'line': 34, 'module': 'dodo', 'name': 'dodo', 'process': {'id': 16268, 'name': 'MainProcess'}, 'thread': {'id':
8821244160, 'name': 'MainThread'}, 'time': {'timestamp': 1675160160.911331}}
∟ text: 2023-01-31 06:16:00.911 | ERROR | dodo:<module>:34 - error-level log


'''
# ---
# name: test_core[4]
'''
2023-01-31 06:16:00.911499-05:00 [ERROR ] exception-level log record={'elapsed': {'repr': '0:00:00.341759', 'seconds':
0.341759}, 'exception': {'type': 'ZeroDivisionError', 'value': 'integer division or modulo by zero', 'traceback': True},
'extra': {}, 'file': {'name': 'dodo.py', 'path': '/Users/kyleking/Developer/packages/tail-jsonl/dodo.py'}, 'function':
'<module>', 'level': {'icon': '❌', 'no': 40}, 'line': 38, 'module': 'dodo', 'name': 'dodo', 'process': {'id': 16268,
'name': 'MainProcess'}, 'thread': {'id': 8821244160, 'name': 'MainThread'}, 'time': {'timestamp': 1675160160.911499}}
∟ text: 2023-01-31 06:16:00.911 | ERROR | dodo:<module>:38 - exception-level log
Traceback (most recent call last):

File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/bin/doit", line 8, in <module>
sys.exit(main())
│ │ └ <function main at 0x103c3a2a0>
│ └ <built-in function exit>
└ <module 'sys' (built-in)>
File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/__main__.py", line 8, in
main
sys.exit(DoitMain().run(sys.argv[1:]))
│ │ │ │ └ ['/Users/kyleking/Developer/packages/tail-jsonl/.venv/bin/doit', 'run', 'test']
│ │ │ └ <module 'sys' (built-in)>
│ │ └ <class 'doit.doit_cmd.DoitMain'>
│ └ <built-in function exit>
└ <module 'sys' (built-in)>
File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/doit_cmd.py", line 294, in
run
return command.parse_execute(args)
│ │ └ ['test']
│ └ <function Command.parse_execute at 0x1037e0fe0>
└ <doit.cmd_run.Run object at 0x103876f50>
File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/cmd_base.py", line 150, in
parse_execute
return self.execute(params, args)
│ │ │ └ ['test']
│ │ └ {'dep_file': '.doit.db', 'backend': 'dbm', 'codec_cls': 'json', 'check_file_uptodate': 'md5',
'dodoFile': 'dodo.py', 'cwdPath...
│ └ <function DoitCmdBase.execute at 0x1037e1da0>
└ <doit.cmd_run.Run object at 0x103876f50>
File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/cmd_base.py", line 524, in
execute
self.loader.setup(params)
│ │ │ └ {'dep_file': '.doit.db', 'backend': 'dbm', 'codec_cls': 'json', 'check_file_uptodate': 'md5',
'dodoFile': 'dodo.py', 'cwdPath...
│ │ └ <function DodoTaskLoader.setup at 0x1037e1800>
│ └ <doit.cmd_base.DodoTaskLoader object at 0x102f748d0>
└ <doit.cmd_run.Run object at 0x103876f50>
File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/cmd_base.py", line 394, in
setup
self.namespace = dict(inspect.getmembers(loader.get_module(
│ │ │ │ │ └ <function get_module at 0x102f6fce0>
│ │ │ │ └ <module 'doit.loader' from
'/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/loader.py'>
│ │ │ └ <function getmembers at 0x102f1dbc0>
│ │ └ <module 'inspect' from
'/opt/homebrew/Cellar/python@3.11/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/insp...
│ └ None
└ <doit.cmd_base.DodoTaskLoader object at 0x102f748d0>
File "/Users/kyleking/Developer/packages/tail-jsonl/.venv/lib/python3.11/site-packages/doit/loader.py", line 96, in
get_module
return importlib.import_module(os.path.splitext(file_name)[0])
│ │ │ │ │ └ 'dodo.py'
│ │ │ │ └ <function splitext at 0x102d0cea0>
│ │ │ └ <module 'posixpath' (frozen)>
│ │ └ <module 'os' (frozen)>
│ └ <function import_module at 0x102f1cc20>
└ <module 'importlib' from
'/opt/homebrew/Cellar/python@3.11/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/im...

File
"/opt/homebrew/Cellar/python@3.11/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py"
, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
│ │ │ │ │ └ 0
│ │ │ │ └ None
│ │ │ └ 0
│ │ └ 'dodo'
│ └ <function _gcd_import at 0x102c53d80>
└ <module '_frozen_importlib' (frozen)>

File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed

> File "/Users/kyleking/Developer/packages/tail-jsonl/dodo.py", line 36, in <module>
1 // 0

ZeroDivisionError: integer division or modulo by zero


'''
# ---
4 changes: 2 additions & 2 deletions tests/_private/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def read_logs() -> List[str]:


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

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


def test_core_no_key_matches(console: Console):
Expand Down
5 changes: 0 additions & 5 deletions tests/assert-cache/README.md

This file was deleted.

12 changes: 0 additions & 12 deletions tests/assert-cache/_private/test_core/test_core[0].json

This file was deleted.

12 changes: 0 additions & 12 deletions tests/assert-cache/_private/test_core/test_core[1].json

This file was deleted.

12 changes: 0 additions & 12 deletions tests/assert-cache/_private/test_core/test_core[2].json

This file was deleted.

12 changes: 0 additions & 12 deletions tests/assert-cache/_private/test_core/test_core[3].json

This file was deleted.

0 comments on commit c3b32e2

Please sign in to comment.