tests.test_sbom module

tests.test_sbom.assert_valid_cyclonedx(content, export_format)[source]

Assert a CycloneDX export validates against its schema.

This guarantee used to live in meta_package_manager.sbom.cyclonedx.CycloneDX.export() at runtime. It moved here so the jsonschema-based validation stack (rfc3987-syntax, lark, lxml) stays out of mpm’s runtime dependencies. See meta_package_manager.sbom.

Return type:

None

tests.test_sbom.test_package_purl_carries_the_namespace()[source]

The pURL of a scoped npm package holds its scope as namespace.

The npm type definition expects it there.

tests.test_sbom.test_registered_purl(monkeypatch, manager_id, package_id, version, arch, vendor, expected)[source]

A package gets the pURL of its registered type, when mpm can build one.

tests.test_sbom.test_cyclonedx_publishes_the_registered_purl()[source]

A component carries the pURL of its type, and its manager pURL as bom-ref.

packageurl-python would lowercase the npm name, which the npm type keeps.

tests.test_sbom.test_spdx_leads_with_the_registered_purl()[source]

The pURL of the registered type comes first, the manager pURL second.

tests.test_sbom.test_advisory_of_the_registered_purl_reaches_the_package(renderer_class)[source]

An advisory found under the pURL of the registered type lands on the package.

tests.test_sbom.test_file_autodetect(file_path, expected)[source]
tests.test_sbom.test_normalize_spdx_id(raw_str, expected)[source]
tests.test_sbom.test_minimal_mode_emits_bare_spdx_payload()[source]

Minimal mode reproduces the legacy bare output.

Rich metadata is ignored, no relationships beyond DESCRIBES are emitted, and download_location falls back to NOASSERTION.

tests.test_sbom.test_bundled_mode_spdx_populates_rich_fields()[source]

A populated package metadata flows into the SPDX document.

A PackageMetadata gives the license, supplier override, originator, checksum, and a dependency relationship resolved at finalize() time.

tests.test_sbom.test_bundled_mode_cyclonedx_populates_rich_fields()[source]

The CycloneDX renderer projects the same metadata.

It lands in hashes, licenses, supplier, external references, and dependency edges.

tests.test_sbom.test_cyclonedx_compound_license_expression_details(expression, expected_identifiers)[source]

Compound expressions emit LicenseExpression.details.

The details carry a canonical SPDX URL per identifier, deduped and sorted by identifier.

tests.test_sbom.test_spdx_license_normalization(declared, expected_present)[source]

The SPDX renderer makes a schema-valid document for every input it accepts.

tests.test_sbom.test_spdx_merges_external_per_package_sbom(tmp_path)[source]

The renderer adopts transitive deps from an upstream SPDX file.

The file is a per-package one, and the renderer records the merge in externalDocumentRefs.

The fixture mirrors the shape of Homebrew’s <prefix>/Cellar/<formula>/<version>/sbom.spdx.json.

tests.test_sbom.test_stats_track_per_manager_and_merge_counts(tmp_path)[source]

SBOM.stats() must reflect what landed in the document.

Two packages from a single manager land normally; one of them carries an external SBOM file containing one transitive dep, which gets spliced in. The SPDX-specific stats then report: inventory=2, in_document=3, merged_documents=1.

tests.test_sbom.test_cyclonedx_stats_count_external_bom_refs(tmp_path)[source]

CycloneDX stats report external BOM refs and dependency edges.

tests.test_sbom.test_spdx_renders_attached_vulnerabilities()[source]

Attached advisories become SECURITY external refs in SPDX.

tests.test_sbom.test_cyclonedx_renders_attached_vulnerabilities()[source]

Attached advisories become a CycloneDX vulnerabilities array entry.

tests.test_sbom.UPSTREAM_ALIAS = 'pkg:pypi/yt-dlp@2026.8.19'

Registry coordinate Homebrew records beside a formula’s own purl.

Stands in for what the Homebrew extractor lifts out of sbom.spdx.json: OSV answers for this one, never for the pkg:brew/... the inventory pass assigns.

tests.test_sbom.test_all_purls_yields_aliases(renderer_class)[source]

The scan queries the alias: it is the only answerable coordinate.

tests.test_sbom.test_resolve_purl_targets_names_every_owner(renderer_class)[source]

The key comes first, then its alias owners. An unknown key stands alone.

tests.test_sbom.test_one_coordinate_shared_by_two_packages_reaches_both(renderer_class)[source]

Two formulae built from one upstream both own its advisories.

tests.test_sbom.test_cyclonedx_one_advisory_reaches_every_alias_owner()[source]

An advisory shared through one alias emits once, affecting both.

tests.test_sbom.test_stats_count_the_packages_an_alias_reaches(renderer_class)[source]

vulnerable_packages counts packages, not the coordinates queried.

tests.test_sbom.test_spdx_advisory_found_under_an_alias_lands_on_the_formula()[source]

An advisory keyed by the upstream purl attaches to the brew package.

tests.test_sbom.test_cyclonedx_advisory_found_under_an_alias_affects_the_formula()[source]

affects addresses the component by its own bom_ref, not the alias.

tests.test_sbom.test_shared_advisory_deduplicated_in_cyclonedx()[source]

One advisory affecting two components yields a single record.

The record has two affects targets.