forked from LovisaLugnegard/exjobb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_functions_unittest.py
More file actions
80 lines (64 loc) · 3.09 KB
/
test_functions_unittest.py
File metadata and controls
80 lines (64 loc) · 3.09 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
import unittest
import cv2
import numpy as np
from PIL import Image
from skimage import img_as_uint
from skimage.measure import block_reduce
# import simulator
# import simulatorNoFlask
import profiling
class TestGetFiles(unittest.TestCase):
"""Tests for get_files"""
# def test_block_reduce_function(self):
# assert(os.path.isfile('D:\\Bibliotek\Documents\Exjobb\Bilder - 20171019T090142Z-001\Bilder/AssayPlate_NUNC_#165305-1_B02_T0001F001L01A01Z01C02.tif'))
# img = cv2.imread(
# 'D:\\Bibliotek\Documents\Exjobb\Bilder - 20171019T090142Z-001\Bilder/AssayPlate_NUNC_#165305'
# '-1_B02_T0001F001L01A01Z01C02.tif', -1)
# binned_img = block_reduce(img, block_size=(1, 1), func=np.sum)
# np.array_equal(img, binned_img)
def test_get_files(self):
file_path = "D:\Bibliotek\Documents\Exjobb\Bilder-20171019T090142Z-001\Bilder"
# file_path = "/mnt/volume/fromAl/Data_20151215 HepG2 LNP size exp live cell 24h_20151215_110422/AssayPlate_NUNC_#165305-1/"
frequency = 1
binning = 2
color_channel = [1]
connect_kafka = "No"
profiling.time_get_files(file_path, frequency, binning, color_channel, connect_kafka)
def test_test_timeit(self):
profiling.timer('test.json')
def test_save_img(self):
# in producer
imgfile = cv2.imread(
"D:\\Bibliotek\\Documents\\Exjobb\\Bilder-20171019T090142Z-001\\Bilder/AssayPlate_NUNC_#165305-1_B02_T0001F001L01A01Z01C02.tif",
-1)
print("type imgfile: {}".format(type(imgfile)))
print("imgfile size: {}".format(imgfile.shape))
binned_img = block_reduce(imgfile, block_size=(1, 1), func=np.sum)
print("binned_img type: {}".format(type(binned_img)))
print("binned_img size: {}".format(binned_img.shape))
ret, jpeg = cv2.imencode('.tif', img_as_uint(binned_img))
print("jpeg type: {}".format(type(jpeg)))
print("jpeg size: {}".format(jpeg.shape))
img_bytes = jpeg.tobytes()
print("img_bytes type: {}".format(type(img_bytes)))
# in consumer
img = cv2.imdecode(np.frombuffer(img_bytes, dtype=np.uint16), -1)
print("type img : {}".format(type(img)))
print("size img: {}".format(img.shape))
fin2 = Image.fromarray(img)
print("fin2 type: {}".format(type(fin2)))
fin2.save("fin22.tif")
assert (np.array_equal(img, imgfile))
def test_simulator_get_files(self):
file_path = '/mnt/volume/fromAl/Data_20151215 HepG2 LNP size exp live cell 24h_20151215_110422/AssayPlate_NUNC_#165305-1/'
frequency = 1
binning = 1
color_channel = ['1', '2', '3']
connect_kafka = 'yes'
simulator.get_files(file_path, frequency, binning, color_channel, connect_kafka)
# def test_create_test_data(self):
# create_test_data.create_test_images("C:\\Users\Lovisa\exjobb\\testData/", 3)
# print(os.path.getsize("testData\AssayPlate_NUNC_#165305-1_B02_T0001F001L01A01Z01C02.tif"))
# print(os.path.getsize("bild.tif"))
if __name__ == '__main__':
unittest.main()