-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.py
221 lines (180 loc) · 7.19 KB
/
tests.py
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import time
import numpy
import cv2
import PIL
import PIL.Image
from PhotonFile import *
import RLE
import configparser
config = configparser.ConfigParser()
config.read('TEST.INI')
l=['aaa','sss','ddf','ff']
config['DEFAULT']['path'] = '/var/shared/' # update
config['DEFAULT']['list'] = ','.join(l) # update
with open('TEST.INI', 'w') as configfile: # save
config.write(configfile)
config.read('TEST.INI')
print (config['DEFAULT']['path'])
print (config['DEFAULT']['list'].split(","))
quit()
def testcases():
# Test cases
# read / save photon file
# read / save cbddlp file (should be same as photon file)
# read / save properties for header/layers
#
print ("Save All...")
photon_filepath_org='/home/nard/PhotonFile/test/bunny.photon'
photonfile=PhotonFile()
photonfile.load(photon_filepath_org)
photon_dirpath_new='/home/nard/PhotonFile/test/bunny.img'
photonfile.layers.saveAll(photon_dirpath_new)
print("...success.")
return
print ("Test signatures...")
photonfile=PhotonFile()
photon_filepath_org='/home/nard/PhotonFile/test/bunny.photon'
photonfile.load(photon_filepath_org)
assert (photonfile.signature()=='ChituBox 1.4.0')
print("...success.")
print ("Test read/write .cbddlp file...")
filepath='/home/nard/PhotonFile/test/bunny.cbddlp'
filepath_new='/home/nard/PhotonFile/test/bunny2.cbddlp'
org_filesize=os.path.getsize(filepath)
photonfile=PhotonFile(filepath)
photonfile.load()
photonfile.save(filepath_new)
new_filesize=os.path.getsize(filepath_new)
assert new_filesize==org_filesize
print("...success.")
print ("Test read/write .photon file...")
filepath='/home/nard/PhotonFile/test/bunny.photon'
filepath_new='/home/nard/PhotonFile/test/bunny2.photon'
org_filesize=os.path.getsize(filepath)
photonfile=PhotonFile()
#photonfile.load()
photonfile.load(filepath)
photonfile.load(filepath) # do this 2 time to check clear old vars
photonfile.save(filepath_new)
new_filesize=os.path.getsize(filepath_new)
assert new_filesize==org_filesize
print("...success.")
print ("Test layers.count / layers.last / layers.height / volume...")
filepath='/home/nard/PhotonFile/test/bunny.photon'
photonfile.load(filepath)
assert photonfile.layers.count() == 1716
assert photonfile.layers.last() == 1716 -1
assert photonfile.layers.height(0) == 0.05
assert photonfile.volume(retUnit='ml') == 9.0
print("...success.")
print ("Test Property get/set...")
dlpWidth_write=2560
prevWidth_write=320
layerHeight_write=0.04
photonfile.setProperty("Resolution X",dlpWidth_write)
photonfile.previews.setProperty(0,"Resolution X",prevWidth_write)
photonfile.layers.setProperty(0,"Layer height (mm)",layerHeight_write)
dlpWidth_read=photonfile.getProperty("Resolution X")
prevWidth_read=photonfile.previews.getProperty(0,"Resolution X")
layerHeight_read=photonfile.layers.getProperty(0,"Layer height (mm)")
assert dlpWidth_read==dlpWidth_write
assert prevWidth_read==prevWidth_write
assert layerHeight_read==layerHeight_write
print("...success.")
print ("Test layerimage save to file...")
filepath0='/home/nard/PhotonFile/test/images/test0.png'
filepath4='/home/nard/PhotonFile/test/images/test4.png'
photonfile.layers.save(0,filepath0)
photonfile.layers.save(4,filepath4)
print("...success.")
print ("Test image insert to layer...")
filepath0='/home/nard/PhotonFile/test/images/test0.png'
filepath4='/home/nard/PhotonFile/test/images/test4.png'
photonfile.layers.insert(filepath4,4)
photonfile.layers.insert(filepath0,0)
assert photonfile.layers.count() == 1716+2
print("...success.")
print ("Test layer delete...")
photonfile.layers.delete(0)
photonfile.layers.delete(4)
assert photonfile.layers.count() == 1716
photonfile.save(filepath_new)
new_filesize=os.path.getsize(filepath_new)
assert new_filesize==org_filesize
print("...success.")
print ("Test image encoding...")
filepath = '/home/nard/PhotonFile/test/images/test.png'
filepath_new='/home/nard/PhotonFile/test/images/test2.png'
photonfile.layers.insert(filepath,4)
photonfile.layers.save(4,filepath_new)
org_imgfilesize=os.path.getsize(filepath)
org_imgobjsize=PIL.Image.open(filepath).size
new_imgfilesize=os.path.getsize(filepath_new)
new_imgobjsize=PIL.Image.open(filepath_new).size
assert(new_imgobjsize==org_imgobjsize)
assert(new_imgfilesize==org_imgfilesize)
print("...success.")
print ("Test layer replace layer with new image...")
photon_filepath_org='/home/nard/PhotonFile/test/bunny.photon'
photonfile.load(photon_filepath_org)
img_filepath4='/home/nard/PhotonFile/test/images/test4.png'
photonfile.layers.replace(4,img_filepath4)
assert photonfile.layers.count() == 1716
photon_filepath_new='/home/nard/PhotonFile/test/bunny2.photon'
photonfile.save(photon_filepath_new)
org_filesize=os.path.getsize(photon_filepath_org)
new_filesize=os.path.getsize(photon_filepath_new)
assert new_filesize==org_filesize
print("...success.")
print ("Test append photonfile with new image...")
photon_filepath_org='/home/nard/PhotonFile/test/bunny.photon'
photon_filepath_new='/home/nard/PhotonFile/test/bunny2.photon'
photonfile.load(photon_filepath_org)
img_filepath4='/home/nard/PhotonFile/test/images/test4.png'
photonfile.layers.append(img_filepath4)
photonfile.layers.delete(photonfile.layers.last())
photonfile.save(photon_filepath_new)
assert new_filesize==org_filesize
print("...success.")
print ("Save All...")
photon_filepath_org='/home/nard/PhotonFile/test/bunny.photon'
photonfile.load(photon_filepath_org)
photon_dirpath_new='/home/nard/PhotonFile/test/bunny.img'
photonfile.layers.saveAll(photon_dirpath_new)
print("...success.")
print ("get All...")
print("...success.")
print ("Save Replace...")
print("...success.")
print ("Test copy image (via clipboard)...")
print("...success.")
print ("Test cut/paste image (via clipboard)...")
print("...success.")
print ("Test undo (via clipboard)...")
print("...success.")
print ("Save Preview...")
print("...success.")
print ("Replace Preview...")
print("...success.")
return
#photonfile.exportBitmap(dirPath="/home/nard/PhotonFile/test",filepre="3DB_",layerNr=150)
#PhotonFile.encodeImageFile2RLE('test/test.png')
#bmpNp1D=photonfile.getBitmap2(layerNr=150)#,retNumpyArray=True)
#bmpNp1Duint8=bmpNp1D.flatten().astype(numpy.uint8)
#print (bmpNp1Duint8.dtype,bmpNp1Duint8.shape,)
#rle=RLE.encode8bImage2RLE(bmpNp1Duint8)
#Temp Commented for restruct
#bmpNp1Duint8=RLE.decodeRLE28bImage(rle)
#print (bmpNp1Duint8.dtype,bmpNp1Duint8.shape,)
#img2D=bmpNp1Duint8.reshape(1440,2560)
#im=PIL.Image.fromarray(img2D)
#im.save('test/out.png')
#mg=data.reshape(2560,1440,4)
# imgarr8=img[:,:,1]
# img1D=imgarr8.flatten(0)
#filename=os.path.abspath('')+"/"+sys.argv[1]
#filename=sys.argv[1]
def main():
testcases()
if __name__ == '__main__':
main()