Skip to content

Commit

Permalink
test(changelog): add tests for changelog, compare with snapshots (syr…
Browse files Browse the repository at this point in the history
…upy module)
  • Loading branch information
tomassebestik committed Sep 29, 2024
1 parent 8de6c1d commit 49532aa
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 106 deletions.
11 changes: 5 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ minimum_pre_commit_version: 3.3.0
default_install_hook_types: [pre-commit, commit-msg]
default_stages: [commit]

exclude: '^tests/__snapshots__/'

repos:
- repo: meta
hooks:
Expand Down Expand Up @@ -30,6 +32,8 @@ repos:
rev: v1.11.2
hooks:
- id: mypy
args: ['--config-file', 'pyproject.toml']
exclude: 'tests/'

- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
Expand Down Expand Up @@ -66,18 +70,13 @@ repos:
args:
- --base64-limit=4
- --hex-limit=3
exclude: 'tests/'

- repo: https://github.com/lyz-code/yamlfix/
rev: 1.17.0
hooks:
- id: yamlfix

- repo: https://github.com/espressif/cz-plugin-espressif
rev: v1.0.1
hooks:
- id: update-changelog
files: ^pyproject\.toml$

- repo: local
hooks:
- id: pip-compile
Expand Down
35 changes: 26 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
<a href="https://www.espressif.com">
<img src="czespressif/templates/espressif-logo.svg" align="right" height="20" />
</a>

# CHANGELOG

> All notable changes to this project are documented in this file.
> This list is not exhaustive - only important changes, fixes, and new features in the code are reflected here.
<sub>The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
</sub>

---
<div align="center">
<img alt="Static Badge" src="https://img.shields.io/badge/Keep%20a%20Changelog-v1.1.0-salmon?logo=keepachangelog&logoColor=black&labelColor=white&link=https%3A%2F%2Fkeepachangelog.com%2Fen%2F1.1.0%2F">
<img alt="Static Badge" src="https://img.shields.io/badge/Conventional%20Commits-v1.0.0-pink?logo=conventionalcommits&logoColor=black&labelColor=white&link=https%3A%2F%2Fwww.conventionalcommits.org%2Fen%2Fv1.0.0%2F">
<img alt="Static Badge" src="https://img.shields.io/badge/Semantic%20Versioning-v2.0.0-grey?logo=semanticrelease&logoColor=black&labelColor=white&link=https%3A%2F%2Fsemver.org%2Fspec%2Fv2.0.0.html">
</div>
<hr>

## Unreleased

### 🐛 Bug fixes

- **changelog**: fix double title, header and footer on 'cz bump' *(Tomas Sebestik - f715e63)*
- **changelog**: fix double title, header and footer on 'cz bump' *(Tomas Sebestik - cce3c00)*

### 📖 Documentation

- **docker-example**: add run_command.txt for running demo container *(Tomas Sebestik - 0fa8c2e)*

### 🔧 Code refactoring

- **python-3.9**: refactor syntax and typing for python 3.9 *(Tomas Sebestik - 8de6c1d)*

---

## v1.1.0 (2024-09-24)
Expand Down Expand Up @@ -54,7 +64,14 @@

---

