Skip to content

Commit

Permalink
updated testing utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
sveseli committed Aug 14, 2020
1 parent 2009cfd commit 986c667
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 12 deletions.
12 changes: 11 additions & 1 deletion test/testChannelPut.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

#
Expand Down
74 changes: 74 additions & 0 deletions test/testNtTypes.py
Original file line number Diff line number Diff line change
@@ -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))



22 changes: 19 additions & 3 deletions test/testPvObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class TestPvObject:
#

def test_Boolean(self):
print()
value = TestUtility.getRandomBoolean()
pv = PvObject({'v' : BOOLEAN}, {'v' : value})
assert(pv['v'] == value)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
37 changes: 30 additions & 7 deletions test/testUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -21,6 +24,7 @@ class TestUtility:

FLOAT_PRECISION = 0.0001
DOUBLE_PRECISION = 0.000001
NANOSECONDS_IN_SECOND = 1000000000

@classmethod
def assertBooleanEquality(cls, value1, value2):
Expand All @@ -46,6 +50,12 @@ def assertFloatEquality(cls, value1, value2):
def assertDoubleEquality(cls, value1, value2):
assert(math.fabs(value1-value2)<cls.DOUBLE_PRECISION)

@classmethod
def assertListEquality(cls, list1, list2):
assert(len(list1) == len(list2))
for i in range(0,len(list1)):
assert(str(list1[i])==str(list2[i]))

@classmethod
def getRandomBoolean(cls):
allowedValues = [False, True]
Expand Down Expand Up @@ -74,22 +84,27 @@ def getRandomUShort(cls):

@classmethod
def getRandomInt(cls):
#return int(random.uniform(-2147483648,2147483648))
return int(random.uniform(-100,100))
return int(random.uniform(-2147483648,2147483648))
#return int(random.uniform(-100,100))

@classmethod
def getRandomUInt(cls):
return int(random.uniform(0,1000))
#return int(random.uniform(0,4294967296))
#return int(random.uniform(0,1000))
return int(random.uniform(0,4294967296))

@classmethod
def getRandomLong(cls):
return LONG(random.uniform(-9223372036854775806,9223372036854775806))
#return LONG(random.uniform(-10000,10000))

@classmethod
def getRandomPositiveLong(cls):
return LONG(random.uniform(0,9223372036854775806))

@classmethod
def getRandomULong(cls):
#return LONG(random.uniform(0,18446744073709551616))
return LONG(random.uniform(0,10000))
return LONG(random.uniform(0,18446744073709551616))
#return LONG(random.uniform(0,10000))

@classmethod
def getRandomFloat(cls):
Expand All @@ -109,7 +124,7 @@ def getRandomString(cls):

@classmethod
def getRandomListSize(cls):
return int(random.uniform(1,100))
return int(random.uniform(1,1000))

@classmethod
def getBooleanChannel(cls):
Expand Down Expand Up @@ -160,3 +175,11 @@ def getStringChannel(cls):
return Channel(TestServer.STRING_CHANNEL_NAME)


@classmethod
def getTimeStamp(cls):
tStamp = np.datetime64(dt.now(), 'ns')
t = (tStamp-np.datetime64(0,'ns'))/np.timedelta64(1, 's')
s = int(t)
ns = int((t - s)*cls.NANOSECONDS_IN_SECOND)
return PvTimeStamp(s,ns,0)

Empty file modified tools/build/build_env.sh
100644 → 100755
Empty file.
Empty file modified tools/build/build_pvapy.sh
100644 → 100755
Empty file.
Empty file modified tools/build/build_pvapy_python3.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion tools/conda/pvapy-conda/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ echo "Starting test server"
cd test
python testServer.py 15 &

for f in PvObject ChannelPut MultiChannel; do
for f in PvObject NtTypes ChannelPut MultiChannel; do
echo "Starting $f tests"
sleep 1
nosetests -v test$f.py
Expand Down
Empty file modified tools/local/pvapy-local/build.linux.sh
100644 → 100755
Empty file.
Empty file modified tools/local/pvapy-local/test.sh
100644 → 100755
Empty file.
Empty file modified tools/pip/pvapy-pip/build.darwin.sh
100644 → 100755
Empty file.
Empty file modified tools/pip/pvapy-pip/build.linux.sh
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions tools/pip/pvapy-pip/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ python testServer.py 10 &

echo "Starting tests"
nosetests -v testPvObject.py
nosetests -v testNtTypes.py
nosetests -v testChannelPut.py
nosetests -v testMultiChannel.py

Expand Down

0 comments on commit 986c667

Please sign in to comment.