1- # TEST FIXTURES
1+ # Test fixtures
22
3- ## RE-CREATION
3+ ## Model fixtures
4+
5+ Serialization and deserialization tests share BOM factories from
6+ [ ` tests/_data/models.py ` ] ( ../models.py ) . To cover a model change:
7+
8+ 1 . Add a descriptively named factory that starts with ` get_bom_ ` and returns a
9+ ` Bom ` . The function is discovered automatically; its name also becomes the
10+ snapshot filename prefix.
11+ 2 . Populate every field relevant to the change so the JSON and XML output
12+ tests exercise the complete model. Name a fixture ending in ` _invalid ` only
13+ when serialization is expected to fail.
14+ 3 . Register a factory in ` all_get_bom_funct_with_incomplete_deps ` when its
15+ dependency graph is intentionally incomplete. Otherwise, include the
16+ complete dependency graph in the returned BOM.
17+ 4 . Re-create the snapshots, review the changed files, then run the tests again
18+ without snapshot re-creation enabled.
19+ 5 . For version-specific fixtures, prefix the name with the target schema version
20+ tag (e.g. ` get_bom_v1_5_* ` ). The test runner uses ` is_valid_for_schema_version() `
21+ to ensure such models are only evaluated against applicable schema versions.
22+
23+ The output tests serialize each discovered model for the applicable schema
24+ versions, validate the generated JSON and XML, and compare it with the stored
25+ snapshots. The deserialization tests also use these fixtures for round-trip
26+ coverage.
27+
28+ ## Re-creation
429
530Some assets here can be (re-)created automatically, by setting the env var ` CDX_TEST_RECREATE_SNAPSHOTS=1 ` .
631It might also help to set ` PYTHONHASHSEED=0 ` !
@@ -10,4 +35,6 @@ As a shortcut just run:
1035CDX_TEST_RECREATE_SNAPSHOTS=1 poetry run tox -e py
1136```
1237
13- The files will be written as is, which might not be human-readable. feel free to reformat the files manually.
38+ Only commit snapshots that belong to the model change. Snapshot tests compare
39+ the serialized text with the stored fixture using exact string equality, so do
40+ not reformat snapshots manually.
0 commit comments