Skip to content
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Main CI

on: [push]

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
python-version:
- '3.12'
steps:
- uses: actions/checkout@v4
- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install testing dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-test.txt
- name: Lint
# FIXME
continue-on-error: true
run: |
flake8 lib/pyld tests --count --show-source --statistics
env:
LOADER: ${{ matrix.loader }}
test:
runs-on: ubuntu-latest
needs: [lint]
timeout-minutes: 10
strategy:
matrix:
python-version:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- 'pypy3.10'
loader: [requests, aiohttp]
steps:
- uses: actions/checkout@v4
- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Install testing dependencies
run: |
pip install -r requirements-test.txt
- name: Fetch test suites
run: |
git clone --depth 1 https://github.com/w3c/json-ld-api.git _json-ld-api
git clone --depth 1 https://github.com/w3c/json-ld-framing.git _json-ld-framing
git clone --depth 1 https://github.com/json-ld/normalization.git _normalization
- name: Test with Python=${{ matrix.python-version }} Loader=${{ matrix.loader }}
run: |
python tests/runtests.py ./_json-ld-api/tests -l ${{ matrix.loader }}
python tests/runtests.py ./_json-ld-framing/tests -l ${{ matrix.loader }}
python tests/runtests.py ./_normalization/tests -l ${{ matrix.loader }}
env:
LOADER: ${{ matrix.loader }}
#coverage:
# needs: [test]
# FIXME
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ lib/PyLD.egg-info
profiler
tests/test_caching.py
tests/data/test_caching.json

# Local Python version with `pyenv`
.python-version

# PyCharm & other JetBrains IDEs
.idea
11 changes: 11 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[submodule "specifications/json-ld-api"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the specs, but since their sole purpose here is for testing, could this be named test-suites/? That's what the scripts in jsonld.js use.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing!

I can rename those. A few things concern me a bit though:

  • Each repository we're checking out contains not just tests but the whole specification, which might be confusing and violate the principle of least surprise;
  • We will likely add more tests to the tests directory which will not be using the specifications, and the existence of both tests and test-suites will be confusing;
  • At some point, we might want to use the specifications for other purposes than tests, for instance, to aid documentation generation, or something.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the specifications/ folder name, as I do hope/expect we'll get more unit tests added to tests/ at some point, and test-suites/ would certainly be confusing.

Copy link
Collaborator

@mielvds mielvds Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree keeping specifications/, but should we not place it under tests/?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mielvds this will mean there will be a path like tests/specifications/json-ld-api/tests/, lots of nesting. Also... what if we want to reuse specifications for different purposes other than tests?

For instance, they could be extremely useful for LLM-assisted work on the library because specs are authoritatitve.

path = specifications/json-ld-api
url = git@github.com:w3c/json-ld-api.git

[submodule "specifications/json-ld-framing"]
path = specifications/json-ld-framing
url = git@github.com:w3c/json-ld-framing.git

[submodule "specifications/rdf-dataset-canonicalization"]
path = specifications/rdf-dataset-canonicalization
url = git@github.com:w3c-ccg/rdf-dataset-canonicalization.git
42 changes: 0 additions & 42 deletions .travis.yml

This file was deleted.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# pyld ChangeLog

## 3.0.0 - 2023-xx-xx

### Changed
- **BREAKING**: Require supported Python version >= 3.8.

## 2.0.3 - 2020-08-06

### Fixed
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
upgrade-submodules:
git submodule update --remote --init --recursive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you remove all the checked out dirs without leaving git thinking there are unstaged changes? Put another way, how do you undo this command?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to undo the version upgrade of the submodules, you can do:

git reset --hard

If you've modified the submodules locally, after having them upgraded (for debugging purposes perhaps) then you do:

git submodule foreach git reset --hard

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add those to the makefile for convenience?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • During a normal workflow, I guess modification of submodules won't happen often. reset --hard is a destructive operation, not sure if we should create a shortcut for it 🤔


test:
python tests/runtests.py
25 changes: 18 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ yet supported.
Requirements
------------

- Python_ (3.6 or later)
- Python_ (3.8 or later)
- Requests_ (optional)
- aiohttp_ (optional, Python 3.5 or later)

Expand Down Expand Up @@ -190,16 +190,27 @@ Tests
This library includes a sample testing utility which may be used to verify
that changes to the processor maintain the correct output.

To run the sample tests you will need to get the test suite files by cloning
the ``json-ld-api``, ``json-ld-framing``, and ``normalization`` repositories
hosted on GitHub:
To run the sample tests you will need the test suite files provided in the
``json-ld-api``, ``json-ld-framing``, and ``rdf-dataset-canonicalization``
repositories hosted
on GitHub:

- https://github.com/w3c/json-ld-api
- https://github.com/w3c/json-ld-framing
- https://github.com/json-ld/normalization
- https://github.com/w3c-ccg/rdf-dataset-canonicalization

If the suites repositories are available as sibling directories of the PyLD
source directory, then all the tests can be run with the following:
They are included beneath ``specifications`` directory of this repository as
Git submodules. By default, ``git clone`` does
not retrieve submodules; to download them, please issue the following command:

.. code-block:: bash

make upgrade-submodules

Issue the same command to update each submodule to the latest available commit.

If the suites repositories are available then all the tests can be run with
the following:

.. code-block:: bash

Expand Down
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flake8
1 change: 1 addition & 0 deletions specifications/json-ld-api
Submodule json-ld-api added at 229c82
1 change: 1 addition & 0 deletions specifications/json-ld-framing
Submodule json-ld-framing added at f13920
1 change: 1 addition & 0 deletions specifications/rdf-dataset-canonicalization
28 changes: 15 additions & 13 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import unittest
import re
from argparse import ArgumentParser
from pathlib import Path
from typing import List
from unittest import TextTestResult

sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'lib'))
Expand All @@ -32,9 +34,20 @@
LOCAL_BASES = [
'https://w3c.github.io/json-ld-api/tests',
'https://w3c.github.io/json-ld-framing/tests',
'https://github.com/json-ld/normalization/tests'
'https://github.com/w3c-ccg/rdf-dataset-canonicalization/tree/main/tests',
]


def default_test_targets() -> List[Path]:
"""Default test directories from specifications."""
specifications = Path(__file__).parent.parent / 'specifications'
return [
specifications / 'json-ld-api/tests',
specifications / 'json-ld-framing/tests',
specifications / 'rdf-dataset-canonicalization/tests',
]


class TestRunner(unittest.TextTestRunner):
"""
Loads test manifests and runs tests.
Expand Down Expand Up @@ -95,18 +108,7 @@ def main(self):
test_targets = self.options.tests
else:
# default to find known sibling test dirs
test_targets = []
sibling_dirs = [
'../json-ld-api/tests/',
'../json-ld-framing/tests/',
'../normalization/tests/',
]
for dir in sibling_dirs:
if os.path.exists(dir):
print('Test dir found', dir)
test_targets.append(dir)
else:
print('Test dir not found', dir)
test_targets = default_test_targets()

# ensure a manifest or a directory was specified
if len(test_targets) == 0:
Expand Down