101 lines
3.3 KiB
Python
101 lines
3.3 KiB
Python
"""
|
|
AuDaGe Converter tests
|
|
|
|
name: test_converter.py
|
|
by: Josh Lucas
|
|
date: 2026-10-29
|
|
|
|
desc: Unit tests for the AuDaGe Converter module.
|
|
"""
|
|
|
|
import unittest
|
|
from importlib import resources
|
|
|
|
from AuDaGe.converter import Converter
|
|
|
|
try:
|
|
from tests import assets, output
|
|
except ImportError: # pragma: no cover
|
|
import assets # noqa: I001
|
|
import output # ty: ignore[unresolved-import]
|
|
|
|
|
|
class TestConverter(unittest.TestCase):
|
|
plcs = ("WA3252_PLC_001_1", "WA3252_PLC_002_1")
|
|
tags = ("caption", "desc", "message", "tagname", "unit")
|
|
|
|
def setUp(self):
|
|
self.assets_path = resources.files(assets)
|
|
self.output_path = resources.files(output)
|
|
|
|
def test_init(self):
|
|
self.converters = {}
|
|
for plc in self.plcs:
|
|
for tag in self.tags:
|
|
substitutions = {"$extension$": tag.title(), "$plc$": plc}
|
|
self.converters[(plc, tag)] = Converter(
|
|
f"extensions/kepserver/strings/{tag}_csv.yaml",
|
|
substitutions=substitutions,
|
|
)
|
|
|
|
def test_from_AF(self):
|
|
pass
|
|
|
|
def test_from_file(self):
|
|
self.kep = {}
|
|
for key, converter in self.converters.items():
|
|
self.kep[key] = converter.from_file(
|
|
str(self.assets_path.joinpath(f"{key[0]}.csv"))
|
|
)
|
|
|
|
def test_to_AF(self):
|
|
self.af = {}
|
|
for (kep_key, kep), (converter_key, converter) in zip(
|
|
self.kep.items(), self.converters.items()
|
|
):
|
|
self.af[kep_key] = converter.to_AF(kep)
|
|
|
|
def test_to_file(self):
|
|
pass
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(failfast=True)
|
|
# try:
|
|
# kep = kep_converter.from_file(
|
|
# f"C:/Users/j.lucas/OneDrive - Prime Controls/Customers/NTMWD/"
|
|
# f"Engineering/Leonard (North) Water Treatment Plant/Programs/PLC/"
|
|
# f"WA3252-PLC-001-1 Raw Water PS/{plc}.csv"
|
|
# )
|
|
# except FileNotFoundError:
|
|
# kep = kep_converter.from_file(
|
|
# f"D:/OneDrive - Prime Controls/Customers/NTMWD/"
|
|
# f"Engineering/Leonard (North) Water Treatment Plant/Programs/PLC/"
|
|
# f"WA3252-PLC-001-1 Raw Water PS/{plc}.csv"
|
|
# )
|
|
# af = kep_converter.to_AF(kep)
|
|
# kep2 = kep_converter.from_AF(af)
|
|
# kep_converter.to_file(kep2, f"tests/output/{plc}_strings_{tag}.csv")
|
|
# af2 = kep_converter.to_AF(kep2)
|
|
# macro_converter = Converter(
|
|
# f"extensions/factorytalk/macro/{tag}_macro.yaml",
|
|
# substitutions=substitutions,
|
|
# )
|
|
# macro = macro_converter.from_AF(af2)
|
|
# macro_converter.to_file(macro, f"tests/output/{plc}_{tag}.mcr")
|
|
# kep_converter = Converter("extensions/kepserver/modbus/csv.yaml")
|
|
# kep = kep_converter.from_file(
|
|
# f"C:/Users/j.lucas/OneDrive - Prime Controls/Customers/NTMWD/"
|
|
# f"Engineering/Leonard (North) Water Treatment Plant/Programs/PLC/"
|
|
# f"WA3252-PLC-001-1 Raw Water PS/{plc}.csv"
|
|
# )
|
|
# af = kep_converter.to_AF(kep)
|
|
# macro_converter = Converter(
|
|
# "extensions/factorytalk/macro/alarm_severity_macro.yaml",
|
|
# substitutions={"$plc$": plc},
|
|
# )
|
|
# macro = macro_converter.from_AF(af)
|
|
# macro_converter.to_file(
|
|
# macro, f"tests/output/{plc}_alarm_severities.mcr"
|
|
# )
|