mirror of
https://github.com/naruxde/revpimodio2.git
synced 2025-11-08 13:53:53 +01:00
test: Test replace_io file
This commit is contained in:
1
tests/replace_io/config.rsc
Normal file
1
tests/replace_io/config.rsc
Normal file
File diff suppressed because one or more lines are too long
22
tests/replace_io/replace_io.conf
Normal file
22
tests/replace_io/replace_io.conf
Normal file
@@ -0,0 +1,22 @@
|
||||
[test1]
|
||||
replace=Output_19
|
||||
frm=b
|
||||
defaultvalue=255
|
||||
byteorder=big
|
||||
|
||||
[r_bit0]
|
||||
replace=Output_20
|
||||
bmk=EinBit
|
||||
frm=?
|
||||
bit=0
|
||||
|
||||
[r_bit1]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=1
|
||||
defaultvalue=True
|
||||
|
||||
[r_bit5]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=5
|
||||
5
tests/replace_io/replace_io_bytes.conf
Normal file
5
tests/replace_io/replace_io_bytes.conf
Normal file
@@ -0,0 +1,5 @@
|
||||
[data_values]
|
||||
replace = I_LiftData
|
||||
frm = 200s
|
||||
defaultvalue = 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
|
||||
5
tests/replace_io/replace_io_bytes_fail.conf
Normal file
5
tests/replace_io/replace_io_bytes_fail.conf
Normal file
@@ -0,0 +1,5 @@
|
||||
[data_values]
|
||||
replace = I_LiftData
|
||||
frm = 200s
|
||||
defaultvalue = 255 0 0 0 0 a 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
|
||||
19
tests/replace_io/replace_io_fail.conf
Normal file
19
tests/replace_io/replace_io_fail.conf
Normal file
@@ -0,0 +1,19 @@
|
||||
[test1]
|
||||
replace=Output_19
|
||||
frm=h
|
||||
|
||||
[r_bit0]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=0
|
||||
|
||||
[r_bit1]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=1
|
||||
defaultvalue=True
|
||||
|
||||
[r_bit5]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=5
|
||||
19
tests/replace_io/replace_io_failbit_int.conf
Normal file
19
tests/replace_io/replace_io_failbit_int.conf
Normal file
@@ -0,0 +1,19 @@
|
||||
[test1]
|
||||
replace=Output_19
|
||||
frm=b
|
||||
|
||||
[r_bit0]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=True
|
||||
|
||||
[r_bit1]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=1
|
||||
defaultvalue=True
|
||||
|
||||
[r_bit5]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=5
|
||||
19
tests/replace_io/replace_io_faildefaultvalue_bool.conf
Normal file
19
tests/replace_io/replace_io_faildefaultvalue_bool.conf
Normal file
@@ -0,0 +1,19 @@
|
||||
[test1]
|
||||
replace=Output_19
|
||||
frm=c
|
||||
|
||||
[r_bit0]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=0
|
||||
|
||||
[r_bit1]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=1
|
||||
defaultvalue=komisch
|
||||
|
||||
[r_bit5]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=5
|
||||
20
tests/replace_io/replace_io_faildefaultvalue_int.conf
Normal file
20
tests/replace_io/replace_io_faildefaultvalue_int.conf
Normal file
@@ -0,0 +1,20 @@
|
||||
[test1]
|
||||
replace=Output_19
|
||||
frm=c
|
||||
defaultvalue=True
|
||||
|
||||
[r_bit0]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=0
|
||||
|
||||
[r_bit1]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=1
|
||||
defaultvalue=True
|
||||
|
||||
[r_bit5]
|
||||
replace=Output_20
|
||||
frm=?
|
||||
bit=5
|
||||
4
tests/replace_io/replace_io_failformat.conf
Normal file
4
tests/replace_io/replace_io_failformat.conf
Normal file
@@ -0,0 +1,4 @@
|
||||
[test1
|
||||
replace=Output_19
|
||||
frm h
|
||||
|
||||
65
tests/replace_io/test_replace_io.py
Normal file
65
tests/replace_io/test_replace_io.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Tests for replace io file."""
|
||||
__author__ = "Sven Sager"
|
||||
__copyright__ = "Copyright (C) 2024 Sven Sager"
|
||||
__license__ = "GPLv2"
|
||||
|
||||
from os.path import join, dirname
|
||||
|
||||
from tests import TestRevPiModIO
|
||||
|
||||
|
||||
class TestReplaceIO(TestRevPiModIO):
|
||||
|
||||
data_dir = dirname(__file__)
|
||||
|
||||
def test_replace_io_file(self):
|
||||
replace_io_file = join(self.data_dir, "replace_io.conf")
|
||||
rpi = self.modio(replace_io_file=replace_io_file)
|
||||
self.assertEqual(rpi.replace_io_file, replace_io_file)
|
||||
rpi.setdefaultvalues()
|
||||
self.assertEqual(rpi.io.test1.value, -1)
|
||||
self.assertFalse(rpi.io.r_bit0.value)
|
||||
self.assertTrue(rpi.io.r_bit1.value)
|
||||
self.assertFalse(rpi.io.r_bit5.value)
|
||||
self.assertFalse("Output_19" in rpi.io)
|
||||
|
||||
self.assertEqual(rpi.io.test1.byteorder, "big")
|
||||
self.assertEqual(rpi.io.r_bit0.byteorder, "little")
|
||||
|
||||
self.assertEqual(rpi.io.r_bit0.bmk, "EinBit")
|
||||
|
||||
with self.assertRaises(RuntimeError):
|
||||
rpi.export_replaced_ios("/gehtnich/replace_io.conf")
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
rpi.io.test1.export = 1
|
||||
rpi.io.test1.export = True
|
||||
rpi.io.Input_20.replace_io("byte_test", "3s", defaultvalue=b"\xff\x00\x80", export=True)
|
||||
rpi.export_replaced_ios("/tmp/replace_io.conf")
|
||||
del rpi
|
||||
|
||||
rpi = self.modio(replace_io_file="/tmp/replace_io.conf")
|
||||
self.assertTrue(rpi.io.test1.export)
|
||||
self.assertTrue(rpi.io.byte_test.export)
|
||||
self.assertEqual(rpi.io.byte_test.defaultvalue, b"\xff\x00\x80")
|
||||
|
||||
def test_fb_replace_io_fail(self):
|
||||
with self.assertRaises(RuntimeError):
|
||||
rpi = self.modio(replace_io_file=join(self.data_dir, "replace_io_fail.conf"))
|
||||
with self.assertRaises(RuntimeError):
|
||||
rpi = self.modio(replace_io_file="no_file_nonono")
|
||||
with self.assertRaises(RuntimeError):
|
||||
rpi = self.modio(replace_io_file=join(self.data_dir, "replace_io_failformat.conf"))
|
||||
with self.assertRaises(ValueError):
|
||||
rpi = self.modio(
|
||||
replace_io_file=join(self.data_dir, "replace_io_faildefaultvalue_bool.conf")
|
||||
)
|
||||
with self.assertRaises(ValueError):
|
||||
rpi = self.modio(
|
||||
replace_io_file=join(self.data_dir, "replace_io_faildefaultvalue_int.conf")
|
||||
)
|
||||
with self.assertRaises(ValueError):
|
||||
rpi = self.modio(replace_io_file=join(self.data_dir, "replace_io_failbit_int.conf"))
|
||||
with self.assertRaisesRegex(ValueError, r"defaultvalue to bytes"):
|
||||
rpi = self.modio(replace_io_file=join(self.data_dir, "replace_io_bytes_fail.conf"))
|
||||
Reference in New Issue
Block a user