Skip to content

Golden Tests

chris-day edited this page Nov 21, 2025 · 9 revisions

Golden Tests – Full Detailed Specification

This document explains the Golden Test framework used by uml2semantics-python to ensure deterministic and reproducible ontology generation.
Golden Tests are especially important for standards-based ontologies, such as ISO 20022, where stability and version control are critical.


1. Purpose of Golden Tests

Golden tests validate:

  • Deterministic OWL output across runs
  • Consistent choice semantics
  • Stable datatype facet handling
  • Enumeration value generation
  • Correct annotation attachment
  • Proper prefix management
  • No unexpected changes caused by refactoring or dependency updates

They serve as a contract between the TSV specification and the OWL generator.


2. Structure of the Golden Test Suite

A typical folder layout:

tests/
  golden/
    case-001-basic/
      Classes.tsv
      Attributes.tsv
      expected.ttl

    case-002-datatypes/
      Classes.tsv
      Attributes.tsv
      Datatypes.tsv
      expected.ttl

    case-003-enumerations/
      Enumerations.tsv
      EnumerationNamedValues.tsv
      expected.ttl

    case-004-choice-exclusive/
      Classes.tsv
      expected.ttl

    case-005-full-model/
      Classes.tsv
      Attributes.tsv
      Datatypes.tsv
      Enumerations.tsv
      EnumerationNamedValues.tsv
      AnnotationProperties.tsv
      Annotations.tsv
      expected.ttl

Each case includes:

  • A self-contained set of TSV inputs
  • An expected.ttl output
  • Optional annotations TSV files

3. Canonicalisation of Output

Golden tests rely on canonical Turtle so that diffs reflect meaningful changes only.

The canonicaliser enforces:

  • Alphabetical prefix ordering
  • Alphabetical triple ordering
  • Deterministic blank node ordering
  • Consistent indentation
  • Stable union/disjoint representation

This prevents false test failures caused by:

  • OS differences
  • Python library serialisation differences
  • Metadata or timestamp variance

4. Golden Test Execution Pipeline

Each golden test follows a standard pipeline:

Step 1 – Load TSV Inputs

Test runner reads .tsv files in the case folder.

Step 2 – Generate OWL

The converter constructs the ontology graph.

Step 3 – Canonicalise Turtle

Turtle is normalised using the canonicaliser.

Step 4 – Compare with expected.ttl

If equal → pass
If not equal → fail (with diff)

Example diff:

--- expected.ttl
+++ actual.ttl
@@ -12,7 +12,7 @@
 iso:GBP a iso:CurrencyCode .
-iso:EUR a iso:CurrencyCode .
+iso:EUR a iso:CurrencyCode ; rdfs:label "Euro" .

5. Example Golden Test Case: Exclusive Choice

Classes.tsv

Curie     Name                     ChoiceOf         ChoiceSemantics
ex:Choice PartyIdentifierChoice    LEIId|BICId      exclusive
ex:LEIId  LEIId
ex:BICId  BICId

expected.ttl (Extract)

ex:PartyIdentifierChoice rdfs:subClassOf [
    owl:unionOf ( ex:LEIId ex:BICId )
] .

ex:PartyIdentifierChoice owl:disjointWith ex:LEIId .
ex:PartyIdentifierChoice owl:disjointWith ex:BICId .

Tests confirm:

  • Correct union construction
  • Correct disjoint axioms
  • Correct prefix usage
  • Deterministic ordering

6. Example Golden Test Case: ISO 4217 Enumeration

Enumerations.tsv

Curie            Name
iso:CurrencyCode CurrencyCode

EnumerationNamedValues.tsv

Enumeration    Curie      Name
CurrencyCode   iso:GBP    GBP
CurrencyCode   iso:EUR    EUR

expected.ttl (Extract)

iso:GBP a iso:CurrencyCode .
iso:EUR a iso:CurrencyCode .

Golden test checks:

  • Enumeration class is declared
  • Individuals generated correctly
  • No unintended disjoint axioms
  • Proper CURIE resolution

7. Example Golden Test Case: Datatype Facet Restrictions

Datatypes.tsv

Curie     Name     BaseDatatype  Pattern       MinLength  MaxLength
iso:LEI20 LEI20    xsd:string    [A-Z0-9]{20}  20         20

expected.ttl (Extract)

iso:LEI20 owl:equivalentClass [
    owl:onDatatype xsd:string ;
    owl:withRestrictions (
       [ xsd:pattern "[A-Z0-9]{20}" ]
       [ xsd:minLength "20"^^xsd:integer ]
       [ xsd:maxLength "20"^^xsd:integer ]
    )
] .

Golden test verifies:

  • Facet rendering
  • Proper XSD integer encoding
  • Deterministic ordering

8. Adding a New Golden Test Case

To create a new golden test:

  1. Create a folder under tests/golden/case-XXX-name/
  2. Add relevant TSV inputs
  3. Run uml2semantics to generate actual.ttl
  4. Canonicalise using the canonicaliser script
  5. Rename canonical output to expected.ttl
  6. Commit the case folder

The test suite will automatically discover and run it.


9. Mermaid Diagram – Golden Test Framework

graph TD
  A[TSV Inputs] --> B[uml2semantics Generator]
  B --> C[Turtle Output]
  C --> D[Canonicaliser]
  D --> E[Expected.ttl]
  E --> F[Diff Engine]
  F --> G[Test Result]
Loading

10. Best Practices

  • Keep TSV inputs alphabetically ordered
  • Use stable CURIE prefixes
  • Add separate golden cases per feature (choice, enum, facets, annotations)
  • Update expected.ttl only for intentional improvements
  • Use CI to run golden tests automatically

11. Navigation

Clone this wiki locally