Skip to content

Latest commit

 

History

History
 
 

tests

README.md

Running the tests

All commands below are run from the repository root. Running a test file directly by path (python3 tests/files/load_tests.py) fails with ModuleNotFoundError: No module named 'estimators', because the repo root is not on sys.path in that mode.

python3 -m unittest tests.<package>.<module>

Test suites

Suite Command Needs a generated fixture?
Files - shallow scan python3 -m unittest tests.files.shallow_estimator_test No
Files - deep scan load python3 -m unittest tests.files.load_tests Yes
Chat python3 -m unittest tests.chat.estimator_test tests.chat.scanner_test No
EO in-place archives - sanity python3 -m unittest tests.eo_in_place_archives.sanity_tests No
EO in-place archives - load python3 -m unittest tests.eo_in_place_archives.load_tests Yes
EO shared mailboxes - sanity python3 -m unittest tests.eo_shared_mail_boxes.sanity_tests No
EO shared mailboxes - load python3 -m unittest tests.eo_shared_mail_boxes.load_tests Yes
EO group mailboxes - sanity python3 -m unittest tests.eo_group_mailboxes.sanity_tests No
Integration (live, see below) python3 -m unittest tests.integration.exchange_test tests.integration.chat_test tests.integration.files_test tests.integration.failure_handling_test No, but needs credentials

Load tests need a fixture first

The load tests replay a large synthetic tenant. That tenant is not checked in (.gitignore excludes tests/*/test_data/), so it has to be generated once before the suite can run. Without it the suite fails fast with FileNotFoundError: Test data not found at ... Please run data_state_creator.py first.

python3 tests/files/data_state_creator.py
python3 tests/eo_in_place_archives/data_state_creator.py
python3 tests/eo_shared_mail_boxes/data_state_creator.py

Each generator writes tests/<suite>/test_data/state.json, which is the path the matching load test reads by default.

Every generator also computes the expected result alongside the raw tenant data, so a fixture generated by an older revision of data_state_creator.py will keep asserting the old expectations. Regenerate the fixture whenever a generator or the aggregation logic it mirrors changes.

Reproducible fixtures

Pass --seed to get a deterministic tenant. The file is then named after the seed, and the test is pointed at it with TEST_DATA_PATH:

python3 tests/files/data_state_creator.py --seed 7
TEST_DATA_PATH=tests/files/test_data/state_7.json python3 -m unittest tests.files.load_tests

Keep the tests offline

No test may reach the network, except the integration tests in tests/integration/ (see the last section). EOInPlaceArchiveEstimator authenticates its auxiliary TokenManager inside __init__, so its tests patch TokenManager.authenticate_all in setUp before constructing the estimator. If that patch is dropped, authentication fails against the fake tenant, the estimator's except branch sets the stop event, and every assertion in the suite silently collapses to zero rather than erroring out. Apply the same pattern to any new estimator that authenticates during construction.

Common failures

Symptom Cause Fix
ModuleNotFoundError: No module named 'estimators' Ran the file by path Run via python3 -m unittest tests.<pkg>.<module> from the repo root
FileNotFoundError: Test data not found at ... Fixture never generated Run the suite's data_state_creator.py
A load test reports counts that are all 0 The estimator hit the network during construction and set the stop event Patch the estimator's authentication in setUp
A load test is off by a small constant The fixture's expectations disagree with the estimator Regenerate the fixture; if it still disagrees, the generator and estimator have genuinely diverged

Integration tests call Microsoft

Every suite above runs offline. The suite in tests/integration/ is the one exception: it runs the planners end to end against a real Microsoft 365 test tenant. It is skipped unless credentials are provided, so running it without them makes no network calls. See tests/integration/README.md.