Skip to content

Commit

Permalink
test: start using benchmark, pytest-subprocess, and pytest-cache-assert
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing committed Feb 27, 2022
1 parent a28cd27 commit 884ff91
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 54 deletions.
1 change: 0 additions & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ runs:
key: ${{ inputs.os }}-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock')
}}
- name: Install Project and Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
poetry install -E dev -E lint -E test -E commitizen_legacy
shell: bash
9 changes: 7 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,22 @@ repos:
(https://copier.readthedocs.io/en/stable/updating/)
language: fail
files: \.rej$
# Note: there are occasional errors when running doit in pre-commit
# Moving the .doit.db outside of the git directory helps, but there
# are obvious drawbacks
# "doit.dependency.DatabaseException: [Errno 35] Resource
# temporarily unavailable: '.doit.db'"
- id: python-formatter
name: Python Auto-Formatter
description: Apply calcipy formatting
language: system
entry: poetry run doit run format_py
entry: poetry run doit run --db-file=../.pre-commit-doit.db format_py
types: [python]
stages: [push]
- id: toml-formatter
name: Optional TOML Auto-Formatter
description: Install taplo with 'npm install -g @taplo/cli'
language: system
entry: poetry run doit run format_toml
entry: poetry run doit run --db-file=../.pre-commit-doit.db format_toml
types: [toml]
exclude: poetry\.lock
6 changes: 3 additions & 3 deletions calcipy/log_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from inspect import signature
from pathlib import Path

import loguru
from beartype import beartype
from beartype.typing import Any, Callable, Dict, Generator, Iterable, List, Optional
from decorator import contextmanager, decorator
Expand Down Expand Up @@ -74,14 +75,13 @@ def serializable_compact(record: Dict[str, Any]) -> str:
return str_json + '\n'


# Note: loguru.Logger is PEP563 Postponed and can't be use with beartype runtime

# FYI: loguru.Logger is PEP563 Postponed and can't be use with beartype runtime
def _log_action(
message: str, level: str = 'INFO',
_logger: loguru.Logger = logger, # pylint: disable=no-member
**kwargs: Any,
) -> Generator[loguru.Logger, None, None]: # pylint: disable=no-member
"""Log the beggining and end of an action.
"""Log the beginning and end of an action.
Args:
message: string message to describe the context
Expand Down
108 changes: 102 additions & 6 deletions poetry.lock

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

10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,17 @@ yamllint = { version = ">=1.26", optional = true }
# Test
coverage = { version = ">=6", optional = true }
diff-cover = { version = ">=6.4", optional = true }
hypothesis = { version = ">=6.38.0", optional = true }
lxml = { version = ">=4.7.1", optional = true } # required for the HTML mypy report format
mypy = { version = ">=0.812", optional = true }
nox-poetry = { version = ">=0.8", optional = true }
pytest = { version = ">=6", optional = true }
pytest-benchmark = { version = ">=3.4.1", optional = true }
pytest-cache-assert = { version = ">=1.1.1", optional = true }
pytest-html = { version = ">=3.1", optional = true }
pytest-randomly = { version = ">=3.8", optional = true }
pytest-recording = { version = ">=0.11", optional = true }
pytest-subprocess = { version = ">=1.4.1", optional = true }
pytest-watcher = { version = ">=0.2", optional = true } # https://github.com/joeyespo/pytest-watch/issues/121

# commitizen_legacy
Expand All @@ -186,9 +189,9 @@ cz_legacy = { version = ">=0.1.2", optional = true }
dev = [
"better-exceptions",
"commitizen",
"livereload",
"mkdocs-git-revision-date-localized-plugin",
"mkdocs-material",
"livereload",
"pdbpp",
"pdocs",
"pyupgrade",
Expand Down Expand Up @@ -251,15 +254,18 @@ lint = [
test = [
"coverage",
"diff-cover",
"hypothesis",
"lxml",
"mypy",
"nox-poetry",
"pytest",
"pytest-benchmark",
"pytest-cache-assert",
"pytest-html",
"pytest-randomly",
"pytest-recording",
"pytest-subprocess",
"pytest-watcher",
"pytest",
]
commitizen_legacy = ["cz_legacy"]

Expand Down
6 changes: 6 additions & 0 deletions tests/assert-cache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Pytest Assert Cache

This folder is automatically generated by `pytest_cache_assert`.

Files can be regenerated by deleting and allowing `pytest_cache_assert` to
recreate them when next running the test suite.
19 changes: 19 additions & 0 deletions tests/assert-cache/test_format_report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"_info": [
{
"func_args": {},
"test_file": "test_code_tag_collector.py",
"test_name": "test_format_report"
}
],
"_json": {
"output": [
"| Type | Comment | Last Edit | Source File |",
"|:-------|:----------|:------------|:------------------------|",
"| TODO | Example 2 | N/A | .test_calcipy_project:1 |",
"",
"Found code tags for TODO (1)",
""
]
}
}
41 changes: 41 additions & 0 deletions tests/assert-cache/test_search_lines.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"_info": [
{
"func_args": {},
"test_file": "test_code_tag_collector.py",
"test_name": "test_search_lines"
}
],
"_json": [
{
"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"
}
]
}
Loading

0 comments on commit 884ff91

Please sign in to comment.