PyLD 2.0.3__tar.gz → 3.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {PyLD-2.0.3 → pyld-3.0.0}/CHANGELOG.md +48 -0
  2. pyld-3.0.0/LICENSE +26 -0
  3. pyld-3.0.0/MANIFEST.in +1 -0
  4. pyld-3.0.0/PKG-INFO +381 -0
  5. {PyLD-2.0.3 → pyld-3.0.0}/README.rst +105 -12
  6. pyld-3.0.0/README.txt +339 -0
  7. pyld-3.0.0/lib/PyLD.egg-info/PKG-INFO +381 -0
  8. pyld-3.0.0/lib/PyLD.egg-info/SOURCES.txt +32 -0
  9. pyld-3.0.0/lib/PyLD.egg-info/dependency_links.txt +1 -0
  10. pyld-3.0.0/lib/PyLD.egg-info/requires.txt +15 -0
  11. pyld-3.0.0/lib/PyLD.egg-info/top_level.txt +2 -0
  12. pyld-3.0.0/lib/pyld/__about__.py +7 -0
  13. {PyLD-2.0.3 → pyld-3.0.0}/lib/pyld/__init__.py +2 -1
  14. pyld-3.0.0/lib/pyld/canon.py +566 -0
  15. {PyLD-2.0.3 → pyld-3.0.0}/lib/pyld/context_resolver.py +51 -33
  16. {PyLD-2.0.3 → pyld-3.0.0}/lib/pyld/documentloader/aiohttp.py +66 -28
  17. {PyLD-2.0.3 → pyld-3.0.0}/lib/pyld/documentloader/requests.py +17 -14
  18. pyld-3.0.0/lib/pyld/identifier_issuer.py +53 -0
  19. pyld-3.0.0/lib/pyld/iri_resolver.py +319 -0
  20. {PyLD-2.0.3 → pyld-3.0.0}/lib/pyld/jsonld.py +1815 -2038
  21. pyld-3.0.0/lib/pyld/nquads.py +244 -0
  22. {PyLD-2.0.3 → pyld-3.0.0}/lib/pyld/resolved_context.py +2 -0
  23. pyld-3.0.0/pyproject.toml +57 -0
  24. pyld-3.0.0/setup.cfg +4 -0
  25. {PyLD-2.0.3 → pyld-3.0.0}/setup.py +1 -0
  26. pyld-3.0.0/tests/test_document_loader.py +84 -0
  27. pyld-3.0.0/tests/test_iri_resolver.py +508 -0
  28. pyld-3.0.0/tests/test_jsonld.py +571 -0
  29. pyld-3.0.0/tests/test_manifests.py +32 -0
  30. pyld-3.0.0/tests/test_nquads.py +231 -0
  31. PyLD-2.0.3/LICENSE +0 -44
  32. PyLD-2.0.3/PKG-INFO +0 -265
  33. PyLD-2.0.3/README.txt +0 -1
  34. PyLD-2.0.3/lib/pyld/__about__.py +0 -9
  35. {PyLD-2.0.3 → pyld-3.0.0}/lib/c14n/Canonicalize.py +0 -0
  36. {PyLD-2.0.3 → pyld-3.0.0}/lib/c14n/NumberToJson.py +0 -0
  37. {PyLD-2.0.3 → pyld-3.0.0}/lib/c14n/__init__.py +0 -0
  38. {PyLD-2.0.3 → pyld-3.0.0}/lib/pyld/documentloader/__init__.py +0 -0
@@ -1,5 +1,53 @@
1
1
  # pyld ChangeLog
2
2
 
