forked from rwth-iat/basyx-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tutorials.py
More file actions
71 lines (59 loc) · 2.9 KB
/
Copy pathtest_tutorials.py
File metadata and controls
71 lines (59 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright (c) 2026 the Eclipse BaSyx Authors
#
# This program and the accompanying materials are made available under the terms of the MIT License, available in
# the LICENSE file of this project.
#
# SPDX-License-Identifier: MIT
"""
Tests for the tutorials
Functions to test if a tutorial is executable
"""
import os
import tempfile
import unittest
from contextlib import contextmanager
from basyx.aas import model
from .._helper.test_helpers import COUCHDB_OKAY, TEST_CONFIG, COUCHDB_ERROR
class TutorialTest(unittest.TestCase):
def test_tutorial_create_simple_aas(self):
from basyx.aas.examples import tutorial_create_simple_aas
self.assertEqual(tutorial_create_simple_aas.submodel.get_referable('ExampleProperty').value, 'exampleValue')
store = model.DictIdentifiableStore({tutorial_create_simple_aas.submodel})
next(iter(tutorial_create_simple_aas.aas.submodel)).resolve(store)
def test_tutorial_storage(self):
from basyx.aas.examples import tutorial_storage
# The tutorial already includes assert statements for the relevant points. So no further checks are required.
@unittest.skipUnless(COUCHDB_OKAY, "No CouchDB is reachable at {}/{}: {}".format(TEST_CONFIG['couchdb']['url'],
TEST_CONFIG['couchdb']['database'],
COUCHDB_ERROR))
def test_tutorial_backend_couchdb(self):
from basyx.aas.examples import tutorial_backend_couchdb
def test_tutorial_serialization_deserialization_json(self):
with temporary_workingdirectory():
from basyx.aas.examples import tutorial_serialization_deserialization
pass
# The tutorial already includes assert statements for the relevant points. So no further checks are required.
def test_tutorial_aasx(self):
with temporary_workingdirectory():
from basyx.aas.examples import tutorial_aasx
pass
# The tutorial already includes assert statements for the relevant points. So no further checks are required.
def test_tutorial_navigate_aas(self):
from basyx.aas.examples import tutorial_navigate_aas
# The tutorial already includes assert statements for the relevant points. So no further checks are required
@contextmanager
def temporary_workingdirectory():
"""
A helper contextmanager to temporarily change the current working directory of the Python process to a temporary
directory.
The temp directory is deleted with all its contents when leaving the with-context. This can be used to test Python
scripts, which write files to the current working directory.
"""
cwd = os.getcwd()
tempdir = tempfile.TemporaryDirectory()
os.chdir(tempdir.name)
try:
yield None
finally:
os.chdir(cwd)
tempdir.cleanup()