/usr/lib/python2.7/dist-packages/pyvisa/testsuite/test_util.py is in python-pyvisa 1.8-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | # -*- coding: utf-8 -*-
from __future__ import division, unicode_literals, print_function, absolute_import
from pyvisa.testsuite import BaseTestCase
from pyvisa import util
try:
# noinspection PyPackageRequirements
import numpy as np
except ImportError:
np = None
class TestParser(BaseTestCase):
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)
def test_ieee_integer(self):
values = list(range(99))
containers = (list, tuple) #+ ((np.asarray,) if np else ())
for fmt in 'bBhHiIfd':
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)
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)
|