-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtestNtTypes.py
More file actions
109 lines (98 loc) · 3.39 KB
/
testNtTypes.py
File metadata and controls
109 lines (98 loc) · 3.39 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
import numpy as np
import random
import math
import pickle
from pvaccess import NtTable
from pvaccess import NtNdArray
from pvaccess import NtAttribute
from pvaccess import NtEnum
from pvaccess import NtScalar
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))
s = pickle.dumps(nda)
nda2 = pickle.loads(s)
value2 = nda2['value'][0]['ubyteValue']
print('After pickling, comparing image arrays {} to {}'.format(value2, value))
assert(np.array_equiv(value, value2))
#
# NtScalar
#
def test_NtScalar(self):
print()
value = random.randint(0,100000)
s = NtScalar(INT, value)
value2 = s['value']
print('Comparing scalar value {} to {}'.format(value2, value))
assert(value==value2)
#
# NtEnum
#
def test_NtEnum(self):
print()
maxInt = random.randint(2,100)
indices = list(range(0,maxInt))
choices = list(map(lambda i: 'Ch%d' % i, indices))
current = random.randint(0,maxInt-1)
e = NtEnum(choices, current)
current2 = e['value.index']
print('Comparing enum choice {} to {}'.format(current2, current))
assert(current==current2)
current = random.randint(0,maxInt)
e['value.index'] = current
current2 = e['value.index']
print('Comparing enum choice {} to {}'.format(current2, current))