Skip to content

Commit

Permalink
Move test entities and input and output files to sub-directories (#731)
Browse files Browse the repository at this point in the history
# Description
Moved entities, input and output files to respectively sub-directories
in the Python tests.

Closes #689 
Addresses also issue #609 

While updating the tests to use the new sub-directories, a few other
path-related issues were discovered and fixed:
* two potential segfaults in dlite-storage.i and dlite.rdf.c if an
invalid path is provided were fixed
* raise DLiteParseError instead of DLiteOtherError for invalid json
input
* allow to hide DLiteOtherError by using DLiteUnknownError.


## Type of change
- [x] Bug fix & code cleanup
- [ ] New feature
- [ ] Documentation update
- [ ] Test update

## Checklist for the reviewer
This checklist should be used as a help for the reviewer.

- [ ] Is the change limited to one issue?
- [ ] Does this PR close the issue?
- [ ] Is the code easy to read and understand?
- [ ] Do all new feature have an accompanying new test?
- [ ] Has the documentation been updated as necessary?
  • Loading branch information
jesper-friis committed Jan 24, 2024
2 parents 2996631 + d604870 commit ece8707
Show file tree
Hide file tree
Showing 41 changed files with 227 additions and 270 deletions.
2 changes: 1 addition & 1 deletion bindings/python/dlite-storage.i
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Returns next instance or None if exhausted.") next;
if (dlite_storage_iter_next($self->s, $self->state, uuid) == 0) {
DLiteInstance *inst = dlite_instance_load($self->s, uuid);
// Why isn't the refcount already increased?
dlite_instance_incref(inst);
if (inst) dlite_instance_incref(inst);
return inst;
}
return NULL;
Expand Down
16 changes: 10 additions & 6 deletions bindings/python/scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,30 @@ install(
# Tests
test_success(
dlite-validate-Person
dlite-validate ../tests/Person.json
dlite-validate ../tests/entities/Person.json
)
test_success(
dlite-validate-persons
dlite-validate -p ../tests/Person.json -i a1d8d35f-723c-5ea1-abaf-8fc8f1d0982f
../tests/persons.json
dlite-validate
-p ../tests/entities/Person.json
-i a1d8d35f-723c-5ea1-abaf-8fc8f1d0982f
../tests/input/persons.json
)
test_success(
dlite-validate-persons2
dlite-validate
--storage-path=../tests
--storage-path=../tests/entities
--id=Ada
--show
../tests/persons.json
../tests/input/persons.json
)

# No --id for storage with multiple instances
test_failure(
dlite-validate-persons-fail2
dlite-validate --storage-path ../tests/Person.json --show ../tests/persons.json
dlite-validate
--storage-path ../tests/entities/Person.json
--show ../tests/input/persons.json
)

# The "dimensions" keyword is required
Expand Down
14 changes: 0 additions & 14 deletions bindings/python/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,2 @@
.gdb_history
__pycache__

inst.ttl
inst.yaml
test.json
test.yaml

xxx.json
xxx2.json
yyy.json

myentity.json
persons2.json

db.xml
1 change: 1 addition & 0 deletions bindings/python/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(tests
test_postgresql2_read
test_ref_type
test_pydantic
test_iri
)

foreach(test ${tests})
Expand Down
23 changes: 0 additions & 23 deletions bindings/python/tests/Person.json

This file was deleted.

22 changes: 17 additions & 5 deletions bindings/python/tests/entities/Invalid1.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
{
"name": "Missing version",
"namespace": "http://onto-ns.com/meta",
"meta": "http://onto-ns.com/meta/0.3/EntitySchema",
"dimensions": {}
"properties": {}
"uri": "http://onto-ns.com/meta/0.1/Invalid1",
"description": "An datamodel for an item with float type and invalid shape name.",
"dimensions": {
"nf": "Number of eigen-frequencies."
},
"properties": {
"name": {
"type": "str",
"description": "Name of the item."
},
"f": {
"type": "float64",
"shape": ["nf_MISPELLED"],
"unit": "Hz",
"description": "The magic eigen-frequencies of the item."
}
}
}
18 changes: 13 additions & 5 deletions bindings/python/tests/entities/Invalid2.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"name": "Missing namespace",
"version": "0.0.1",
"meta": "http://onto-ns.com/meta/0.3/EntitySchema",
"dimensions": {}
"properties": {}
"uri": "http://onto-ns.com/meta/0.1/Invalid2",
"description": "A datamodel with ref-types with invalid shape name...",
"dimensions": {
"nrefs": "Number of references to Ref datamodels."
},
"properties": {
"items": {
"type": "ref",
"$ref": "http://onto-ns.com/meta/0.1/Item",
"shape": ["INVALID_nrefs"],
"description": "List of Item datamodels."
}
}
}
20 changes: 17 additions & 3 deletions bindings/python/tests/entities/Invalid3.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
{
"url": "http://onto-ns.com/meta/0.1/Invalid3",
"description": "Missing properties",
"dimensions": {}
"uri": "http://onto-ns.com/meta/0.1/Invalid3",
"description": "Invalid JSON (square bracket for dimensions instead of braces).",
"dimensions": [
"nfrequencies": "Number of eigen-frequencies."
],
"properties": {
"name": {
"type": "str",
"description": "Name of the item."
},
"f": {
"type": "float64",
"shape": ["nf"],
"unit": "Hz",
"description": "The magic eigen-frequencies of the item."
}
}
}
7 changes: 7 additions & 0 deletions bindings/python/tests/entities/Invalid5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Missing version",
"namespace": "http://onto-ns.com/meta",
"meta": "http://onto-ns.com/meta/0.3/EntitySchema",
"dimensions": {}
"properties": {}
}
7 changes: 7 additions & 0 deletions bindings/python/tests/entities/Invalid6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Missing namespace",
"version": "0.0.1",
"meta": "http://onto-ns.com/meta/0.3/EntitySchema",
"dimensions": {}
"properties": {}
}
5 changes: 5 additions & 0 deletions bindings/python/tests/entities/Invalid7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"url": "http://onto-ns.com/meta/0.1/Invalid7",
"description": "Missing properties",
"dimensions": {}
}
File renamed without changes.
File renamed without changes.
31 changes: 10 additions & 21 deletions bindings/python/tests/entities/Person.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
{
"name": "Person",
"version": "0.1",
"namespace": "http://onto-ns.com/meta",
"meta": "http://onto-ns.com/meta/0.3/EntitySchema",
"uri": "http://onto-ns.com/meta/0.1/Person",
"description": "A person.",
"dimensions": [
{
"name": "N",
"description": "Number of skills."
}
],
"properties": [
{
"name": "name",
"dimensions": {
"N": "Number of skills."
},
"properties": {
"name": {
"type": "string",
"description": "Full name."
},
{
"name": "age",
"age": {
"type": "float",
"unit": "years",
"description": "Age of person."
},
{
"name": "skills",
"skills": {
"type": "string",
"dims": [
"N"
],
"shape": ["N"],
"description": "List of skills."
}
]
}
}
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions bindings/python/tests/global_dlite_state_mod2.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from pathlib import Path

import dlite
from dlite import Instance, Dimension, Property, Relation

assert len(dlite.istore_get_uuids()) == 3 + 3

thisdir = os.path.abspath(os.path.dirname(__file__))

url = "json://" + thisdir + "/MyEntity.json"
thisdir = Path(__file__).absolute().parent
entitydir = thisdir / "entities"

url = f"json://{entitydir}/MyEntity.json"

# myentity is already defined via test_global_dlite_state, no new instance is added to istore
myentity = Instance.from_url(url)
Expand Down
19 changes: 0 additions & 19 deletions bindings/python/tests/input/Invalid1.json

This file was deleted.

15 changes: 0 additions & 15 deletions bindings/python/tests/input/Invalid2.json

This file was deleted.

19 changes: 0 additions & 19 deletions bindings/python/tests/input/Invalid3.json

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 0 additions & 26 deletions bindings/python/tests/inst.json

This file was deleted.

2 changes: 2 additions & 0 deletions bindings/python/tests/output/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.json
*.yaml
*.ttl
db.xml
4 changes: 3 additions & 1 deletion bindings/python/tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

thisdir = Path(__file__).resolve().parent
outdir = thisdir / "output"
indir = thisdir / "input"
entitydir = thisdir / "entities"


# Create collection
Expand All @@ -23,7 +25,7 @@
assert rel is None

# Create instances
url = f"json://{thisdir}/MyEntity.json?mode=r"
url = f"json://{entitydir}/MyEntity.json?mode=r"
e = dlite.Instance.from_url(url)
inst1 = dlite.Instance.from_metaid(e.uri, [3, 2])
inst2 = dlite.Instance.from_metaid(e.uri, (3, 4), "myinst")
Expand Down
Loading

0 comments on commit ece8707

Please sign in to comment.