Ejemplo n.º 1
0
    def test_parse_binary(self):
        s = (b'#A@\xe2\x8b<@\xe2\x8b<@\xe2\x8b<@\xe2\x8b<@\xde\x8b<@\xde\x8b<@'
             b'\xde\x8b<@\xde\x8b<@\xe0\x8b<@\xe0\x8b<@\xdc\x8b<@\xde\x8b<@'
             b'\xe2\x8b<@\xe0\x8b<')
        e = [
            0.01707566, 0.01707566, 0.01707566, 0.01707566, 0.01707375,
            0.01707375, 0.01707375, 0.01707375, 0.01707470, 0.01707470,
            0.01707280, 0.01707375, 0.01707566, 0.01707470
        ]
        with self.assertWarns(FutureWarning):
            p = util.parse_binary(s, is_big_endian=False, is_single=True)
        for a, b in zip(p, e):
            self.assertAlmostEqual(a, b)

        # Test handling indefinite length block
        p = util.from_ieee_block(s, datatype='f', is_big_endian=False)
        for a, b in zip(p, e):
            self.assertAlmostEqual(a, b)

        # Test handling definite length block
        p = util.from_ieee_block(b'#214' + s[2:],
                                 datatype='f',
                                 is_big_endian=False)
        for a, b in zip(p, e):
            self.assertAlmostEqual(a, b)

        p = util.from_hp_block(b'#A\x0e\x00' + s[2:],
                               datatype='f',
                               is_big_endian=False)
        for a, b in zip(p, e):
            self.assertAlmostEqual(a, b)
Ejemplo n.º 2
0
    def test_parse_binary(self):
        s = (b'#A@\xe2\x8b<@\xe2\x8b<@\xe2\x8b<@\xe2\x8b<@\xde\x8b<@\xde\x8b<@'
             b'\xde\x8b<@\xde\x8b<@\xe0\x8b<@\xe0\x8b<@\xdc\x8b<@\xde\x8b<@'
             b'\xe2\x8b<@\xe0\x8b<')
        e = [
            0.01707566, 0.01707566, 0.01707566, 0.01707566, 0.01707375,
            0.01707375, 0.01707375, 0.01707375, 0.01707470, 0.01707470,
            0.01707280, 0.01707375, 0.01707566, 0.01707470
        ]

        # Test handling indefinite length block
        p = util.from_ieee_block(s, datatype='f', is_big_endian=False)
        for a, b in zip(p, e):
            self.assertAlmostEqual(a, b)

        # Test handling definite length block
        p = util.from_ieee_block(b'#214' + s[2:],
                                 datatype='f',
                                 is_big_endian=False)
        for a, b in zip(p, e):
            self.assertAlmostEqual(a, b)

        p = util.from_hp_block(b'#A\x0e\x00' + s[2:],
                               datatype='f',
                               is_big_endian=False,
                               container=partial(array.array, 'f'))
        for a, b in zip(p, e):
            self.assertAlmostEqual(a, b)
Ejemplo n.º 3
0
    def test_parse_binary(self):
        s = (b'#A@\xe2\x8b<@\xe2\x8b<@\xe2\x8b<@\xe2\x8b<@\xde\x8b<@\xde\x8b<@'
             b'\xde\x8b<@\xde\x8b<@\xe0\x8b<@\xe0\x8b<@\xdc\x8b<@\xde\x8b<@'
             b'\xe2\x8b<@\xe0\x8b<')
        e = [0.01707566, 0.01707566, 0.01707566, 0.01707566, 0.01707375,
             0.01707375, 0.01707375, 0.01707375, 0.01707470, 0.01707470,
             0.01707280, 0.01707375, 0.01707566, 0.01707470]
        with self.assertWarns(FutureWarning):
            p = util.parse_binary(s, is_big_endian=False, is_single=True)
        for a, b in zip(p, e):
            self.assertAlmostEqual(a, b)

        # Test handling indefinite length block
        p = util.from_ieee_block(s, datatype='f', is_big_endian=False)
        for a, b in zip(p, e):
            self.assertAlmostEqual(a, b)

        # Test handling definite length block
        p = util.from_ieee_block(b'#214' + s[2:], datatype='f',
                                 is_big_endian=False)
        for a, b in zip(p, e):
            self.assertAlmostEqual(a, b)

        p = util.from_hp_block(b'#A\x0e\x00' + s[2:], datatype='f',
                               is_big_endian=False)
        for a, b in zip(p, e):
            self.assertAlmostEqual(a, b)
