aboutsummaryrefslogtreecommitdiff
path: root/tests/errors
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-06-30 16:34:20 +0530
committerGitHub <[email protected]>2026-06-30 16:34:20 +0530
commitbd3b12ff2f30c251c5fc52b43f81ec2f282d53ab (patch)
treece6e3f57da4c7d9af29c39df4dea78e54523cf3d /tests/errors
parent21ec7908c94839fff63b5275871cf84e92787a08 (diff)
parent6774eab5f8a1bbda930efd38d41d793557057aed (diff)
downloadedify-bd3b12ff2f30c251c5fc52b43f81ec2f282d53ab.tar.xz
edify-bd3b12ff2f30c251c5fc52b43f81ec2f282d53ab.zip
chore!: package reorg + uv/ruff/pytest/hatchling toolchain + Python 3.11 floor (#255)
## Summary Closes #68 — package reorganization to a single-purpose, dir-per-concern layout (no `src/`). Closes #69 — toolchain migration to `uv` + `ruff` + `pytest` + `hatchling` + `hatch-vcs`, driven entirely from `pyproject.toml`. Closes #253. Closes #259 — drop `.editorconfig`; LF / trim / final-newline / Python indent now enforced by `mixed-line-ending` (added in fixup) + existing pre-commit hooks + `ruff format`.— Python floor bump to 3.11; drops `py39` / `py310` / `pypy310` from the CI matrix. The three issues are paired by construction (dropping `src/` requires the new build backend's package discovery, and the 3.11 floor lets the new layout use `typing.Self`, frozen dataclasses, `match`/`case`, and Python-3.11 idioms throughout). ## Highlights **Layout** — `edify/builder/` (RegexBuilder + 11 mixin files + `types/` for state/flags/frame/protocol), `edify/elements/types/` (sealed dataclass union: 16 leaves, 7 char-shaped, 4 captures, 7 groups, 9 quantifiers, RootElement), `edify/compile/` (per-family render functions + dispatch, plus `quantifier/` subpackage for suffix + apply), `edify/validate/`, `edify/errors/` (typed exception hierarchy), `edify/library/` (per-validator files in family folders: `email/`, `ip/`, `date/`, plus flat single-validator files), `pattern/`, `serialize/`, `result/` skeletons. **Toolchain** — replaces `tox` / `virtualenv` / `flake8` / `isort` / `black` / `setup.py` / `setup.cfg` / `pytest.ini` / `.coveragerc` / `.bumpversion.cfg` / `MANIFEST.in` / `ci/` / `tests.local.sh` with `pyproject.toml`-driven `uv` + `ruff` + `pytest` + `hatchling` + `hatch-vcs`. CI workflow rewritten to `uv sync --frozen` + `uv run pytest`; required-status-check names preserved (`check`, `docs`, `py311 (ubuntu)`, `py312 (ubuntu)`, `py313 (ubuntu)`, `py314 (ubuntu)`, `pypy311 (ubuntu)`). Pre-commit replaced with `ruff` hooks, all hook repos pinned by commit SHA. **Tests** — reorganised under `tests/builder/` and `tests/library/<family>/` using the `*.test.py` naming shape. 173 tests, 100% line coverage, ruff lint + format clean, `uv build` produces sdist + wheel cleanly. ## Behaviour changes versus 0.3 These will get their own upgrade-guide entries when the migration tooling lands (#80): - `to_regex_string()` now returns the bare pattern (no `/.../` wrap). - `to_regex()` on a named back-reference compiles successfully via `(?P=name)` instead of raising. - Builder errors raise typed `EdifyError` subclasses (`MustBeAStringError`, `StartInputAlreadyDefinedError`, etc.) instead of bare `Exception` — catch via `except EdifyError`. - Internal helpers (`apply_quantifier`, `frame_creating_element`, `evaluate`, `state`, etc.) removed outright per the 0.3 → 1.0 stub-free policy.
Diffstat (limited to 'tests/errors')
-rw-r--r--tests/errors/errors.test.py153
1 files changed, 153 insertions, 0 deletions
diff --git a/tests/errors/errors.test.py b/tests/errors/errors.test.py
new file mode 100644
index 0000000..12cfcd5
--- /dev/null
+++ b/tests/errors/errors.test.py
@@ -0,0 +1,153 @@
+from edify.errors.anchors import (
+ CannotDefineStartAfterEndError,
+ EndInputAlreadyDefinedError,
+ StartInputAlreadyDefinedError,
+)
+from edify.errors.captures import InvalidTotalCaptureGroupsIndexError
+from edify.errors.input import (
+ MustBeAStringError,
+ MustBeInstanceError,
+ MustBeIntegerGreaterThanZeroError,
+ MustBeLessThanError,
+ MustBeOneCharacterError,
+ MustBePositiveIntegerError,
+ MustBeSingleCharacterError,
+ MustHaveASmallerValueError,
+)
+from edify.errors.internal import (
+ FailedToCompileRegexError,
+ NonFusableElementError,
+ UnexpectedFrameTypeError,
+ UnknownElementTypeError,
+)
+from edify.errors.naming import (
+ CannotCreateDuplicateNamedGroupError,
+ NamedGroupDoesNotExistError,
+ NameNotValidError,
+)
+from edify.errors.structure import (
+ CannotCallSubexpressionError,
+ CannotEndWhileBuildingRootExpressionError,
+)
+
+
+def test_start_input_already_defined_outside_subexpression():
+ error = StartInputAlreadyDefinedError()
+ assert "already has a start" in str(error)
+ assert "ignore_start_and_end" not in str(error)
+
+
+def test_start_input_already_defined_in_subexpression():
+ error = StartInputAlreadyDefinedError(in_subexpression=True)
+ assert "ignore_start_and_end" in str(error)
+
+
+def test_end_input_already_defined_outside_subexpression():
+ error = EndInputAlreadyDefinedError()
+ assert "already has an end" in str(error)
+ assert "ignore_start_and_end" not in str(error)
+
+
+def test_end_input_already_defined_in_subexpression():
+ error = EndInputAlreadyDefinedError(in_subexpression=True)
+ assert "ignore_start_and_end" in str(error)
+
+
+def test_cannot_define_start_after_end():
+ error = CannotDefineStartAfterEndError()
+ assert "start of input after defining an end" in str(error)
+
+
+def test_invalid_total_capture_groups_index():
+ error = InvalidTotalCaptureGroupsIndexError(5, 3)
+ assert "Invalid index #5" in str(error)
+ assert "only 3 capture groups" in str(error)
+
+
+def test_must_be_a_string():
+ error = MustBeAStringError("Name", "int")
+ assert "Name must be a string" in str(error)
+ assert "int" in str(error)
+
+
+def test_must_be_one_character():
+ error = MustBeOneCharacterError("Value")
+ assert "Value must be one character long" in str(error)
+
+
+def test_must_be_single_character():
+ error = MustBeSingleCharacterError("Value", "str")
+ assert "Value must be a single character" in str(error)
+ assert "str" in str(error)
+
+
+def test_must_be_positive_integer():
+ error = MustBePositiveIntegerError("count")
+ assert "count must be a positive integer" in str(error)
+
+
+def test_must_be_integer_greater_than_zero():
+ error = MustBeIntegerGreaterThanZeroError("x")
+ assert "x must be an integer greater than zero" in str(error)
+
+
+def test_must_be_instance():
+ error = MustBeInstanceError("Expression", "str", "RegexBuilder")
+ assert "Expression must be an instance of RegexBuilder" in str(error)
+ assert "str" in str(error)
+
+
+def test_must_have_a_smaller_value():
+ error = MustHaveASmallerValueError("z", "a")
+ assert "z must have a smaller character value than a" in str(error)
+
+
+def test_must_be_less_than():
+ error = MustBeLessThanError("X", "Y")
+ assert "X must be less than Y" in str(error)
+
+
+def test_name_not_valid():
+ error = NameNotValidError("bad name")
+ assert "Name bad name is not valid" in str(error)
+
+
+def test_cannot_create_duplicate_named_group():
+ error = CannotCreateDuplicateNamedGroupError("dup")
+ assert 'Can not create duplicate named group "dup"' in str(error)
+
+
+def test_named_group_does_not_exist():
+ error = NamedGroupDoesNotExistError("missing")
+ assert 'Named group "missing" does not exist' in str(error)
+
+
+def test_cannot_end_while_building_root_expression():
+ error = CannotEndWhileBuildingRootExpressionError()
+ assert "Can not end while building the root expression" in str(error)
+
+
+def test_cannot_call_subexpression():
+ error = CannotCallSubexpressionError("capture")
+ assert "Can not call subexpression" in str(error)
+ assert "capture" in str(error)
+
+
+def test_unknown_element_type():
+ error = UnknownElementTypeError("WeirdElement")
+ assert "WeirdElement" in str(error)
+
+
+def test_non_fusable_element():
+ error = NonFusableElementError("DigitElement")
+ assert "Cannot fuse element of type DigitElement" in str(error)
+
+
+def test_unexpected_frame_type():
+ error = UnexpectedFrameTypeError("DigitElement")
+ assert "Stack frame anchored at unexpected element type DigitElement" in str(error)
+
+
+def test_failed_to_compile_regex():
+ error = FailedToCompileRegexError("missing )")
+ assert "Cannot compile regex: missing )" in str(error)