Skip to content

Commit

Permalink
Move generation of AASX files to __init__.py
Browse files Browse the repository at this point in the history
As other tests also need AASX files, we cannot generate  AASX files in ComplianceToolAASXTest, because other tests can be run before or without tests from ComplianceToolAASXTest.
  • Loading branch information
zrgt committed Oct 19, 2023
1 parent 6dcd7b1 commit 5ef70e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
28 changes: 28 additions & 0 deletions test/compliance_tool/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import zipfile

AASX_FILES = ("test_demo_full_example_json_aasx",
"test_demo_full_example_xml_aasx",
"test_demo_full_example_xml_wrong_attribute_aasx",
"test_empty_aasx")


def _zip_directory(directory_path, zip_file_path):
"""Zip a directory recursively."""
with zipfile.ZipFile(zip_file_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, _, files in os.walk(directory_path):
for file in files:
file_path = os.path.join(root, file)
arcname = os.path.relpath(file_path, directory_path)
zipf.write(file_path, arcname=arcname)


def generate_aasx_files():
"""Zip dirs and create test AASX files."""
script_dir = os.path.dirname(__file__)
for i in AASX_FILES:
_zip_directory(os.path.join(script_dir, "files", i),
os.path.join(script_dir, "files", i.rstrip("_aasx") + ".aasx"))


generate_aasx_files()
24 changes: 0 additions & 24 deletions test/compliance_tool/test_compliance_check_aasx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,12 @@
# SPDX-License-Identifier: MIT
import os
import unittest
import zipfile

from basyx.aas.compliance_tool import compliance_check_aasx as compliance_tool
from basyx.aas.compliance_tool.state_manager import ComplianceToolStateManager, Status


class ComplianceToolAASXTest(unittest.TestCase):
AASX_FILES = ("test_demo_full_example_json_aasx",
"test_demo_full_example_xml_aasx",
"test_demo_full_example_xml_wrong_attribute_aasx",
"test_empty_aasx")

@classmethod
def setUpClass(cls):
"""Zip dirs and create test AASX files."""
script_dir = os.path.dirname(__file__)
for i in cls.AASX_FILES:
cls._zip_directory(os.path.join(script_dir, "files", i),
os.path.join(script_dir, "files", i.rstrip("_aasx") + ".aasx"))

@classmethod
def _zip_directory(cls, directory_path, zip_file_path):
"""Zip a directory recursively."""
with zipfile.ZipFile(zip_file_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, _, files in os.walk(directory_path):
for file in files:
file_path = os.path.join(root, file)
arcname = os.path.relpath(file_path, directory_path)
zipf.write(file_path, arcname=arcname)

def test_check_deserialization(self) -> None:
manager = ComplianceToolStateManager()
script_dir = os.path.dirname(__file__)
Expand Down

0 comments on commit 5ef70e0

Please sign in to comment.