def test_get_int_values(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) for value in (-32768, -16385, -256, -128, -127, 0, 127, 128, 255, 256, 16384, 32767): row['ID'] = value self.assertEqual(row['ID'], value)
def test_get_int(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) x = row['ID'] y = row['testint2'] self.assertEqual(x, 0) self.assertEqual(y, 0)
def test_write_string(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) row['NAME'] = 'abc' self.assertTrue(row['NAME'] == 'abc') row['NAME'] = '' self.assertTrue(row['NAME'] == '')
def test_export(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) data = row.export() self.assertIn('testDword', data) self.assertIn('testbool1', data) self.assertEqual(data['testbool5'], 0)
def test_export(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) data = row.export() self.assertTrue('testDword' in data) self.assertTrue('testbool1' in data) self.assertTrue(data['testbool5'] == 0)
def test_get_string(self): """ Text extraction from string from bytearray """ test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) self.assertEqual(row['NAME'], 'test')
def test_set_bool(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) row['testbool8'] = True row['testbool1'] = False self.assertEqual(row['testbool8'], True) self.assertEqual(row['testbool1'], False)
def test_set_bool(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) row['testbool8'] = 1 row['testbool1'] = 0 self.assertEqual(row['testbool8'], 1) self.assertEqual(row['testbool1'], 0)
def test_get_time(self): """ TIME extraction from bytearray """ test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) self.assertEqual(row['testTime'], '-21:17:57:28.193')
def test_get_s5time(self): """ S5TIME extraction from bytearray """ test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) self.assertEqual(row['testS5time'], '0:00:00.100000')
def test_get_dt(self): """ DATE_AND_TIME extraction from bytearray """ test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) self.assertEqual(row['testdateandtime'], '2020-07-12T17:32:02.854000')
def test_get_dtl(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec_indented, layout_offset=4) val = row['testDtl'] self.assertEqual( val, datetime.datetime(year=2022, month=3, day=9, hour=12, minute=34, second=45))
def test_write_string(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) row['NAME'] = 'abc' self.assertEqual(row['NAME'], 'abc') row['NAME'] = '' self.assertEqual(row['NAME'], '') try: row['NAME'] = 'waaaaytoobig' except ValueError: pass # value should still be empty self.assertEqual(row['NAME'], '')
def test_indented_layout(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec_indented, layout_offset=4) x = row['ID'] y_single_space = row['testbool1'] y_multi_space = row['testbool2'] y_single_indent = row['testint2'] y_multi_indent = row['testbool8'] with self.assertRaises(KeyError): fail_single_space = row['testbool4'] with self.assertRaises(KeyError): fail_multiple_spaces = row['testbool5'] with self.assertRaises(KeyError): fail_single_indent = row['testbool6'] with self.assertRaises(KeyError): fail_multiple_indent = row['testbool7'] self.assertEqual(x, 0) self.assertEqual(y_single_space, True) self.assertEqual(y_multi_space, True) self.assertEqual(y_single_indent, 0) self.assertEqual(y_multi_indent, 0)
def test_set_word(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) # The range of numbers is 0 to 65535 row.set_value(27, 'WORD', 0) # set value self.assertEqual(row['testWord'], 0)
def test_get_dint(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) value = row.get_value(23, 'DINT') # get value self.assertEqual(value, -2147483648)
def test_set_dint(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) # The range of numbers is -2147483648 to 2147483647 + row.set_value(23, 'DINT', 2147483647) # set value self.assertEqual(row['testDint'], 2147483647)
def test_get_dword(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) self.assertEqual(row['testDword'], 4294967295)
def test_set_dword(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) # The range of numbers is 0 to 4294967295. row['testDword'] = 9999999 self.assertEqual(row['testDword'], 9999999)
def test_get_char(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec_indented, layout_offset=4) val = row['testChar'] self.assertEqual(val, 'A')
def test_set_sint(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) row['testsint0'] = 127 self.assertEqual(row['testsint0'], 127)
def test_get_sint(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) value = row.get_value(44, 'SINT') # get value self.assertEqual(value, 127)
def test_get_wstring(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec_indented, layout_offset=4) val = row['testWstring'] self.assertEqual(val, 'ΩstÄ')
def test_get_date(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec_indented, layout_offset=4) val = row['testDate'] self.assertEqual(val, datetime.date(day=9, month=3, year=2022))
def test_get_tod(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec_indented, layout_offset=4) val = row['testTod'] self.assertEqual(val, datetime.timedelta(hours=12, minutes=34, seconds=56))
def test_get_word(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) value = row.get_value(27, 'WORD') # get value self.assertEqual(value, 65535)
def test_get_lreal(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec_indented, layout_offset=4) val = row['testLreal'] self.assertEqual(val, 123456789.123456789)
def test_get_real(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) self.assertTrue(0.01 > (row['testReal'] - 827.3) > -0.1)
def test_set_int(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) row['ID'] = 259 self.assertEqual(row['ID'], 259)
def test_set_real(self): test_array = bytearray(_bytearray) row = util.DB_Row(test_array, test_spec, layout_offset=4) row['testReal'] = 1337.1337 self.assertTrue(0.01 > (row['testReal'] - 1337.1337) > -0.01)