Ejemplo n.º 4
0
 def test_ieee_noninteger(self):
     values = [val + 0.5 for val in range(100)]
     containers = (list, tuple) #+ ((np.asarray,) if np else ())
     for fmt in 'fd':
         for endi in (True, False):
             for cont in containers:
                 conv = cont(values)
                 block = util.to_ieee_block(conv, fmt, endi)
                 parsed = util.from_ieee_block(block, fmt, endi, cont)
                 self.assertEqual(conv, parsed)
Ejemplo n.º 5
0
    def test_parse_binary(self):
        s = (
            b"#A@\xe2\x8b<@\xe2\x8b<@\xe2\x8b<@\xe2\x8b<@\xde\x8b<@\xde\x8b<@"
            b"\xde\x8b<@\xde\x8b<@\xe0\x8b<@\xe0\x8b<@\xdc\x8b<@\xde\x8b<@"
            b"\xe2\x8b<@\xe0\x8b<"
        )
        e = [
            0.01707566,
            0.01707566,
            0.01707566,
            0.01707566,
            0.01707375,
            0.01707375,
            0.01707375,
            0.01707375,
            0.01707470,
            0.01707470,
            0.01707280,
            0.01707375,
            0.01707566,
            0.01707470,
        ]

        # Test handling indefinite length block
        p = util.from_ieee_block(s, datatype="f", is_big_endian=False)
        for a, b in zip(p, e):
            assert a == pytest.approx(b)

        # Test handling definite length block
        p = util.from_ieee_block(b"#214" + s[2:], datatype="f", is_big_endian=False)
        for a, b in zip(p, e):
            assert a == pytest.approx(b)

        p = util.from_hp_block(
            b"#A\x0e\x00" + s[2:],
            datatype="f",
            is_big_endian=False,
            container=partial(array.array, "f"),
        )
        for a, b in zip(p, e):
            assert a == pytest.approx(b)
Ejemplo n.º 6
0
 def test_parse_binary(self):
     s = b'#A@\xe2\x8b<@\xe2\x8b<@\xe2\x8b<@\xe2\x8b<@\xde\x8b<@\xde\x8b<@\xde\x8b<' \
         b'@\xde\x8b<@\xe0\x8b<@\xe0\x8b<@\xdc\x8b<@\xde\x8b<@\xe2\x8b<@\xe0\x8b<'
     e = [0.01707566, 0.01707566, 0.01707566, 0.01707566, 0.01707375,
          0.01707375, 0.01707375, 0.01707375, 0.01707470, 0.01707470,
          0.01707280, 0.01707375, 0.01707566, 0.01707470]
     p = util.parse_binary(s, is_big_endian=False, is_single=True)
     for a, b in zip(p, e):
         self.assertAlmostEqual(a, b)
     p = util.from_ieee_block(s, datatype='f', is_big_endian=False)
     for a, b in zip(p, e):
         self.assertAlmostEqual(a, b)
Ejemplo n.º 7
0
    def test_ieee_noninteger(self):
        values = [val + 0.5 for val in range(100)]
        containers = (list, tuple) #+ ((np.asarray,) if np else ())
        for fmt in 'fd':
            for endi in (True, False):
                for cont in containers:
                    conv = cont(values)
                    msg = 'fmt=%s, endianness=%s, container=%s' % (fmt, endi, cont.__name__)
                    try:
                        block = util.to_ieee_block(conv, fmt, endi)
                        parsed = util.from_ieee_block(block, fmt, endi, cont)
                    except Exception as e:
                        raise Exception(msg + '\n' + repr(e))

                    self.assertEqual(conv, parsed, msg)
Ejemplo n.º 8
0
    def test_ieee_noninteger(self):
        values = [val + 0.5 for val in range(99)]
        containers = (list, tuple) #+ ((np.asarray,) if np else ())
        for fmt in 'fd':
            for endi in (True, False):
                for cont in containers:
                    conv = cont(values)
                    msg = 'fmt=%s, endianness=%s, container=%s' % (fmt, endi, cont.__name__)
                    try:
                        block = util.to_ieee_block(conv, fmt, endi)
                        parsed = util.from_ieee_block(block, fmt, endi, cont)
                    except Exception as e:
                        raise Exception(msg + '\n' + repr(e))

                    self.assertEqual(conv, parsed, msg)