diff --git a/test/testChannelPut.py b/test/testChannelPut.py index 095dbcce..c896473c 100644 --- a/test/testChannelPut.py +++ b/test/testChannelPut.py @@ -226,24 +226,34 @@ def testPutLong_Long(self): # def testPut_PvULong(self): + print() value = TestUtility.getRandomULong() c = TestUtility.getULongChannel() c.put(PvULong(value)) value2 = c.get().getPyObject() + print('Testing equality: %d == %d' % (value2, value)) assert(value == value2) def testPut_ULong(self): - value = TestUtility.getRandomULong() + print() + # put(ulong) will be mapped to put(long) in python, + # resulting in overflow errors; + # simply use positive long for this test + value = TestUtility.getRandomPositiveLong() c = TestUtility.getULongChannel() + print('Test value: %d' % (value)) c.put(value) value2 = c.get().getPyObject() + print('Testing equality: %d == %d' % (value2, value)) assert(value == value2) def testPutULong_ULong(self): + print() value = TestUtility.getRandomULong() c = TestUtility.getULongChannel() c.putULong(value) value2 = c.get().getPyObject() + print('Testing equality: %d == %d' % (value2, value)) assert(value == value2) # diff --git a/test/testNtTypes.py b/test/testNtTypes.py new file mode 100644 index 00000000..8beacfed --- /dev/null +++ b/test/testNtTypes.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +import numpy as np +import random +import math +from pvaccess import NtTable +from pvaccess import NtNdArray +from pvaccess import NtAttribute +from pvaccess import PvDimension +from pvaccess import PvCodec +from pvaccess import PvInt +from pvaccess import INT +from pvaccess import UBYTE +from testUtility import TestUtility + + +class TestNtTypes: + + # + # NtTable + # + + def test_NtTable(self): + print() + nColumns = random.randint(3,10) + dim = random.randint(10,100) + print('Using {} columns of size: {}'.format(nColumns,dim)) + maxInt = int(math.fabs(TestUtility.getRandomInt())) + print('Using Max Int for array element: {}'.format(maxInt)) + ntTable = NtTable(nColumns, INT) + labels = [] + columns = [] + for i in range(0, nColumns): + labels.append('Col%d' % (i+1)) + columns.append(list(np.random.randint(-maxInt,maxInt, size=dim, dtype=np.int32))) + ntTable.setColumn(i, columns[i]) + ntTable.setLabels(labels) + TestUtility.assertListEquality(ntTable['labels'], labels) + for i in range(0, nColumns): + a1 = ntTable.getColumn(i) + a2 = columns[i] + TestUtility.assertListEquality(a1,a2) + + + # + # NtNdArray + # + + def test_NtNdArray(self): + print() + timeStamp = TestUtility.getTimeStamp() + id = random.randint(0,100000) + nx = 1024 + ny = 1024 + nda = NtNdArray() + nda['uniqueId'] = id + dims = [PvDimension(nx, 0, nx, 1, False), PvDimension(ny, 0, ny, 1, False)] + nda['codec'] = PvCodec('pvapyc', PvInt(14)) + nda['dimension'] = dims + nda['descriptor'] = 'PvaPy Simulated Image' + nda['compressedSize'] = nx*ny + nda['uncompressedSize'] = nx*ny + nda['timeStamp'] = timeStamp + nda['dataTimeStamp'] = timeStamp + attrs = [NtAttribute('ColorMode', PvInt(0))] + nda['attribute'] = attrs + value = np.random.randint(0,256, size=nx*ny, dtype=np.uint8) + nda['value'] = {'ubyteValue' : value} + value2 = nda['value'][0]['ubyteValue'] + print('Comparing image arrays {} to {}'.format(value2, value)) + assert(np.array_equiv(value, value2)) + + + diff --git a/test/testPvObject.py b/test/testPvObject.py index eeee2c3e..be3f87ec 100644 --- a/test/testPvObject.py +++ b/test/testPvObject.py @@ -26,6 +26,7 @@ class TestPvObject: # def test_Boolean(self): + print() value = TestUtility.getRandomBoolean() pv = PvObject({'v' : BOOLEAN}, {'v' : value}) assert(pv['v'] == value) @@ -41,6 +42,7 @@ def test_Boolean(self): # def test_Byte(self): + print() value = chr(TestUtility.getRandomUByte()) pv = PvObject({'v' : BYTE}, {'v' : value}) assert(pv['v'] == value) @@ -56,6 +58,7 @@ def test_Byte(self): # def test_UByte(self): + print() value = TestUtility.getRandomUByte() pv = PvObject({'v' : UBYTE}, {'v' : value}) assert(pv['v'] == value) @@ -71,6 +74,7 @@ def test_UByte(self): # def test_Short(self): + print() value = TestUtility.getRandomShort() pv = PvObject({'v' : SHORT}, {'v' : value}) assert(pv['v'] == value) @@ -86,6 +90,7 @@ def test_Short(self): # def test_UShort(self): + print() value = TestUtility.getRandomUShort() pv = PvObject({'v' : USHORT}, {'v' : value}) assert(pv['v'] == value) @@ -101,6 +106,7 @@ def test_UShort(self): # def test_Int(self): + print() value = TestUtility.getRandomInt() pv = PvObject({'v' : INT}, {'v' : value}) assert(pv['v'] == value) @@ -116,6 +122,7 @@ def test_Int(self): # def test_UInt(self): + print() value = TestUtility.getRandomUInt() pv = PvObject({'v' : UINT}, {'v' : value}) assert(pv['v'] == value) @@ -131,6 +138,7 @@ def test_UInt(self): # def test_Long(self): + print() value = TestUtility.getRandomLong() pv = PvObject({'v' : LONG}, {'v' : value}) assert(pv['v'] == value) @@ -146,6 +154,7 @@ def test_Long(self): # def test_ULong(self): + print() value = TestUtility.getRandomULong() pv = PvObject({'v' : ULONG}, {'v' : value}) assert(pv['v'] == value) @@ -161,15 +170,22 @@ def test_ULong(self): # def test_Float(self): + print() value = TestUtility.getRandomFloat() pv = PvObject({'v' : FLOAT}, {'v' : value}) - TestUtility.assertFloatEquality(pv['v'], value) + value2 = pv['v'] + print('Testing equality: %.10f == %.10f' % (value2, value)) + TestUtility.assertFloatEquality(value2, value) value = TestUtility.getRandomFloat() pv['v'] = value - TestUtility.assertFloatEquality(pv['v'], value) + value2 = pv['v'] + print('Testing equality: %.10f == %.10f' % (value2, value)) + TestUtility.assertFloatEquality(value2, value) value = TestUtility.getRandomFloat() pv.setFloat(value) - TestUtility.assertFloatEquality(pv.getFloat(), value) + value2 = pv.getFloat() + print('Testing equality: %.10f == %.10f' % (value2, value)) + TestUtility.assertFloatEquality(value2, value) # # Double diff --git a/test/testUtility.py b/test/testUtility.py index d1aa1ff8..198a6d66 100644 --- a/test/testUtility.py +++ b/test/testUtility.py @@ -4,8 +4,11 @@ import string import math import types +import numpy as np +from datetime import datetime as dt from pvaccess import Channel +from pvaccess import PvTimeStamp from testServer import TestServer try: @@ -21,6 +24,7 @@ class TestUtility: FLOAT_PRECISION = 0.0001 DOUBLE_PRECISION = 0.000001 + NANOSECONDS_IN_SECOND = 1000000000 @classmethod def assertBooleanEquality(cls, value1, value2): @@ -46,6 +50,12 @@ def assertFloatEquality(cls, value1, value2): def assertDoubleEquality(cls, value1, value2): assert(math.fabs(value1-value2)