Skip to content

Commit

Permalink
test: use syrupy
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing committed Aug 31, 2023
1 parent bce19d9 commit a2078ff
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 48 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
- "[email protected]"
- "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
16 changes: 15 additions & 1 deletion poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ hypothesis = {extras = ["cli"], version = ">=6.58.0"} # Use CLI with: "poetry ru
pytest-asyncio = ">=0.21.0"
pytest-recording = ">=0.12.0"
pytest-subprocess = ">=1.4.1"
syrupy = ">=4.4.0"
types-pyyaml = ">=6.0.12.6"
types-setuptools = ">=67.3.0.1"

Expand Down
22 changes: 22 additions & 0 deletions tests/code_tag_collector/__snapshots__/test_collector.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# serializer version: 1
# name: test__format_report
'''

| Type | Comment | Last Edit | Source File |
|--------|-----------|-------------|---------------------|
| TODO | Example 2 | N/A | data/test_project:1 |

Found code tags for TODO (1)

'''
# ---
# name: test__search_lines
list([
_CodeTag(lineno=2, tag='FIXME', text='Show README.md in the documentation (may need to update paths?)")'),
_CodeTag(lineno=3, tag='FYI', text='Replace src_examples_dir and make more generic to specify code to include in documentation'),
_CodeTag(lineno=4, tag='HACK', text='Show table of contents in __init__.py file'),
_CodeTag(lineno=7, tag='REVIEW', text='Show table of contents in __init__.py file'),
_CodeTag(lineno=10, tag='HACK', text='Support unconventional dashed code tags'),
_CodeTag(lineno=13, tag='FIXME', text='and FYI: in the same line, but only match the first'),
])
# ---
49 changes: 4 additions & 45 deletions tests/code_tag_collector/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_github_blame_url(clone_uri: str, expected: str):
assert github_blame_url(clone_uri) == expected


def test__search_lines():
def test__search_lines(snapshot):
lines = [
'# DEBUG: Show dodo.py in the documentation', # noqa: T001
'print("FIXME: Show README.md in the documentation (may need to update paths?)")', # noqa: T100
Expand All @@ -52,42 +52,10 @@ def test__search_lines():

comments = _search_lines(lines, re.compile(matcher))

# TODO: assert_against_cache(comments)
assert [_c.model_dump() for _c in comments] == [
{
'lineno': 2,
'tag': 'FIXME',
'text': 'Show README.md in the documentation (may need to update paths?)\")',
},
{
'lineno': 3,
'tag': 'FYI',
'text': 'Replace src_examples_dir and make more generic to specify code to include in documentation',
},
{
'lineno': 4,
'tag': 'HACK',
'text': 'Show table of contents in __init__.py file',
},
{
'lineno': 7,
'tag': 'REVIEW',
'text': 'Show table of contents in __init__.py file',
},
{
'lineno': 10,
'tag': 'HACK',
'text': 'Support unconventional dashed code tags',
},
{
'lineno': 13,
'tag': 'FIXME',
'text': 'and FYI: in the same line, but only match the first',
},
]
assert comments == snapshot


def test__format_report(fake_process):
def test__format_report(fake_process, snapshot):
fake_process.pass_command([fake_process.any()]) # Allow "git blame" and other commands to run unregistered
fake_process.keep_last_process(keep=True)
lines = ['# DEBUG: Example 1', '# TODO: Example 2'] # noqa: T101
Expand All @@ -100,16 +68,7 @@ def test__format_report(fake_process):

output = _format_report(TEST_DATA_DIR.parent, tagged_collection, tag_order=tag_order)

# TODO: assert_against_cache({'output': output.split('\n')})
assert output.split('\n') == [
'',
'| Type | Comment | Last Edit | Source File |',
'|--------|-----------|-------------|---------------------|',
'| TODO | Example 2 | N/A | data/test_project:1 |',
'',
'Found code tags for TODO (1)',
'',
]
assert output == snapshot


def test_write_code_tag_file_when_no_matches(fix_test_cache):
Expand Down

0 comments on commit a2078ff

Please sign in to comment.