-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_search_img.py
77 lines (49 loc) · 1.91 KB
/
test_search_img.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
"""
Simple unit test for search_img module
"""
import unittest
import os
import collections
from search_img import SearchImage
class TestSearchImage(unittest.TestCase):
""" Unit test class for SearchImage """
def test_index_create(self):
""" Remove and re-create all indixes from the location. """
search_img = SearchImage('test')
# Clear the location
os.system('rm -rf ' + search_img.save_path)
# Have to do this again to recreate paths
search_img = SearchImage('test')
index, status = search_img.index_image_files('testing/')
# To assert index was rebuilt
self.assertTrue(status == True)
# To assert index was valid
self.assertTrue(len(index)>0)
def test_index_reuse(self):
""" Reuse bulit index. """
search_img = SearchImage('test')
index, status = search_img.index_image_files('testing/')
# To assert index was loaded
self.assertTrue(status == False)
# To assert index was valid
self.assertTrue(len(index)>0)
def test_index_validity(self):
"""Specific file based testing for specific data."""
search_img = SearchImage('test')
index, status = search_img.index_image_files('testing/')
print type(index)
self.assertTrue(type(index) == collections.defaultdict)
item = index['testing/image/insta_pic.jpg']
# Test presence of a few keys
self.assertTrue('megapixels' in item)
self.assertTrue('image_height' in item)
item = index['testing/image/samsung.jpg']
self.assertTrue('g_p_s_longitude' in item)
print index.keys()
# Like this pick specific keys to specific files
# and write assertions
item = index['testing/image/filter_lenovo.jpg']
print item
self.assertTrue('model' in item)
if __name__ == "__main__":
unittest.main()