Skip to content

Commit

Permalink
Fix Python expect data
Browse files Browse the repository at this point in the history
Fixes the expected output data for python and adds a script to
automatically regenerate the expected data to make it easier in the
future
  • Loading branch information
JPEWdev committed Jan 29, 2024
1 parent e428418 commit f163915
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
File renamed without changes.
42 changes: 42 additions & 0 deletions tests/expect/make_expect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#! /usr/bin/env python3
#
# Copyright (c) 2024 Joshua Watt
#
# SPDX-License-Identifier: MIT

import sys
import subprocess

from pathlib import Path

THIS_DIR = Path(__file__).parent
DATA_DIR = THIS_DIR.parent / "data"


def make_dest(src, lang, ext):
return THIS_DIR / lang / (src.stem + ext)


def main():
for src in DATA_DIR.iterdir():
if not src.is_file():
continue

if not src.name.endswith(".jsonld"):
continue

for lang, ext in (("python", ".py"), ("raw", ".txt")):
subprocess.run(
[
"shacl2code",
"generate",
f"--input={src}",
lang,
f"--output={make_dest(src, lang, ext)}",
],
check=True,
)


if __name__ == "__main__":
sys.exit(main())
6 changes: 3 additions & 3 deletions tests/expect/python/spdx3.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,20 +488,20 @@ def serializer(self):
if prop.elide(value):
if min_count:
raise ValueError(
f"Property '{pyname}' in {self.__class__.__name__} is required (currently {value!r})"
f"Property '{pyname}' in {self.__class__.__name__} ({id(self)}) is required (currently {value!r})"
)
continue

if min_count is not None:
if not prop.check_min_count(value, min_count):
raise ValueError(
f"Property '{pyname}' in {self.__class__.__name__} requires a minimum of {min_count} elements"
f"Property '{pyname}' in {self.__class__.__name__} ({id(self)}) requires a minimum of {min_count} elements"
)

if max_count is not None:
if not prop.check_max_count(value, max_count):
raise ValueError(
f"Property '{pyname}' in {self.__class__.__name__} requires a maximum of {max_count} elements"
f"Property '{pyname}' in {self.__class__.__name__} ({id(self)}) requires a maximum of {max_count} elements"
)

d[json_name] = prop.serializer(value)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
THIS_FILE = Path(__file__)
THIS_DIR = THIS_FILE.parent

SPDX3_MODEL = THIS_DIR / "data" / "spdx3-model.jsonld"
SPDX3_MODEL = THIS_DIR / "data" / "spdx3.jsonld"
SPDX3_EXPECT = THIS_DIR / "expect" / "python" / "spdx3.py"


Expand Down
2 changes: 1 addition & 1 deletion tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
THIS_FILE = Path(__file__)
THIS_DIR = THIS_FILE.parent

SPDX3_MODEL = THIS_DIR / "data" / "spdx3-model.jsonld"
SPDX3_MODEL = THIS_DIR / "data" / "spdx3.jsonld"
SPDX3_EXPECT = THIS_DIR / "expect" / "raw" / "spdx3.txt"


Expand Down

0 comments on commit f163915

Please sign in to comment.