Skip to content

Commit c976ab6

Browse files
committed
Merge remote-tracking branch 'origin/v8/develop' into publish_tests
2 parents 25f93f3 + 049454a commit c976ab6

File tree

8 files changed

+2426
-1400
lines changed

8 files changed

+2426
-1400
lines changed

.github/workflows/checks.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Python Tests
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v3
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.11'
20+
21+
- name: Install Poetry
22+
run: |
23+
curl -sSL https://install.python-poetry.org | python3 -
24+
echo "$HOME/.local/bin" >> $GITHUB_PATH
25+
26+
- name: Install dependencies
27+
run: |
28+
poetry install
29+
30+
- name: Run tests
31+
run: |
32+
poetry run make run-test

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,4 @@ dmypy.json
130130

131131
# Pyre type checker
132132
.pyre/
133-
.repor
134133
.report

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ ruff:
1717
ruff check --fix
1818
ruff format
1919

20+
run-test:
21+
pytest
22+
2023
help:
2124
@echo "Available commands:"
2225
@echo " install - Install dependencies and set up pre-commit hooks"
2326
@echo " ruff - Format code and fix linting issues using ruff"
27+
@echo " run-test - Run tests"
2428
@echo " demo - Run /examples/demo.py file"
2529
@echo " async-demo - Run /examples/async_demo.py file"
2630
@echo " paranet-demo - Run /examples/paranets_demo.py file"
@@ -212,4 +216,4 @@ test-base-node29-mainnet:
212216
NODE_TO_TEST="Node 29" PYTHONUNBUFFERED=1 PYTHONPATH=. poetry run python -u -m pytest -o log_cli=true -o log_cli_level=INFO -s --json-report --json-report-file=.report/mainnet_base.json --html=.report/mainnet_base.html --self-contained-html tests/mainnet/Base_Mainnet.py
213217

214218
test-base-node30-mainnet:
215-
NODE_TO_TEST="Node 30" PYTHONUNBUFFERED=1 PYTHONPATH=. poetry run python -u -m pytest -o log_cli=true -o log_cli_level=INFO -s --json-report --json-report-file=.report/mainnet_base.json --html=.report/mainnet_base.html --self-contained-html tests/mainnet/Base_Mainnet.py
219+
NODE_TO_TEST="Node 30" PYTHONUNBUFFERED=1 PYTHONPATH=. poetry run python -u -m pytest -o log_cli=true -o log_cli_level=INFO -s --json-report --json-report-file=.report/mainnet_base.json --html=.report/mainnet_base.html --self-contained-html tests/mainnet/Base_Mainnet.py

dkg/utils/knowledge_collection_tools.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from dkg.types import JSONLD, NQuads
66
from pyld import jsonld
77
from dkg.constants import DEFAULT_RDF_FORMAT, DEFAULT_CANON_ALGORITHM, ESCAPE_MAP
8-
from rdflib import Graph, BNode, URIRef, Literal as RDFLiteral
8+
from rdflib import Graph, BNode, URIRef, Dataset
99
from rdflib.exceptions import ParserError as RDFParserError
1010
from uuid import uuid4
1111
from web3 import Web3
@@ -182,16 +182,13 @@ def replace_blank_node(term):
182182
def group_nquads_by_subject(nquads_list: list[str], sort: bool = False):
183183
grouped = {}
184184

185-
# Process each quad in original order
186-
for nquad in nquads_list:
187-
if not nquad.strip(): # Skip empty lines
188-
continue
185+
all_nquads = "\n".join(nquad for nquad in nquads_list if nquad.strip())
189186

190-
# Parse single quad
191-
g = Graph()
192-
g.parse(data=nquad, format="nquads")
193-
quad = next(iter(g))
194-
subject, predicate, obj = quad
187+
d = Dataset()
188+
d.parse(data=all_nquads, format="nquads")
189+
190+
for quad in d:
191+
subject, predicate, obj, graph = quad
195192

196193
# Get subject key
197194
subject_key = (
@@ -204,11 +201,8 @@ def group_nquads_by_subject(nquads_list: list[str], sort: bool = False):
204201
if subject_key not in grouped:
205202
grouped[subject_key] = []
206203

207-
# Format object
208-
object_value = f'"{obj}"' if isinstance(obj, RDFLiteral) else f"<{obj}>"
209-
210204
# Add quad to group
211-
quad_string = f"{subject_key} <{predicate}> {object_value} ."
205+
quad_string = f"{subject.n3()} {predicate.n3()} {obj.n3()} ."
212206
grouped[subject_key].append(quad_string)
213207

214208
# Return grouped quads (sorted if requested)

poetry.lock

Lines changed: 1847 additions & 1382 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[tool.poetry]
22
name = "dkg"
3-
version = "8.0.13"
3+
version = "8.0.14"
44
description = "Python library for interacting with the OriginTrail Decentralized Knowledge Graph"
55
authors = ["Uladzislau Hubar <hubar.uladzislau@gmail.com>, Zvonimir Sculac <zvonimir.sculac@origin-trail.com>"]
66
license = "Apache-2.0"
77
readme = "README.md"
88

9+
910
[tool.poetry.dependencies]
1011
python = "^3.10"
1112
pyyaml = "^6.0.2"
@@ -23,11 +24,28 @@ python-dotenv = "^1.0.1"
2324
[tool.poetry.group.dev.dependencies]
2425
ruff = "^0.8.4"
2526
pre-commit = "^4.0.1"
26-
pytest = "^7.4.0"
27+
pytest = "^8.0"
28+
pytest-cov = "^4.0"
29+
2730

2831
[tools.setuptools]
2932
packages = ["dkg"]
3033

34+
3135
[build-system]
3236
requires = ["poetry-core"]
3337
build-backend = "poetry.core.masonry.api"
38+
39+
40+
[tool.pytest.ini_options]
41+
minversion = "8.0"
42+
addopts = "-ra"
43+
testpaths = [
44+
"test"
45+
]
46+
47+
48+
python_files = [
49+
"test_*.py",
50+
"*_test.py"
51+
]
File renamed without changes.

0 commit comments

Comments
 (0)