Skip to main content

Content modelling built on the Plastron RDF to Python object mapper

Project description

plastron-models

Metadata content models based on RDF

Model Packages

  • annotations: Auxiliary model classes for Web Annotations
  • letter: Legacy content model for the Katherine Anne Porter correspondence collection
  • newspaper: Content model for the Student Newspapers collection, based on the NDNP data format
  • poster: Legacy content model for the Prange Posters and Wall Newspapers collection
  • umd: Standardized digital object content model for current and future collections

Vocabulary Retrieval

The get_vocabulary method in the plastron-models/src/plastron/validation/vocabularies/__init__.py module initializer controls how vocabularies used for validation are retrieved.

Vocabularies used to validate models are retrieved either from the local filesystem, or from a vocabulary server on the network.

The code uses two variables:

  • VOCABULARIES_DIR - The full filepath to the directory containing the local vocabulary files
  • VOCABULARIES - A dictionary mapping a URI to the name of the file containing the vocabulary.

Vocabularies matching URIs in the VOCABULARIES dictionary are first looked up locally, with the local file being used, if found. If not, a network lookup using the URI as the vocabulary location is used.

Vocabulary URIs not in the VOCABULARIES dictionary are always looked up via the network.

Vocabulary Retrieval for Tests

In general, unit tests should be run without making calls to the network, as making a network call makes the tests slower and less reliable.

The retrieval of the vocabularies via the __init__.py module initializer is problematic for the tests, because the module initialization occurs before a test is even run. This makes normal methods of overriding the network calls ineffective. For example, trying to intercept the network calls using the “httpretty” library doesn’t work, because by the time the “@httpretty.activate” decorator is accessed, the module has already been initialized. The same is true when attempting to “monkey patch” the module.

One method that was found to work was to add a conftest.py file into the root directory of the project, with a pytest_configure method. It is necessary to have the conftest.py in the root directory, so that it will always be used when running pytests in any of the Plastron modules (as those tests may use one of the content models with a vocabulary). The pytest_configure method runs as soon as pytest starts, and before any modules are loaded, providing an opportunity to set the “VOCABULARIES_DIR” and “VOCABULARIES” variables to values that are suitable for testing.

Any vocabularies needed for the tests should be added as follows:

  1. Add a file containing the vocabulary (in "turtle" format) to the "plastron-models/tests/data/vocabularies/" directory.

  2. In the conftest.py file in the root directory, add the vocabulary URI and filename to the VOCABULARIES dictionary.

Note that if a vocabulary is not added, a network call will still be attempted, due to the fallback behavior of the get_vocabularies method.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plastron_models-4.5.0.tar.gz (46.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plastron_models-4.5.0-py3-none-any.whl (58.1 kB view details)

Uploaded Python 3

File details

Details for the file plastron_models-4.5.0.tar.gz.

File metadata

  • Download URL: plastron_models-4.5.0.tar.gz
  • Upload date:
  • Size: 46.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for plastron_models-4.5.0.tar.gz
Algorithm Hash digest
SHA256 3a174af823b47aab0d230f78e27c2c5c70d508639fd9104100e21d42a8326357
MD5 acfcaa042f5aae2427f34f478a73cacd
BLAKE2b-256 65dcf8d132d7e3aa35885f9840645494fbe8a2390a8680634d30127e42b4fc6b

See more details on using hashes here.

File details

Details for the file plastron_models-4.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for plastron_models-4.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d3604a9dc679bd31b6296e3ece9d42c7aa54fabe71d897c609c2184674bc6ab
MD5 52f4f5c965e7898a89899e1ad72b56e7
BLAKE2b-256 7e0a558a8f5ff24eac1d27720cc568809eed989cb6af040f5b29c45a9d574c92

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page