Skip to content

Commit

Permalink
update tests to check new patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed May 30, 2024
1 parent 950e3ec commit 04eec14
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 42 deletions.
53 changes: 29 additions & 24 deletions tests/data/expected_json_schema.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,52 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"title": "Test",
"type": "object",
"properties": {
"name": {
"title": "Name",
"type": "string",
"term": "schema:hello"
"title": "name",
"term": "schema:hello",
"type": "string"
},
"number": {
"title": "Number",
"type": "number",
"term": "schema:one"
"title": "number",
"term": "schema:one",
"type": "number"
},
"test2": {
"title": "Test2",
"term": "schema:something",
"type": "array",
"items": {
"$ref": "#/definitions/Test2"
},
"term": "schema:something"
}
},
"ontology": {
"title": "ontology",
"type": "string",
"enum": [
"https://www.evidenceontology.org/term/",
"https://amigo.geneontology.org/amigo/term/",
"http://semanticscience.org/resource/"
]
}
},
"definitions": {
"Test2": {
"title": "Test2",
"type": "object",
"properties": {
"title": "Test2",
"type": "object",
"properties": {
"names": {
"title": "Names",
"type": "array",
"items": {
"type": "string"
},
"term": "schema:hello"
},
"number": {
"title": "Number",
"type": "number",
"term": "schema:one"
"names": {
"title": "names",
"term": "schema:hello",
"type": "array",
"items": {
"type": "string"
}
},
"number": {
"title": "number",
"term": "schema:one",
"type": "number"
}
}
}
Expand Down
32 changes: 31 additions & 1 deletion tests/data/expected_python_dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dataclasses import dataclass, field
from dataclasses_json import config, dataclass_json
from typing import List, Optional
from enum import Enum
from uuid import uuid4


Expand All @@ -12,6 +13,7 @@ class Test:
name: str
number: Optional[float] = None
test2: List[Test2] = field(default_factory=list)
ontology: Optional[Ontology] = None

# JSON-LD fields
id: str = field(
Expand All @@ -34,7 +36,28 @@ class Test:
"test2": "schema:something",
}
)



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]


@dataclass_json
@dataclass
class Test2:
Expand All @@ -60,4 +83,11 @@ class Test2:
"names": "schema:hello",
"number": "schema:one",
}
)
)



class Ontology(Enum):
ECO = "https://www.evidenceontology.org/term/"
GO = "https://amigo.geneontology.org/amigo/term/"
SIO = "http://semanticscience.org/resource/"
15 changes: 14 additions & 1 deletion tests/data/expected_python_sdrdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class Test(
json_schema_extra=dict(term = "schema:something",)
)

ontology: Optional[Ontology] = element(
default=None,
tag="ontology",
json_schema_extra=dict()
)

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


Expand Down Expand Up @@ -71,4 +77,11 @@ class Test2(
json_schema_extra=dict(term = "schema:one",)
)

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



class Ontology(Enum):
ECO = "https://www.evidenceontology.org/term/"
GO = "https://amigo.geneontology.org/amigo/term/"
SIO = "http://semanticscience.org/resource/"
29 changes: 25 additions & 4 deletions tests/data/expected_sdrdm_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,22 @@
"is_attr": false,
"name": "SomeTest2"
}
},
{
"name": "ontology",
"multiple": false,
"dtypes": ["Ontology"],
"docstring": "",
"options": [],
"term": null,
"required": false,
"xml": {
"is_attr": false,
"name": "ontology"
}
}
],
"docstring": "",
"object_type": "Object"
"docstring": ""
},
{
"name": "Test2",
Expand Down Expand Up @@ -76,8 +88,17 @@
}
}
],
"docstring": "",
"object_type": "Object"
"docstring": ""
}
],
"enums": [
{
"name": "Ontology",
"mappings": {
"ECO": "https://www.evidenceontology.org/term/",
"GO": "https://amigo.geneontology.org/amigo/term/",
"SIO": "http://semanticscience.org/resource/"
}
}
],
"config": {
Expand Down
2 changes: 1 addition & 1 deletion tests/data/expected_shacl.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tst:TestShape
sh:node md:Test2Shape ;
sh:minCount 0 ;

].
];

tst:Test2Shape
a sh:NodeShape ;
Expand Down
30 changes: 25 additions & 5 deletions tests/data/expected_shex.shex
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,31 @@ 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*;
schema:hello xsd:string {
shex:annotation [
shex:label "name"
]
};
schema:one xsd:double? {
shex:annotation [
shex:label "number"
]
};
schema:something @tst:Test2* {
shex:annotation [
shex:label "test2"
]
};
}
tst:Test2 {
schema:hello xsd:string*;
schema:one xsd:double?;
schema:hello xsd:string* {
shex:annotation [
shex:label "names"
]
};
schema:one xsd:double? {
shex:annotation [
shex:label "number"
]
};
}
20 changes: 15 additions & 5 deletions tests/data/expected_xml_schema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,28 @@
<!-- Test Definition -->
<xs:complexType name="TestType">
<xs:sequence>
<xs:element name="test2" type="Test2Type" maxOccurs="unbounded" />
<xs:element name="test2" type="Test2Type" maxOccurs="unbounded"/>
<xs:element name="ontology" type="OntologyType" />
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="number" type="xs:float" />
<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:element name="names" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="number" type="xs:float" />
<xs:attribute name="number" type="xs:float" />
</xs:complexType>

<!-- Enum Ontology Definition -->
<xs:simpleType name="OntologyType">
<xs:restriction base="xs:string">
<xs:enumeration value="https://www.evidenceontology.org/term/"/>
<xs:enumeration value="https://amigo.geneontology.org/amigo/term/"/>
<xs:enumeration value="http://semanticscience.org/resource/"/>
</xs:restriction>
</xs:simpleType>

</xs:schema>
15 changes: 15 additions & 0 deletions tests/data/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ nsmap:
- Type: Test2[]
- Term: schema:something
- XML: SomeTest2
- ontology
- Type: Ontology

### Test2

Expand All @@ -33,3 +35,16 @@ nsmap:
- Type: float
- Term: schema:one
- XML: @number


## Enumerations

### Ontology

Ontology endpoints for different types of sequences.

```
GO = "https://amigo.geneontology.org/amigo/term/"
SIO = "http://semanticscience.org/resource/"
ECO = "https://www.evidenceontology.org/term/"
```
3 changes: 2 additions & 1 deletion tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mod tests {
.find(|o| o.name == "Test2".to_string())
.unwrap();

assert_eq!(test1.attributes.len(), 3);
assert_eq!(test1.attributes.len(), 4);
assert_eq!(test2.attributes.len(), 2);

// Check if the attributes are correct
Expand All @@ -46,6 +46,7 @@ mod tests {
"name".to_string(),
"number".to_string(),
"test2".to_string(),
"ontology".to_string(),
];

assert_eq!(test1_attr_names, expected);
Expand Down

0 comments on commit 04eec14

Please sign in to comment.