test: add pytest unit test suite for CLI and ping core#1
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 forping_tester.pydesktop/tests/test_cli.pyโ 33 tests forcli.pydesktop/pytest.iniโ pytest configurationIMPROVEMENTS.mdโ improvement log (new file)Test coverage
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.