**[Espressif Systems CO LTD. (2024)](https://www.espressif.com/)**

- [Commitizen tools plugin with Espressif code style](https://www.github.com/espressif/cz-plugin-espressif)
- [Espressif Coding Standards and Best Practices](https://www.github.com/espressif/standards)
<div align="center">
<small>
<b>
<a href="https://www.github.com/espressif/cz-plugin-espressif">Commitizen Espressif plugin</a>
·
<a href="https://www.github.com/espressif/standards">Espressif Standards</a>
</b>
<br>
<sup><a href="https://www.espressif.com">Espressif Systems CO LTD. (2024)</a><sup>
</small>
</div>
142 changes: 59 additions & 83 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,31 @@ gitstyle := '%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s

# Helper function for quick menu
[private]
default:
@just --list
@default:
just --list


# .Edit this Justfile
edit-just:
# ... Edit this Justfile
@edit-just:
$EDITOR ./Justfile


# PROJECT: Install development environment
install:
pip uninstall -y czespressif commitizen
pip install --require-virtualenv -e '.[dev]'
pip install --require-virtualenv --upgrade pip


# PROJECT: Re-compile requirements.txt from dev-dependencies in pyproject.toml
lock-requirements:
pip-compile --strip-extras --output-file=requirements.txt pyproject.toml > /dev/null


# PROJECT: Release version info and list of commits since last release
@version:
cz bump --dry-run | grep -E 'change\(bump\)|tag to create|increment detected'; \
echo "\nCommits since last release:"; \
git log -n 30 --graph --pretty="{{gitstyle}}" v{{current_version}}..HEAD


# PROJECT: Run pre-commit linter(s)/formatter(s) on entire codebase
repo-pre-commit hook="":
pre-commit run {{hook}} --all-files
# PROJECT: Install development environment
@install:
pip install --require-virtualenv -e '.[dev,test]'
pip install --require-virtualenv --upgrade pip


# PROJECT: Re-compile requirements.txt from dev-dependencies in pyproject.toml
@lock-requirements:
pip-compile --strip-extras --output-file=requirements.txt pyproject.toml > /dev/null


# PROJECT: Remove caches, builds, reports and other generated files
Expand All @@ -57,26 +51,52 @@ repo-pre-commit hook="":
.ruff_cache \
*.egg-info \
**/__pycache__/ \
**/*.test.md \
build \
demo \
dist \
output/* \
:


# GIT: Revert the last commit - keeping changes staged
uncommit:
git reset --soft HEAD~1
# PROJECT: Build and check distribution package
@build:
just clean
python -m build
twine check dist/*


# PROJECT:
@bump-test:
clear
pre-commit run --all-files
cz bump --dry-run


# PYTEST: Run tests with coverage report
@test:
pytest

# PYTEST: Updade snapshots (known results) for pytest
@update-snapshots:
pytest --snapshot-update


# DOCKER: Test Build Docker image for demo
@docker-test-buildx:
cd docker && docker buildx build --platform linux/arm64,linux/amd64 -t tomasad/czespressif-demo . && cd -


# GIT: Unstage files without modifying them
unstage:
git reset HEAD --
# DOCKER: Build and push Docker image for demo
@docker-push-buildx:
cd docker && docker buildx build --platform linux/arm64,linux/amd64 -t tomasad/czespressif-demo --push . && cd -


# DOCKER: Run Docker image for demo
@docker-run directory=".":
pushd {{directory}} && docker run --rm -v $(pwd):/app -u $(id -u):$(id -g) tomasad/czespressif-demo && popd


# GIT: Show commits only on current branch
branch-commits base="master":
@branch-commits base="master":
@if git rev-parse --verify "{{base}}" > /dev/null 2>&1; then \
git log --first-parent --no-merges --graph --pretty="{{gitstyle}}" {{base}}..HEAD; \
else \
Expand All @@ -86,92 +106,48 @@ branch-commits base="master":


# GIT: Try commit again, open failed commit message it in the editor for corrections
recommit:
@recommit:
git commit --edit --file=$(git rev-parse --git-dir)/COMMIT_EDITMSG


# GIT: Run interactive "git rebase" command
rebase base="master":
@rebase base="master":
git fetch origin {{base}}
git rebase -i origin/{{base}}


# PROJECT: Build and pip install
@build:
just clean
pip uninstall -y czespressif commitizen
python -m build
twine check dist/*
pip install -e .
cz example >> /dev/null

# ----------------------------------------------

# TEST: Test the output of `cz bump` command
@test-cz-bump:
@generate-cz-bump:
clear
cz bump --dry-run | tee "output/cz-bump.test.md"


# TEST: Test the output of `cz example` command
@test-cz-example:
@generate-cz-example:
clear
cz example | tee "output/cz-example.test.md"


# TEST: Test the output of `cz info` command
@test-cz-info:
@generate-cz-info:
clear
cz info | tee "output/cz-info.test.md"


# TEST: Test the output of `cz schema` command
@test-cz-schema:
@generate-cz-schema:
clear
cz schema | tee "output/cz-schema.test.md"


# TEST: Test the output of `cz changelog` command
@test-changelog:
@generate-changelog:
clear
cz changelog --dry-run | tee "output/CHANGELOG.test.md"


# TEST: Test the output of `cz changelog --incremental` command
@test-changelog-incremental:
@generate-changelog-incremental:
clear
cz changelog --incremental --dry-run | tee "output/CHANGELOG-incremental.test.md"


# TEST: Test the output of `cz changelog v1.0.0` command
@test-release-notes:
@generate-release-notes:
clear
cz changelog v1.0.0 --template="RELEASE_NOTES.md.j2" --dry-run | tee "output/RELEASE_NOTES.test.md"


# TEST GROUP: Screen test to see the output, generate all files to 'output' directory
test:
just version
echo "Maximize terminal ...." && sleep 5; clear
just test-cz-bump && sleep 2; clear
just test-cz-info && sleep 2; clear
just test-cz-example && sleep 2; clear
just test-cz-schema && sleep 2; clear
just test-changelog && sleep 5; clear
just test-changelog-incremental && sleep 5; clear
just test-release-notes && sleep 5; clear
echo "Resize terminal, tests ends ...." && sleep 2; clear


# DOCKER: Build and push Docker image for demo
docker-buildx-test:
cd docker && docker buildx build --platform linux/arm64,linux/amd64 -t tomasad/czespressif-demo . && cd -


# DOCKER: Build and push Docker image for demo
docker-buildx-push:
cd docker && docker buildx build --platform linux/arm64,linux/amd64 -t tomasad/czespressif-demo --push . && cd -


# DOCKER: Run Docker image for demo
docker-run go_dir=".":
pushd {{go_dir}} && docker run --rm -v $(pwd):/app -u $(id -u):$(id -g) tomasad/czespressif-demo && popd
cz changelog v1.1.0 --template="RELEASE_NOTES.md.j2" --dry-run | tee "output/RELEASE_NOTES.test.md"
1 change: 1 addition & 0 deletions czespressif/templates/CHANGELOG.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
{# Render the footer only for full changelog, not for cz bump #}
{% if config.changelog_footer and config.changelog_footer|length > 0 %}{# ---CHANGELOG FOOTER #}
---{# Add horizontal line before the footer, only if the footer is not empty #}

{% if not config.incremental %}
{{ config.changelog_footer }}{# CHANGELOG FOOTER--- #}
{% endif %}
Expand Down
22 changes: 14 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
dependencies = ["commitizen>=3.29.0"]

[project.optional-dependencies]
dev = [
"just-bin~=1.26.0",
"pip-tools~=7.3",
dev = ["just-bin~=1.26.0", "pip-tools~=7.3", "pre-commit~=3.3.0", "twine~=5.1.1"]
test = [
"pytest-cov~=4.1.0",
"pytest-mock~=3.14.0",
"pytest-sugar~=1.0.0",
"pytest~=7.4.0",
"twine~=5.1.1",
"syrupy~=4.7.0",
]
test = ["pytest-cov~=4.1.0", "pytest~=7.4.0"]

[project.entry-points."commitizen.plugin"]
czespressif = "czespressif:CzPluginEspressif"
Expand Down Expand Up @@ -61,9 +61,15 @@
skip = 'tests/*'

[tool.ruff]
extend-exclude = ["tests/.*"]
extend-exclude = []
line-length = 160

[tool.ruff.per-file-ignores]
"tests/*" = [
"PLR0913", # PYLINT: Ignore Too many arguments in tests directory
"S101", # BANDIT: Ignore use of assert in tests directory
]

[tool.ruff.format]
quote-style = "single"

Expand All @@ -75,7 +81,7 @@
lines-between-types = 1

[tool.mypy]
exclude = ["venv"]
exclude = ["^__init__.py$", "^build/.*", "^dist/.*", "^docs/.*", "^tests/.*"]
ignore_missing_imports = true
packages = "czespressif"
pretty = true
Expand All @@ -84,7 +90,7 @@
warn_return_any = true

[tool.pytest.ini_options]
addopts = "-s --log-cli-level DEBUG --cov=sample_python_app --cov-report=term"
addopts = "--log-cli-level DEBUG --cov=czespressif --cov-report=term"

[tool.coverage.run]
omit = ["*/tests/*", "__*__.py"]
Expand Down
Loading

0 comments on commit 49532aa

Please sign in to comment.