Skip to content

Commit

Permalink
Merge remote-tracking branch 'eclipse-basyx/main' into refactor/http_api
Browse files Browse the repository at this point in the history
# Conflicts:
#	basyx/aas/adapter/http.py
  • Loading branch information
zrgt committed Sep 3, 2024
2 parents 236f8d7 + f5e1cf7 commit 17bf7d8
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/adapter/xml/test_xml_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from basyx.aas import model
from basyx.aas.adapter.xml import StrictAASFromXmlDecoder, XMLConstructables, read_aas_xml_file, \
read_aas_xml_file_into, read_aas_xml_element
from basyx.aas.adapter.xml.xml_deserialization import _tag_replace_namespace
from basyx.aas.adapter._generic import XML_NS_MAP
from lxml import etree
from typing import Iterable, Type, Union
Expand Down Expand Up @@ -449,3 +450,29 @@ def construct_submodel(cls, element: etree._Element, object_class=EnhancedSubmod
self.assertIsInstance(submodel, EnhancedSubmodel)
assert isinstance(submodel, EnhancedSubmodel)
self.assertEqual(submodel.enhanced_attribute, "fancy!")


class TestTagReplaceNamespace(unittest.TestCase):
def test_known_namespace(self):
tag = '{https://admin-shell.io/aas/3/0}tag'
expected = 'aas:tag'
self.assertEqual(_tag_replace_namespace(tag, XML_NS_MAP), expected)

def test_empty_prefix(self):
# Empty prefix should not be replaced as otherwise it would apply everywhere
tag = '{https://admin-shell.io/aas/3/0}tag'
nsmap = {"": "https://admin-shell.io/aas/3/0"}
expected = '{https://admin-shell.io/aas/3/0}tag'
self.assertEqual(_tag_replace_namespace(tag, nsmap), expected)

def test_empty_namespace(self):
# Empty namespaces should also have no effect
tag = '{https://admin-shell.io/aas/3/0}tag'
nsmap = {"aas": ""}
expected = '{https://admin-shell.io/aas/3/0}tag'
self.assertEqual(_tag_replace_namespace(tag, nsmap), expected)

def test_unknown_namespace(self):
tag = '{http://unknownnamespace.com}unknown'
expected = '{http://unknownnamespace.com}unknown' # Unknown namespace should remain unchanged
self.assertEqual(_tag_replace_namespace(tag, XML_NS_MAP), expected)
55 changes: 55 additions & 0 deletions test/examples/test__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2024 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
import unittest

from basyx.aas import model
from basyx.aas.examples.data import create_example, create_example_aas_binding


class TestExampleFunctions(unittest.TestCase):

def test_create_example(self):
obj_store = create_example()

# Check that the object store is not empty
self.assertGreater(len(obj_store), 0)

# Check that the object store contains expected elements
expected_ids = [
'https://acplt.org/Test_AssetAdministrationShell',
'https://acplt.org/Test_Submodel_Template',
'https://acplt.org/Test_ConceptDescription_Mandatory'
]
for id in expected_ids:
self.assertIsNotNone(obj_store.get_identifiable(id))

def test_create_example_aas_binding(self):
obj_store = create_example_aas_binding()

# Check that the object store is not empty
self.assertGreater(len(obj_store), 0)

# Check that the object store contains expected elements
aas_id = 'https://acplt.org/Test_AssetAdministrationShell'
sm_id = 'https://acplt.org/Test_Submodel_Template'
cd_id = 'https://acplt.org/Test_ConceptDescription_Mandatory'

aas = obj_store.get_identifiable(aas_id)
sm = obj_store.get_identifiable(sm_id)
cd = obj_store.get_identifiable(cd_id)

self.assertIsNotNone(aas)
self.assertIsNotNone(sm)
self.assertIsNotNone(cd)

# Check types
self.assertIsInstance(aas, model.aas.AssetAdministrationShell)
self.assertIsInstance(sm, model.submodel.Submodel)
self.assertIsInstance(cd, model.concept.ConceptDescription)

# Check that the submodel is referred by the AAS
self.assertIn(model.ModelReference.from_referable(sm), aas.submodel)
26 changes: 26 additions & 0 deletions test/model/test_concept.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2023 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
import unittest

from basyx.aas.examples.data import example_aas
from basyx.aas import model


class ConceptDescriptionTest(unittest.TestCase):
def test_concept_description(self):
concept_description = example_aas.create_example_concept_description()

concept_description._set_category(category=None)
concept_description_category = concept_description.__dict__.get("_category")
self.assertEqual(concept_description_category, "PROPERTY")

concept_description._set_category(category="VALUE")
concept_description_category = concept_description.__dict__.get("_category")
self.assertEqual(concept_description_category, "VALUE")

with self.assertRaises(model.base.AASConstraintViolation):
concept_description._set_category(category="FORBIDDEN_CONCEPT_DESCRIPTION")

0 comments on commit 17bf7d8

Please sign in to comment.