Skip to content

Commit

Permalink
update and add tests for exporters
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed May 27, 2024
1 parent 825ddee commit f26c6a6
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 7 deletions.
63 changes: 63 additions & 0 deletions tests/data/expected_python_dc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
## This is a generated file. Do not modify it manually!
from __future__ import annotations
from dataclasses import dataclass, field
from dataclasses_json import config, dataclass_json
from typing import List, Optional
from uuid import uuid4


@dataclass_json
@dataclass
class Test:
name: str
number: Optional[float] = None
test2: List[Test2] = field(default_factory=list)

# JSON-LD fields
id: str = field(
metadata=config(field_name="@id"),
default_factory=lambda: "tst:Test/" + str(uuid4())
)
__type__: list[str] = field(
metadata=config(field_name="@type"),
default_factory = lambda: [
"tst:Test",
],
)
__context__: dict[str, str | dict] = field(
metadata=config(field_name="@context"),
default_factory = lambda: {
"tst": "https://www.github.com/my/repo/",
"schema": "http://schema.org/",
"name": "schema:hello",
"number": "schema:one",
"test2": "schema:something",
}
)

@dataclass_json
@dataclass
class Test2:
names: List[str] = field(default_factory=list)
number: Optional[float] = None

# JSON-LD fields
id: str = field(
metadata=config(field_name="@id"),
default_factory=lambda: "tst:Test2/" + str(uuid4())
)
__type__: list[str] = field(
metadata=config(field_name="@type"),
default_factory = lambda: [
"tst:Test2",
],
)
__context__: dict[str, str | dict] = field(
metadata=config(field_name="@context"),
default_factory = lambda: {
"tst": "https://www.github.com/my/repo/",
"schema": "http://schema.org/",
"names": "schema:hello",
"number": "schema:one",
}
)
74 changes: 74 additions & 0 deletions tests/data/expected_python_sdrdm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# AUTOGENERATED! DO NOT EDIT!

from __future__ import annotations
from typing import Dict, List, Optional
from uuid import uuid4

from lxml.etree import _Element
from pydantic import PrivateAttr, model_validator
from pydantic_xml import attr, element

import sdRDM
from sdRDM.base.listplus import ListPlus
from sdRDM.tools.utils import elem2dict


class Test(
sdRDM.DataModel,
search_mode="unordered",
):
name: str = attr(
tag="name",
json_schema_extra=dict(term = "schema:hello",)
)

number: Optional[float] = attr(
default=None,
tag="number",
json_schema_extra=dict(term = "schema:one",)
)

test2: List[Test2] = element(
default_factory=ListPlus,
tag="SomeTest2",
json_schema_extra=dict(term = "schema:something",)
)

_repo: str = PrivateAttr(default="https://www.github.com/my/repo/")


def add_to_test2(
self,
names: List[str],
number: Optional[float],
**kwargs,
):
params = {

"names": names,
"number": number
}

self.test2.append(
Test2(**params)
)

return self.test2[-1]

class Test2(
sdRDM.DataModel,
search_mode="unordered",
):
names: List[str] = element(
default_factory=ListPlus,
tag="name",
json_schema_extra=dict(term = "schema:hello",)
)

number: Optional[float] = attr(
default=None,
tag="number",
json_schema_extra=dict(term = "schema:one",)
)

_repo: str = PrivateAttr(default="https://www.github.com/my/repo/")
4 changes: 2 additions & 2 deletions tests/data/expected_sdrdm_schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"name": "Test",
"objects": [
{
"name": "Test",
Expand Down Expand Up @@ -89,6 +88,7 @@
"nsmap": {
"tst": "http://example.com/test/"
},
"repo": "https://www.github.com/my/repo"
"repo": "https://www.github.com/my/repo/",
"prefix": "tst"
}
}
48 changes: 48 additions & 0 deletions tests/data/expected_shacl.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix tst: <https://www.github.com/my/repo/> .
@prefix schema: <http://schema.org/> .


tst:TestShape
a sh:NodeShape ;
sh:targetClass md:Test ;

sh:property [
sh:path schema:hello ;
sh:datatype xsd:string ;
sh:minCount 1 ;
sh:maxCount 1 ;

];
sh:property [
sh:path schema:one ;
sh:datatype xsd:double ;
sh:minCount 0 ;
sh:maxCount 1 ;

];
sh:property [
sh:path schema:something ;
sh:node md:Test2Shape ;
sh:minCount 0 ;

].

tst:Test2Shape
a sh:NodeShape ;
sh:targetClass md:Test2 ;

sh:property [
sh:path schema:hello ;
sh:datatype xsd:string ;
sh:minCount 0 ;

];
sh:property [
sh:path schema:one ;
sh:datatype xsd:double ;
sh:minCount 0 ;
sh:maxCount 1 ;

].
13 changes: 13 additions & 0 deletions tests/data/expected_shex.shex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX tst: <https://www.github.com/my/repo/>
PREFIX schema: <http://schema.org/>

tst:Test {
schema:hello xsd:string;
schema:one xsd:double?;
schema:something @tst:Test2*;
}
tst:Test2 {
schema:hello xsd:string*;
schema:one xsd:double?;
}
25 changes: 25 additions & 0 deletions tests/data/expected_xml_schema.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- Roots -->
<xs:element name="Test" type="TestType"/>
<xs:element name="Test2" type="Test2Type"/>

<!-- Test Definition -->
<xs:complexType name="TestType">
<xs:sequence>
<xs:element name="test2" type="Test2Type" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="number" type="xs:float" />
</xs:complexType>

<!-- Test2 Definition -->
<xs:complexType name="Test2Type">
<xs:sequence>
<xs:element name="names" type="xs:string" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="number" type="xs:float" />
</xs:complexType>

</xs:schema>
7 changes: 2 additions & 5 deletions tests/data/model.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
---
id-field: true
repo: "https://www.github.com/my/repo"
repo: "https://www.github.com/my/repo/"
prefix: "tst"
prefixes:
schema: http://schema.org/
nsmap:
tst: http://example.com/test/
---

# Test

## Objects

### Test

- __name__
Expand Down

0 comments on commit f26c6a6

Please sign in to comment.