Files
AuDaGe/tests/test_xsy.py
2026-10-14 21:23:21 -05:00

93 lines
2.6 KiB
Python

"""
AuDaGe XSY tests
name: test_xsy.py
by: Josh Lucas
date: 2026-09-14
desc: Unit tests for the AuDaGe XSY module.
"""
import os
import unittest
from importlib import resources
from AuDaGe.formats.controlexpert.xsy import *
try:
from tests import assets, output
except ImportError: # pragma: no cover
import assets # noqa: I001
import output
class TestXSY(unittest.TestCase):
"""This test case tests the XSYBlock, DataBlock, and Definitions classes in
the xsy module.
"""
def setUp(self):
self.in_paths = [
file
for file in resources.files(assets).iterdir()
if os.path.splitext(file)[-1].lower() == ".xsy"
]
def test_DataBlock(self):
for in_path in self.in_paths:
datablock = DataBlock.from_file(in_path)
self.assertIsInstance(datablock, DataBlock)
self.assertIsInstance(datablock, XSYBlock)
def test_Definitions(self):
for in_path in self.in_paths:
definitions = Definitions.from_file(in_path)
self.assertIsInstance(definitions, Definitions)
self.assertIsInstance(definitions, XSYBlock)
class TestXSYReader(unittest.TestCase):
def setUp(self):
self.xsy_reader = XSYReader()
self.in_paths = [
file
for file in resources.files(assets).iterdir()
if os.path.splitext(file)[-1].lower() == ".xsy"
]
self.out_path = resources.files(output)
def test_init(self):
self.assertIsInstance(self.xsy_reader, XSYReader)
def test_read(self):
for path in self.in_paths:
xsy = self.xsy_reader.read(path)
self.assertIsInstance(xsy, XSY)
def test_export(self):
for path in self.in_paths:
file_name = os.path.splitext(os.path.split(path)[-1])[0]
xsy = self.xsy_reader.read(path, expand=False)
xsy.datablock.to_csv(
self.out_path.joinpath(f"{file_name}_datablock.csv"),
index=False,
)
xsy.definitions.to_csv(
self.out_path.joinpath(f"{file_name}_definitions.csv"),
index=False,
)
debug = False
for debug_step in (
XSY.DebugStep if debug else [XSY.DebugStep.COMPLETE]
):
xsy.expand_datablock(debug_step=debug_step).to_csv(
self.out_path.joinpath(
f"{file_name}_debug_{debug_step.name}.csv"
),
index=False,
)
if __name__ == "__main__":
unittest.main(failfast=True)