Example #1
0
 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)
Example #2
0
 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)
Example #3
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'] == '')
Example #4
0
 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)
Example #5
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)
Example #6
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')
Example #7
0
    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)
Example #8
0
    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)
Example #9
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')
Example #10
0
    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')
Example #11
0
    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')
Example #12
0
 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))
Example #13
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.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'], '')
Example #14
0
    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)
Example #15
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)
Example #16
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)
Example #17
0
 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)
Example #18
0
 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)
Example #19
0
 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)
Example #20
0
 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')
Example #21
0
 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)
Example #22
0
 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)
Example #23
0
 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Ä')
Example #24
0
 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))
Example #25
0
 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))
Example #26
0
 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)
Example #27
0
 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)
Example #28
0
 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)
Example #29
0
 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)
Example #30
0
 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)