Add config-based database conversion.
This commit is contained in:
5413
tests/assets/RTU_Status_List.csv
Normal file
5413
tests/assets/RTU_Status_List.csv
Normal file
File diff suppressed because it is too large
Load Diff
@@ -19,20 +19,27 @@ try:
|
||||
from tests import assets, output
|
||||
except ImportError: # pragma: no cover
|
||||
import assets # noqa: I001
|
||||
import output
|
||||
import output # ty: ignore[unresolved-import]
|
||||
|
||||
INPUT_FILES = (
|
||||
"RTU_Status_List.csv",
|
||||
"WA3251_PLC_001_1.csv",
|
||||
)
|
||||
|
||||
|
||||
class TestCSV(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.input_file = resources.files(assets).joinpath(
|
||||
"WA3251_PLC_001_1.csv"
|
||||
self.input_files = (
|
||||
resources.files(assets).joinpath(file) for file in INPUT_FILES
|
||||
)
|
||||
self.output_folder = resources.files(output)
|
||||
with MeasureTime(
|
||||
do_print=True,
|
||||
message="Kepserver CSV import completed in {time:.3f} {unit}",
|
||||
):
|
||||
self.csv_frame = csv.Frame.from_file(self.input_file)
|
||||
self.csv_frames = (
|
||||
csv.Frame.from_file(file) for file in self.input_files
|
||||
)
|
||||
with MeasureTime(
|
||||
do_print=True,
|
||||
message=(
|
||||
@@ -40,30 +47,34 @@ class TestCSV(unittest.TestCase):
|
||||
"{time:.3f} {unit}"
|
||||
),
|
||||
):
|
||||
self.af = self.csv_frame.to_AF()
|
||||
self.afs = (frame.to_AF() for frame in self.csv_frames)
|
||||
|
||||
def test_read(self):
|
||||
self.assertIsInstance(self.csv_frame, csv.Frame)
|
||||
for frame in self.csv_frames:
|
||||
self.assertIsInstance(frame, csv.Frame)
|
||||
|
||||
def test_from_af(self):
|
||||
with MeasureTime(
|
||||
do_print=True,
|
||||
message=(
|
||||
"Kepserver CSV frame translation from AuDaGeFrame completed in "
|
||||
"{time:.3f} {unit}"
|
||||
),
|
||||
):
|
||||
translate_from_af = csv.Frame.from_AF(self.af)
|
||||
self.assertIsInstance(translate_from_af, csv.Frame)
|
||||
translate_from_af.to_file(
|
||||
self.output_folder.joinpath("kep_from_af.csv")
|
||||
)
|
||||
for i, frame in enumerate(self.afs):
|
||||
with MeasureTime(
|
||||
do_print=True,
|
||||
message=(
|
||||
"Kepserver CSV frame translation from AuDaGeFrame "
|
||||
"completed in {time:.3f} {unit}"
|
||||
),
|
||||
):
|
||||
translate_from_af = csv.Frame.from_AF(frame)
|
||||
self.assertIsInstance(translate_from_af, csv.Frame)
|
||||
translate_from_af.to_file(
|
||||
self.output_folder.joinpath("kep_from_af{i}.csv")
|
||||
)
|
||||
|
||||
def test_to_af(self):
|
||||
self.assertIsInstance(self.af, AuDaGeFrame)
|
||||
for frame in self.afs:
|
||||
self.assertIsInstance(frame, AuDaGeFrame)
|
||||
|
||||
def test_write(self):
|
||||
self.csv_frame.to_file(self.output_folder.joinpath("kepserver.csv"))
|
||||
for i, frame in enumerate(self.csv_frames):
|
||||
frame.to_file(self.output_folder.joinpath(f"kepserver{i}.csv"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -18,7 +18,7 @@ try:
|
||||
from tests import assets, output
|
||||
except ImportError: # pragma: no cover
|
||||
import assets # noqa: I001
|
||||
import output
|
||||
import output # ty: ignore[unresolved-import]
|
||||
|
||||
|
||||
class TestXSY(unittest.TestCase):
|
||||
@@ -30,13 +30,12 @@ class TestXSY(unittest.TestCase):
|
||||
self.in_paths = [
|
||||
file
|
||||
for file in resources.files(assets).iterdir()
|
||||
if os.path.splitext(file)[-1].lower() == ".xsy"
|
||||
if os.path.splitext(str(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)
|
||||
datablock = XSYBlock.from_file(in_path)
|
||||
self.assertIsInstance(datablock, XSYBlock)
|
||||
|
||||
def test_Definitions(self):
|
||||
@@ -52,7 +51,7 @@ class TestXSYReader(unittest.TestCase):
|
||||
self.in_paths = [
|
||||
file
|
||||
for file in resources.files(assets).iterdir()
|
||||
if os.path.splitext(file)[-1].lower() == ".xsy"
|
||||
if os.path.splitext(str(file))[-1].lower() == ".xsy"
|
||||
]
|
||||
self.out_path = resources.files(output)
|
||||
|
||||
@@ -66,7 +65,7 @@ class TestXSYReader(unittest.TestCase):
|
||||
|
||||
def test_export(self):
|
||||
for path in self.in_paths:
|
||||
file_name = os.path.splitext(os.path.split(path)[-1])[0]
|
||||
file_name = os.path.splitext(os.path.split(str(path))[-1])[0]
|
||||
xsy = self.xsy_reader.read(path, expand=False)
|
||||
xsy.datablock.to_csv(
|
||||
self.out_path.joinpath(f"{file_name}_datablock.csv"),
|
||||
@@ -78,7 +77,9 @@ class TestXSYReader(unittest.TestCase):
|
||||
)
|
||||
debug = False
|
||||
for debug_step in (
|
||||
XSY.DebugStep if debug else [XSY.DebugStep.COMPLETE]
|
||||
XSY.DebugStep
|
||||
if debug
|
||||
else [XSY.DebugStep.MAKE_ARRAY_DEFS, XSY.DebugStep.COMPLETE]
|
||||
):
|
||||
xsy.expand_datablock(debug_step=debug_step).to_csv(
|
||||
self.out_path.joinpath(
|
||||
|
||||
Reference in New Issue
Block a user