Unit tests for ipaddr.py, and add it to the coverage gate #24

Closed
opened 2026-10-03 10:59:11 -03:00 by marcos-mendez · 1 comment
marcos-mendez commented 2026-10-03 10:59:11 -03:00 (Migrated from github.com)

Context
ipaddr.py (about 100 lines: is_legal_ip, the IP class and IPRange) is used by the network screens in confconsole.py. Today it is only reached by accident from other tests and sits at 36 percent coverage, so the CI gate does not measure it. It is step 2 of the test plan in COVERAGE.md.

What to do

  1. Set up the tests locally:
    python3 -m venv .venv && . .venv/bin/activate
    pip install pytest coverage pyyaml
    PYTHONPATH=. python -m coverage run --branch --source=ipaddr -m pytest -q tests
    python -m coverage report --show-missing
    
  2. Add tests/test_ipaddr.py covering:
    • is_legal_ip: valid IPv4, too few or too many octets, an octet above 255, non-numeric text.
    • IP: built from a string, an int and another IP; str() and repr(); +, -, &, |, ^.
    • IPRange: from_cidr("192.0.2.0/24"), in for an address inside and outside, fmt_cidr() and str().
    • The Error raised for an argument IP does not accept.
  3. Test the current behaviour only. Making is_legal_ip accept IPv6 is separate planned work; do not change ipaddr.py.
  4. Add ipaddr to the package: list in .github/workflows/tests.yml so the gate measures it.

Done when

  • ipaddr.py is at 100 percent line and branch coverage.
  • ipaddr is in the measured package list and the tests check is green.
  • ipaddr.py itself is unchanged.

Help
Ask in https://github.com/orgs/Keel-Linux/discussions

**Context** `ipaddr.py` (about 100 lines: `is_legal_ip`, the `IP` class and `IPRange`) is used by the network screens in `confconsole.py`. Today it is only reached by accident from other tests and sits at 36 percent coverage, so the CI gate does not measure it. It is step 2 of the test plan in `COVERAGE.md`. **What to do** 1. Set up the tests locally: ``` python3 -m venv .venv && . .venv/bin/activate pip install pytest coverage pyyaml PYTHONPATH=. python -m coverage run --branch --source=ipaddr -m pytest -q tests python -m coverage report --show-missing ``` 2. Add `tests/test_ipaddr.py` covering: - `is_legal_ip`: valid IPv4, too few or too many octets, an octet above 255, non-numeric text. - `IP`: built from a string, an int and another `IP`; `str()` and `repr()`; `+`, `-`, `&`, `|`, `^`. - `IPRange`: `from_cidr("192.0.2.0/24")`, `in` for an address inside and outside, `fmt_cidr()` and `str()`. - The `Error` raised for an argument `IP` does not accept. 3. Test the current behaviour only. Making `is_legal_ip` accept IPv6 is separate planned work; do not change `ipaddr.py`. 4. Add `ipaddr` to the `package:` list in `.github/workflows/tests.yml` so the gate measures it. **Done when** - `ipaddr.py` is at 100 percent line and branch coverage. - `ipaddr` is in the measured package list and the `tests` check is green. - `ipaddr.py` itself is unchanged. **Help** Ask in https://github.com/orgs/Keel-Linux/discussions
Nandika-Gupta commented 2026-10-05 15:17:58 -03:00 (Migrated from github.com)

Hi @marcos-mendez! I'd like to work on this one too. I'll add tests/test_ipaddr.py for is_legal_ip, IP and IPRange, and add ipaddr to the coverage list in tests.yml. Will open a PR shortly.

Hi @marcos-mendez! I'd like to work on this one too. I'll add tests/test_ipaddr.py for is_legal_ip, IP and IPRange, and add ipaddr to the coverage list in tests.yml. Will open a PR shortly.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Keel-Linux/confconsole#24
No description provided.