Skip to content

test: add pytest unit test suite for CLI and ping core#1

Merged
bokiko merged 1 commit intomainfrom
auto/improve-2026-03-17
Mar 18, 2026
Merged

test: add pytest unit test suite for CLI and ping core#1
bokiko merged 1 commit intomainfrom
auto/improve-2026-03-17

Conversation

@bokiko
Copy link
Copy Markdown
Owner

@bokiko bokiko commented Mar 17, 2026

Summary

Adds the first test suite to PingDiff โ€” 68 pure unit tests covering the two core Python modules.

What was added

  • desktop/tests/test_ping_tester.py โ€” 35 tests for ping_tester.py
  • desktop/tests/test_cli.py โ€” 33 tests for cli.py
  • desktop/pytest.ini โ€” pytest configuration
  • IMPROVEMENTS.md โ€” improvement log (new file)

Test coverage

Module Functions tested Tests
ping_tester validate_ip, calculate_jitter, get_best_server, get_connection_quality 35
cli sort_results, filter_by_max_ping, results_to_json, results_to_csv, colorize, format_ping, format_loss, build_parser 33

All 68 tests pass. Tests are network-free and run in ~50ms.

Why

The codebase had zero tests despite having multiple CLI features (--sort, --max-ping, --output, --watch, --csv). This adds a regression safety net for all the core logic that doesn't require live network access.

Add the first test suite to the project โ€” 68 pure unit tests covering
the two core Python modules (ping_tester.py and cli.py).

Tests are network-free and subprocess-free; they run in ~50ms and work
offline, making them safe to run in CI before any network access.

Coverage includes:
- validate_ip: valid/invalid IPv4/IPv6, hostnames, injection strings
- calculate_jitter: empty, single-value, zero, alternating, high-jitter cases
- get_best_server: empty list, all-timeout, lowest-ping selection,
  packet-loss-beats-ping ordering, 100% loss exclusion
- get_connection_quality: all 5 quality tiers with boundary value checks
- sort_results: all 5 sort keys, timeout-last guarantee, unknown-key fallback
- filter_by_max_ping: pass-all, block-all, timeout exclusion, boundary edge cases
- results_to_json: valid JSON, field correctness, best-only, error case, empty
- results_to_csv: parseable output, header row, best-only, multiple rows
- Color helpers: no-color mode, format_ping, format_loss
- build_parser: defaults, flags, region/sort validation, type coercion

Files: desktop/tests/__init__.py, desktop/tests/test_ping_tester.py,
       desktop/tests/test_cli.py, desktop/pytest.ini
@bokiko bokiko merged commit 23bffbd into main Mar 18, 2026
1 check passed
@bokiko bokiko deleted the auto/improve-2026-03-17 branch March 21, 2026 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant