From f03ffa57f20b18d04a9f5fd99cf08a64cd765e2d Mon Sep 17 00:00:00 2001 From: harmehak0173 Date: Wed, 7 Oct 2026 12:42:29 -0400 Subject: [PATCH 1/2] docs: document contributor testing workflow --- .github/CONTRIBUTING.md | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 19549180..3b5af539 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -16,6 +16,73 @@ Follow [Google style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) for docstrings. +## Testing + +When contributing bug fixes or new features, add unit tests to verify the +behavior and prevent regressions. + +### 1. Locate the relevant test file + +Test files live in the `tests/` directory and mirror the modules in +`src/humanize/`: + +- `tests/test_number.py` for number formatting (`intcomma`, `clamp`, `ordinal`, + etc.) +- `tests/test_time.py` for time utilities (`naturaltime`, `naturaldelta`, + `naturaldate`, etc.) +- `tests/test_filesize.py` for file size formatting (`naturalsize`) +- `tests/test_lists.py` for list formatting (`natural_list`) +- `tests/test_i18n.py` for internationalization and locale translations + +### 2. Follow existing test patterns and use parameterization + +Follow `pytest` conventions and use `@pytest.mark.parametrize` when testing +multiple inputs or boundary conditions. + +For example, when testing boundary behavior such as `humanize.clamp()`: + +```python +@pytest.mark.parametrize( + ("value", "format", "floor", "ceil", "expected"), + [ + (5, "%s", 0, 10, "5"), + (-1, "%s", 0, 10, "0"), + (15, "%s", 0, 10, "10"), + ], +) +def test_clamp_boundaries(value, format, floor, ceil, expected): + assert humanize.clamp(value, format=format, floor=floor, ceil=ceil) == expected +``` + +### 3. Run focused tests locally + +Run only the relevant test file or specific test case while developing: + +```sh +pytest tests/test_number.py +pytest tests/test_number.py -k test_clamp +``` + +### 4. Verify that the test catches regressions + +Before finalizing your changes, intentionally introduce a defect or temporarily +revert your implementation to verify that the new test fails. This confirms that +the test actively protects against regressions rather than passing vacuously. + +### 5. Run the full test suite + +Run the complete test suite locally before opening a pull request: + +```sh +pytest +``` + +Or using `tox` across supported environments: + +```sh +tox +``` + ## Localization See [README](https://github.com/python-humanize/humanize#localization). From a953c58087d6c4c89d6c66c058933c6cc46b9126 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Oct 2026 16:43:33 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .github/CONTRIBUTING.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 3b5af539..5c01ccef 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -18,26 +18,24 @@ for docstrings. ## Testing -When contributing bug fixes or new features, add unit tests to verify the -behavior and prevent regressions. +When contributing bug fixes or new features, add unit tests to verify the behavior and +prevent regressions. ### 1. Locate the relevant test file -Test files live in the `tests/` directory and mirror the modules in -`src/humanize/`: +Test files live in the `tests/` directory and mirror the modules in `src/humanize/`: -- `tests/test_number.py` for number formatting (`intcomma`, `clamp`, `ordinal`, +- `tests/test_number.py` for number formatting (`intcomma`, `clamp`, `ordinal`, etc.) +- `tests/test_time.py` for time utilities (`naturaltime`, `naturaldelta`, `naturaldate`, etc.) -- `tests/test_time.py` for time utilities (`naturaltime`, `naturaldelta`, - `naturaldate`, etc.) - `tests/test_filesize.py` for file size formatting (`naturalsize`) - `tests/test_lists.py` for list formatting (`natural_list`) - `tests/test_i18n.py` for internationalization and locale translations ### 2. Follow existing test patterns and use parameterization -Follow `pytest` conventions and use `@pytest.mark.parametrize` when testing -multiple inputs or boundary conditions. +Follow `pytest` conventions and use `@pytest.mark.parametrize` when testing multiple +inputs or boundary conditions. For example, when testing boundary behavior such as `humanize.clamp()`: @@ -65,9 +63,9 @@ pytest tests/test_number.py -k test_clamp ### 4. Verify that the test catches regressions -Before finalizing your changes, intentionally introduce a defect or temporarily -revert your implementation to verify that the new test fails. This confirms that -the test actively protects against regressions rather than passing vacuously. +Before finalizing your changes, intentionally introduce a defect or temporarily revert +your implementation to verify that the new test fails. This confirms that the test +actively protects against regressions rather than passing vacuously. ### 5. Run the full test suite