niso-standards / cpld

Content Profile / Linked Document Standard
MIT License
4 stars 0 forks source link

Content Profile / Linked Document Standard

This repository contains examples and a test suite for implementations of the Content Profile and Linked Document standard

CP/LD Viewer

The viewer directory of this repository contains the source code of the CP/LD Viewer extension to Visual Studio Code.

Have a look at the readme for installation and usage instructions.

Test Suite

How to run

First, you'll have to use poetry to install required packages:

poetry install

Make sure you have the latest version of html tidy installed that supports the html5 doctype.

Then you can run pytest through poetry:

poetry run pytest (use -v or -vv to get more verbose output)

Defining Tests

The tests are captured in the manifest.json using the following structure:

attribute description
id A readable identifier of a test, starting with an index, e.g. 1-html-docid
type One of RetrievalTest, ComparisonTest or NegativeTest (described below)
description A description of what the test tests
input_file The filename for the data that is to be used as input for the test
property An optional property whose value is to be retrieved (RetrievalTest only)
html_id ID of the HTML element which is to be compared (ComparisonTest only)
output_file The file containing the expected output of the retrieval (RetrievalTest only)
output The expected output of the retrieval (RetrievalTest only)
html_output_file The file containing the expected HTML output of a ComparisonTest
html_output Expected HTML output of a ComparisonTest
jsonld_output_file The file containing the expected JSON-LD output of a ComparisonTest
jsonld_output Expected JSON-LD output of a ComparisonTest
nquads_output_file The file containing the expected (sorted) NQuads output of a ComparisonTest
nquads_output Expected (sorted) NQuads output of a ComparisonTest
raises The name of the expected exception raised in the NegativeTest
subject The subject URI of the triple to be tested (TriplesTest only)
predicate The predicate URI of the triple to be tested (TriplesTest only)
objects Expected objects of the triple (TriplesTest only)

For example, the following instructs a RetrievalTest to extract the value for the docid property from a CPLD Document instantiated from the 1-html-docid-input.html file, and compare this value with the contents of the 1-html-docid-output.txt file:

{
    "id": "1-html-docid",
    "type": "RetrievalTest",
    "description": "Extract document ID from HTML file",
    "input_file": "1-html-docid-input.html",
    "property": "docid",
    "output_file": "1-html-docid-output.txt"
}

See tests.md for generated documentation for this file.

The test_cpld_cases.py file is a pytest implementation of the test suite that uses the manifest.json file to parametrize standard test types using the CP/LD library implemented in the cpld package.

NB it is the intention to separate the tests from the Python implementation in the future.

Types of Tests

Test Documentation

The tests.md file is periodically generated from the manifest.json file to give a more readable overview of the test suite.