3
+ ## 3.0.0 - 2026-04-02
4
+
5
+ ### Changed
6
+ - **BREAKING**: Require supported Python version >= 3.10.
7
+ - Update aiohttp document loader to work with Python 3.14.
8
+ - Minimize async related changes to library code in this release.
9
+ - In sync environment use `asyncio.run`.
10
+ - In async environment use background thread.
11
+ - The default test manifests or directories now default to the
12
+ `./specifications` directory.
13
+ - Add ability to run test suites using pytest and make pytest the default way
14
+ for running (unit)tests.
15
+ - The functionality to resolve relative IRIs to absolute IRIs has been moved
16
+ from `context_resolver.py` to `iri_resolver.py` so it can be maintained
17
+ and tested separately.
18
+ - Migrate the `prepend_base(base, iri)` function to the `resolve(iri, base)`
19
+ function.
20
+ - Move the existing function `remove_dot_segments(path)` and update the
21
+ implementation.
22
+ - Migrate the `remove_base(base, iri)` function to the `unresolve(iri, base)`
23
+ function and update the implementation to use stdlib `urllib.parse` and
24
+ `urllib.unparse` to replace the custom implementation.
25
+ - Update code to use `resolve(iri, base)` and `unresolve(iri, base)` instead.
26
+ Invalid base IRIs (including `None`) are no longer allowed, hence missing
27
+ base IRIs in the JSON-LD context are now handled outside the function call.
28
+ - Add unittests
29
+ - **BREAKING**: the custom `cause` and `traceback` attributes on `JsonLdError`
30
+ are replaced by Python [exception chaining](https://peps.python.org/pep-3134/)
31
+ and the built-in `__cause__` attribute.
32
+ - **BREAKING**: The `IdentifierIssuer` class was moved to `identifier_issuer.py`.
33
+ It's now available at `pyld.identifier_issuer`.
34
+ - **BREAKING**: The classes `URDNA2015` and `URGNA2012` were moved to `canon.py`.
35
+ They are now available at `pyld.canon`.
36
+ - `jsonld.expand()` now accepts a `on_property_dropped` parameter which is a handler
37
+ called on every ignored JSON property.
38
+ - **BREAKING**: In cases where there is no document base (for instance, when
39
+ using a string as input), 'http://example.org/base/' is used as the base IRI
40
+ when `@base` is absent or explicitely set to `null`.
41
+ - **BREAKING**: Some internal parameters were renamed from camelCase to pythonic:
42
+ - `requestProfile` to `request_profile` in `load_document()`
43
+ - `rdfDirection` to `rdf_direction` in `_list_to_rdf()` and `_object_to_rdf()`
44
+
45
+ ## 2.0.4 - 2024-02-16
46
+
47
+ ### Fixed
48
+ - Use explicit `None` or `False` for context checks. Fixes an issue while
49
+ framing with an empty context.
50
+
3
51
  ## 2.0.3 - 2020-08-06
4
52
 
5
53
  ### Fixed
pyld-3.0.0/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2011-2025 Digital Bazaar, Inc.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification,
4
+ are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this
7
+ list of conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation and/or
11
+ other materials provided with the distribution.
12
+
13
+ 3. Neither the name of the copyright holder nor the names of its contributors
14
+ may be used to endorse or promote products derived from this software without
15
+ specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
pyld-3.0.0/MANIFEST.in ADDED
@@ -0,0 +1 @@
1
+ include README.rst README.txt LICENSE CHANGELOG.md
pyld-3.0.0/PKG-INFO ADDED
@@ -0,0 +1,381 @@
1
+ Metadata-Version: 2.4
2
+ Name: PyLD
3
+ Version: 3.0.0
4
+ Summary: Python implementation of the JSON-LD API
5
+ Home-page: https://github.com/digitalbazaar/pyld
6
+ Author: Digital Bazaar
7
+ Author-email: support@digitalbazaar.com
8
+ License: BSD 3-Clause license
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console
11
+ Classifier: Environment :: Web Environment
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: BSD License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Topic :: Internet
17
+ Classifier: Topic :: Software Development :: Libraries
18
+ Description-Content-Type: text/x-rst
19
+ License-File: LICENSE
20
+ Requires-Dist: cachetools
21
+ Requires-Dist: frozendict
22
+ Requires-Dist: lxml
23
+ Provides-Extra: requests
24
+ Requires-Dist: requests; extra == "requests"
25
+ Provides-Extra: aiohttp
26
+ Requires-Dist: aiohttp; extra == "aiohttp"
27
+ Provides-Extra: cachetools
28
+ Requires-Dist: cachetools; extra == "cachetools"
29
+ Provides-Extra: frozendict
30
+ Requires-Dist: frozendict; extra == "frozendict"
31
+ Dynamic: author
32
+ Dynamic: author-email
33
+ Dynamic: classifier
34
+ Dynamic: description
35
+ Dynamic: description-content-type
36
+ Dynamic: home-page
37
+ Dynamic: license
38
+ Dynamic: license-file
39
+ Dynamic: provides-extra
40
+ Dynamic: requires-dist
41
+ Dynamic: summary
42
+
43
+ PyLD
44
+ ====
45
+
46
+ .. image:: https://travis-ci.org/digitalbazaar/pyld.png?branch=master
47
+ :target: https://travis-ci.org/digitalbazaar/pyld
48
+ :alt: Build Status
49
+
50
+ Introduction
51
+ ------------
52
+
53
+ This library is an implementation of the JSON-LD_ specification in Python_.
54
+
55
+ JSON, as specified in RFC7159_, is a simple language for representing
56
+ objects on the Web. Linked Data is a way of describing content across
57
+ different documents or Web sites. Web resources are described using
58
+ IRIs, and typically are dereferencable entities that may be used to find
59
+ more information, creating a "Web of Knowledge". JSON-LD_ is intended
60
+ to be a simple publishing method for expressing not only Linked Data in
61
+ JSON, but for adding semantics to existing JSON.
62
+
63
+ JSON-LD is designed as a light-weight syntax that can be used to express
64
+ Linked Data. It is primarily intended to be a way to express Linked Data
65
+ in JavaScript and other Web-based programming environments. It is also
66
+ useful when building interoperable Web Services and when storing Linked
67
+ Data in JSON-based document storage engines. It is practical and
68
+ designed to be as simple as possible, utilizing the large number of JSON
69
+ parsers and existing code that is in use today. It is designed to be
70
+ able to express key-value pairs, RDF data, RDFa_ data,
71
+ Microformats_ data, and Microdata_. That is, it supports every
72
+ major Web-based structured data model in use today.
73
+
74
+ The syntax does not require many applications to change their JSON, but
75
+ easily add meaning by adding context in a way that is either in-band or
76
+ out-of-band. The syntax is designed to not disturb already deployed
77
+ systems running on JSON, but provide a smooth migration path from JSON
78
+ to JSON with added semantics. Finally, the format is intended to be fast
79
+ to parse, fast to generate, stream-based and document-based processing
80
+ compatible, and require a very small memory footprint in order to operate.
81
+
82
+ Conformance
83
+ -----------
84
+
85
+ This library aims to conform with the following:
86
+
87
+ - `JSON-LD 1.1 <JSON-LD WG 1.1_>`_,
88
+ W3C Candidate Recommendation,
89
+ 2019-12-12 or `newer <JSON-LD WG latest_>`_
90
+ - `JSON-LD 1.1 Processing Algorithms and API <JSON-LD WG 1.1 API_>`_,
91
+ W3C Candidate Recommendation,
92
+ 2019-12-12 or `newer <JSON-LD WG API latest_>`_
93
+ - `JSON-LD 1.1 Framing <JSON-LD WG 1.1 Framing_>`_,
94
+ W3C Candidate Recommendation,
95
+ 2019-12-12 or `newer <JSON-LD WG Framing latest_>`_
96
+ - Working Group `test suite <WG test suite_>`_
97
+
98
+ The `test runner`_ is often updated to note or skip newer tests that are not
99
+ yet supported.
100
+
101
+ Requirements
102
+ ------------
103
+
104
+ - Python_ (3.10 or later)
105
+ - Requests_ (optional)
106
+ - aiohttp_ (optional, Python 3.5 or later)
107
+
108
+ Installation
109
+ ------------
110
+
111
+ PyLD can be installed with a pip_ `package <https://pypi.org/project/PyLD/>`_
112
+
113
+ .. code-block:: bash
114
+
115
+ pip install PyLD
116
+
117
+ Defining a dependency on pyld will not pull in Requests_ or aiohttp_. If you
118
+ need one of these for a `Document Loader`_ then either depend on the desired
119
+ external library directly or define the requirement as ``PyLD[requests]`` or
120
+ ``PyLD[aiohttp]``.
121
+
122
+ Quick Examples
123
+ --------------
124
+
125
+ .. code-block:: Python
126
+
127
+ from pyld import jsonld
128
+ import json
129
+
130
+ doc = {
131
+ "http://schema.org/name": "Manu Sporny",
132
+ "http://schema.org/url": {"@id": "http://manu.sporny.org/"},
133
+ "http://schema.org/image": {"@id": "http://manu.sporny.org/images/manu.png"}
134
+ }
135
+
136
+ context = {
137
+ "name": "http://schema.org/name",
138
+ "homepage": {"@id": "http://schema.org/url", "@type": "@id"},
139
+ "image": {"@id": "http://schema.org/image", "@type": "@id"}
140
+ }
141
+
142
+ # compact a document according to a particular context
143
+ # see: https://json-ld.org/spec/latest/json-ld/#compacted-document-form
144
+ compacted = jsonld.compact(doc, context)
145
+
146
+ print(json.dumps(compacted, indent=2))
147
+ # Output:
148
+ # {
149
+ # "@context": {...},
150
+ # "image": "http://manu.sporny.org/images/manu.png",
151
+ # "homepage": "http://manu.sporny.org/",
152
+ # "name": "Manu Sporny"
153
+ # }
154
+
155
+ # compact using URLs
156
+ jsonld.compact('http://example.org/doc', 'http://example.org/context')
157
+
158
+ # expand a document, removing its context
159
+ # see: https://json-ld.org/spec/latest/json-ld/#expanded-document-form
160
+ expanded = jsonld.expand(compacted)
161
+
162
+ print(json.dumps(expanded, indent=2))
163
+ # Output:
164
+ # [{
165
+ # "http://schema.org/image": [{"@id": "http://manu.sporny.org/images/manu.png"}],
166
+ # "http://schema.org/name": [{"@value": "Manu Sporny"}],
167
+ # "http://schema.org/url": [{"@id": "http://manu.sporny.org/"}]
168
+ # }]
169
+
170
+ # expand using URLs
171
+ jsonld.expand('http://example.org/doc')
172
+
173
+ # flatten a document
174
+ # see: https://json-ld.org/spec/latest/json-ld/#flattened-document-form
175
+ flattened = jsonld.flatten(doc)
176
+ # all deep-level trees flattened to the top-level
177
+
178
+ # frame a document
179
+ # see: https://json-ld.org/spec/latest/json-ld-framing/#introduction
180
+ framed = jsonld.frame(doc, frame)
181
+ # document transformed into a particular tree structure per the given frame
182
+
183
+ # normalize a document using the RDF Dataset Normalization Algorithm
184
+ # (URDNA2015), see: https://www.w3.org/TR/rdf-canon/
185
+ normalized = jsonld.normalize(
186
+ doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
187
+ # normalized is a string that is a canonical representation of the document
188
+ # that can be used for hashing, comparison, etc.
189
+
190
+ Document Loader
191
+ ---------------
192
+
193
+ The default document loader for PyLD uses Requests_. In a production
194
+ environment you may want to setup a custom loader that, at a minimum, sets a
195
+ timeout value. You can also force requests to use https, set client certs,
196
+ disable verification, or set other Requests_ parameters.
197
+
198
+ .. code-block:: Python
199
+
200
+ jsonld.set_document_loader(jsonld.requests_document_loader(timeout=...))
201
+
202
+ An asynchronous document loader using aiohttp_ is also available. Please note
203
+ that this document loader limits asynchronicity to fetching documents only.
204
+ The processing loops remain synchronous.
205
+
206
+ .. code-block:: Python
207
+
208
+ jsonld.set_document_loader(jsonld.aiohttp_document_loader(timeout=...))
209
+
210
+ When no document loader is specified, the default loader is set to Requests_.
211
+ If Requests_ is not available, the loader is set to aiohttp_. The fallback
212
+ document loader is a dummy document loader that raises an exception on every
213
+ invocation.
214
+
215
+ Handling ignored properties during JSON-LD expansion
216
+ ----------------------------------------------------
217
+
218
+ If a property in a JSON-LD document does not map to an absolute IRI then it is
219
+ ignored. You can customize this behaviour by passing a customizable handler to
220
+ `on_property_dropped` parameter of `jsonld.expand()`.
221
+
222
+ For example, you can introduce a strict mode by raising a ValueError on every
223
+ dropped property:
224
+
225
+ .. code-block:: Python
226
+
227
+ def raise_this(value):
228
+ raise ValueError(value)
229
+
230
+ jsonld.expand(doc, None, on_property_dropped=raise_this)
231
+
232
+ Commercial Support
233
+ ------------------
234
+
235
+ Commercial support for this library is available upon request from
236
+ `Digital Bazaar`_: support@digitalbazaar.com.
237
+
238
+ Source
239
+ ------
240
+
241
+ The source code for the Python implementation of the JSON-LD API
242
+ is available at:
243
+
244
+ https://github.com/digitalbazaar/pyld
245
+
246
+ Tests
247
+ -----
248
+
249
+ This library includes a sample testing utility which may be used to verify
250
+ that changes to the processor maintain the correct output.
251
+
252
+ To run the sample tests you will need to get the test suite files, which
253
+ by default, are stored in the `specifications/` folder.
254
+ The test suites can be obtained by either using git submodules or by cloning
255
+ them manually.
256
+
257
+ Using git submodules
258
+ ####################
259
+
260
+ The test suites are included as git submodules to ensure versions are in sync.
261
+ When cloning the repository, use the ``--recurse-submodules`` flag to
262
+ automatically clone the submodules.
263
+ If you have cloned the repository without the submodules, you can initialize
264
+ them with the following commands:
265
+
266
+ .. code-block:: bash
267
+
268
+ git submodule init
269
+ git submodule update
270
+
271
+ Cloning manually
272
+ ####################
273
+
274
+ You can also avoid using git submodules by manually cloning
275
+ the ``json-ld-api``, ``json-ld-framing``, and ``normalization`` repositories
276
+ hosted on GitHub using the following commands:
277
+
278
+ .. code-block:: bash
279
+
280
+ git clone https://github.com/w3c/json-ld-api ./specifications/json-ld-api
281
+ git clone https://github.com/w3c/json-ld-framing ./specifications/json-ld-framing
282
+ git clone https://github.com/json-ld/normalization ./specifications/normalization
283
+
284
+ Note that you can clone these repositories into any location you wish; however,
285
+ if you do not clone them into the default ``specifications/`` folder, you will
286
+ need to provide the paths to the test runner as arguments when running the
287
+ tests, as explained below
288
+
289
+ Running the sample test suites and unittests using pytest
290
+ #########################################################
291
+
292
+ If the suites repositories are available in the `specifications/` folder of the
293
+ PyLD source directory, then all unittests, including the sample test suites,
294
+ can be run with `pytest`:
295
+
296
+ .. code-block:: bash
297
+
298
+ pytest
299
+
300
+ If you wish to store the test suites in a different location than the default
301
+ ``specifications/`` folder, or you want to test individual manifest ``.jsonld``
302
+ files or directories containing a ``manifest.jsonld``, then you can supply
303
+ these files or directories as arguments:
304
+
305
+ .. code-block:: bash
306
+
307
+ # use: pytest --tests=TEST_PATH [--tests=TEST_PATH...]
308
+ pytest --tests=./specifications/json-ld-api/tests
309
+
310
+ The test runner supports different document loaders by setting
311
+ ``--loader requests`` or ``--loader aiohttp``. The default document loader is
312
+ set to Requests_.
313
+
314
+ .. code-block:: bash
315
+
316
+ pytest --loader=requests --tests=./specifications/json-ld-api/tests
317
+
318
+ An EARL report can be generated using the ``--earl`` option.
319
+
320
+ .. code-block:: bash
321
+
322
+ pytest --earl=./earl-report.json
323
+
324
+ Running the sample test suites using the original test runner
325
+ #############################################################
326
+
327
+ You can also run the JSON-LD test suites using the original test runner script
328
+ provided:
329
+
330
+ .. code-block:: bash
331
+
332
+ python tests/runtests.py
333
+
334
+ If you wish to store the test suites in a different location than the default
335
+ ``specifications/`` folder, or you want to test individual manifest ``.jsonld``
336
+ files or directories containing a ``manifest.jsonld``, then you can supply
337
+ these files or directories as arguments:
338
+
339
+ .. code-block:: bash
340
+
341
+ python tests/runtests.py TEST_PATH [TEST_PATH...]
342
+
343
+ The test runner supports different document loaders by setting ``-l requests``
344
+ or ``-l aiohttp``. The default document loader is set to Requests_.
345
+
346
+ .. code-block:: bash
347
+
348
+ python tests/runtests.py -l requests ./specifications/json-ld-api/tests
349
+
350
+ An EARL report can be generated using the ``-e`` or ``--earl`` option.
351
+
352
+ .. code-block:: bash
353
+
354
+ python tests/runtests.py -e ./earl-report.json
355
+
356
+
357
+ .. _Digital Bazaar: https://digitalbazaar.com/
358
+
359
+ .. _JSON-LD WG 1.1 API: https://www.w3.org/TR/json-ld11-api/
360
+ .. _JSON-LD WG 1.1 Framing: https://www.w3.org/TR/json-ld11-framing/
361
+ .. _JSON-LD WG 1.1: https://www.w3.org/TR/json-ld11/
362
+
363
+ .. _JSON-LD WG API latest: https://w3c.github.io/json-ld-api/
364
+ .. _JSON-LD WG Framing latest: https://w3c.github.io/json-ld-framing/
365
+ .. _JSON-LD WG latest: https://w3c.github.io/json-ld-syntax/
366
+
367
+ .. _JSON-LD Benchmarks: https://json-ld.org/benchmarks/
368
+ .. _JSON-LD WG: https://www.w3.org/2018/json-ld-wg/
369
+ .. _JSON-LD: https://json-ld.org/
370
+ .. _Microdata: http://www.w3.org/TR/microdata/
371
+ .. _Microformats: http://microformats.org/
372
+ .. _Python: https://www.python.org/
373
+ .. _Requests: http://docs.python-requests.org/
374
+ .. _aiohttp: https://aiohttp.readthedocs.io/
375
+ .. _RDFa: http://www.w3.org/TR/rdfa-core/
376
+ .. _RFC7159: http://tools.ietf.org/html/rfc7159
377
+ .. _WG test suite: https://github.com/w3c/json-ld-api/tree/master/tests
378
+ .. _errata: http://www.w3.org/2014/json-ld-errata
379
+ .. _pip: http://www.pip-installer.org/
380
+ .. _test runner: https://github.com/digitalbazaar/pyld/blob/master/tests/runtests.py
381
+ .. _test suite: https://github.com/json-ld/json-ld.org/tree/master/test-suite
@@ -59,7 +59,7 @@ yet supported.
59
59
  Requirements
60
60
  ------------
61
61
 
62
- - Python_ (3.6 or later)
62
+ - Python_ (3.10 or later)
63
63
  - Requests_ (optional)
64
64
  - aiohttp_ (optional, Python 3.5 or later)
65
65
 
@@ -139,7 +139,7 @@ Quick Examples
139
139
  # document transformed into a particular tree structure per the given frame
140
140
 
141
141
  # normalize a document using the RDF Dataset Normalization Algorithm
142
- # (URDNA2015), see: https://json-ld.github.io/normalization/spec/
142
+ # (URDNA2015), see: https://www.w3.org/TR/rdf-canon/
143
143
  normalized = jsonld.normalize(
144
144
  doc, {'algorithm': 'URDNA2015', 'format': 'application/n-quads'})
145
145
  # normalized is a string that is a canonical representation of the document
@@ -170,6 +170,23 @@ If Requests_ is not available, the loader is set to aiohttp_. The fallback
170
170
  document loader is a dummy document loader that raises an exception on every
171
171
  invocation.
172
172
 
173
+ Handling ignored properties during JSON-LD expansion
174
+ ----------------------------------------------------
175
+
176
+ If a property in a JSON-LD document does not map to an absolute IRI then it is
177
+ ignored. You can customize this behaviour by passing a customizable handler to
178
+ `on_property_dropped` parameter of `jsonld.expand()`.
179
+
180
+ For example, you can introduce a strict mode by raising a ValueError on every
181
+ dropped property:
182
+
183
+ .. code-block:: Python
184
+
185
+ def raise_this(value):
186
+ raise ValueError(value)
187
+
188
+ jsonld.expand(doc, None, on_property_dropped=raise_this)
189
+
173
190
  Commercial Support
174
191
  ------------------
175
192
 
@@ -190,24 +207,92 @@ Tests
190
207
  This library includes a sample testing utility which may be used to verify
191
208
  that changes to the processor maintain the correct output.
192
209
 
193
- To run the sample tests you will need to get the test suite files by cloning
210
+ To run the sample tests you will need to get the test suite files, which
211
+ by default, are stored in the `specifications/` folder.
212
+ The test suites can be obtained by either using git submodules or by cloning
213
+ them manually.
214
+
215
+ Using git submodules
216
+ ####################
217
+
218
+ The test suites are included as git submodules to ensure versions are in sync.
219
+ When cloning the repository, use the ``--recurse-submodules`` flag to
220
+ automatically clone the submodules.
221
+ If you have cloned the repository without the submodules, you can initialize
222
+ them with the following commands:
223
+
224
+ .. code-block:: bash
225
+
226
+ git submodule init
227
+ git submodule update
228
+
229
+ Cloning manually
230
+ ####################
231
+
232
+ You can also avoid using git submodules by manually cloning
194
233
  the ``json-ld-api``, ``json-ld-framing``, and ``normalization`` repositories
195
- hosted on GitHub:
234
+ hosted on GitHub using the following commands:
235
+
236
+ .. code-block:: bash
237
+
238
+ git clone https://github.com/w3c/json-ld-api ./specifications/json-ld-api
239
+ git clone https://github.com/w3c/json-ld-framing ./specifications/json-ld-framing
240
+ git clone https://github.com/json-ld/normalization ./specifications/normalization
241
+
242
+ Note that you can clone these repositories into any location you wish; however,
243
+ if you do not clone them into the default ``specifications/`` folder, you will
244
+ need to provide the paths to the test runner as arguments when running the
245
+ tests, as explained below
246
+
247
+ Running the sample test suites and unittests using pytest
248
+ #########################################################
249
+
250
+ If the suites repositories are available in the `specifications/` folder of the
251
+ PyLD source directory, then all unittests, including the sample test suites,
252
+ can be run with `pytest`:
196
253
 
197
- - https://github.com/w3c/json-ld-api
198
- - https://github.com/w3c/json-ld-framing
199
- - https://github.com/json-ld/normalization
254
+ .. code-block:: bash
255
+
256
+ pytest
257
+
258
+ If you wish to store the test suites in a different location than the default
259
+ ``specifications/`` folder, or you want to test individual manifest ``.jsonld``
260
+ files or directories containing a ``manifest.jsonld``, then you can supply
261
+ these files or directories as arguments:
262
+
263
+ .. code-block:: bash
264
+
265
+ # use: pytest --tests=TEST_PATH [--tests=TEST_PATH...]
266
+ pytest --tests=./specifications/json-ld-api/tests
267
+
268
+ The test runner supports different document loaders by setting
269
+ ``--loader requests`` or ``--loader aiohttp``. The default document loader is
270
+ set to Requests_.
271
+
272
+ .. code-block:: bash
273
+
274
+ pytest --loader=requests --tests=./specifications/json-ld-api/tests
275
+
276
+ An EARL report can be generated using the ``--earl`` option.
200
277
 
201
- If the suites repositories are available as sibling directories of the PyLD
202
- source directory, then all the tests can be run with the following:
278
+ .. code-block:: bash
279
+
280
+ pytest --earl=./earl-report.json
281
+
282
+ Running the sample test suites using the original test runner
283
+ #############################################################
284
+
285
+ You can also run the JSON-LD test suites using the original test runner script
286
+ provided:
203
287
 
204
288
  .. code-block:: bash
205
289
 
206
290
  python tests/runtests.py
207
291
 
208
- If you want to test individual manifest ``.jsonld`` files or directories
209
- containing a ``manifest.jsonld``, then you can supply these files or
210
- directories as arguments:
292
+ If you wish to store the test suites in a different location than the default
293
+ ``specifications/`` folder, or you want to test individual manifest ``.jsonld``
294
+ files or directories containing a ``manifest.jsonld``, then you can supply
295
+ these files or directories as arguments:
211
296
 
212
297
  .. code-block:: bash
213
298
 
@@ -216,8 +301,16 @@ directories as arguments:
216
301
  The test runner supports different document loaders by setting ``-l requests``
217
302
  or ``-l aiohttp``. The default document loader is set to Requests_.
218
303
 
304
+ .. code-block:: bash
305
+
306
+ python tests/runtests.py -l requests ./specifications/json-ld-api/tests
307
+
219
308
  An EARL report can be generated using the ``-e`` or ``--earl`` option.
220
309
 
310
+ .. code-block:: bash
311
+
312
+ python tests/runtests.py -e ./earl-report.json
313
+
221
314
 
222
315
  .. _Digital Bazaar: https://digitalbazaar.com/
223
316