Rewrite XSY module again.
This commit is contained in:
@@ -10,32 +10,76 @@ desc: Unit tests for the AuDaGe XSY module.
|
||||
|
||||
import os
|
||||
import unittest
|
||||
from importlib import resources
|
||||
|
||||
# from timeit import default_timer as timer
|
||||
from AuDaGe.formats.controlexpert.xsy import XSY
|
||||
import output
|
||||
|
||||
IN_PATH = "tests/assets"
|
||||
OUT_PATH = "tests/output"
|
||||
import assets
|
||||
from AuDaGe.formats.controlexpert.xsy import *
|
||||
|
||||
ASSETS_PATH = "assets"
|
||||
OUTPUT_PATH = "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):
|
||||
assert isinstance(XSY(os.path.join(IN_PATH, "hsps.xsy")), XSY)
|
||||
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):
|
||||
xsy = XSY()
|
||||
xsy.read(os.path.join(IN_PATH, "hsps.xsy"), expand=False)
|
||||
xsy.datablock.dataframe.to_csv(
|
||||
os.path.join(OUT_PATH, "datablock.csv"), index=False
|
||||
)
|
||||
xsy.definitions.dataframe.to_csv(
|
||||
os.path.join(OUT_PATH, "defs.csv"), index=False
|
||||
)
|
||||
# xsy.expand_datablock(datablock).to_csv(
|
||||
# os.path.join(OUT_PATH, "expanded.csv"),
|
||||
# index=False
|
||||
# )
|
||||
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
|
||||
)
|
||||
xsy.datablock.update(xsy.expand_datablock())
|
||||
xsy.datablock.to_csv(
|
||||
self.out_path.joinpath(f"{file_name}_expanded.csv"), index=False
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
__package__ = "test_xsy"
|
||||
unittest.main(failfast=True)
|
||||
|
||||
Reference in New Issue
Block a user