Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Python Tests #83

Merged
merged 1 commit into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 28 additions & 40 deletions tests/python/TestBoundingBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,10 @@
# THE SOFTWARE.
#

from threading import Thread
import sys
import os
import urllib
import time
import json
import unittest
import numpy as np
import vdms

hostname = "localhost"
port = 55557

class TestBoundingBox(unittest.TestCase):
import TestCommand

class TestBoundingBox(TestCommand.TestCommand):

@classmethod
def setUpClass(self):
self.number_of_inserts = 2
Expand Down Expand Up @@ -113,8 +103,8 @@ def addBoundingBoxwithImage(self, db, numBoxes, imgprops=None):
self.assertEqual(response[i+1]["AddBoundingBox"]["status"], 0)

def test_addBoundingBox(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

all_queries = []

Expand Down Expand Up @@ -144,8 +134,8 @@ def test_addBoundingBox(self):
self.assertEqual(response[i]["AddBoundingBox"]["status"], 0)

def test_findBoundingBox(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

prefix_name = "find_my_bb_"

Expand Down Expand Up @@ -180,8 +170,8 @@ def test_findBoundingBox(self):
self.assertEqual(response[1]["FindBoundingBox"]["entities"][0]["name"], prefix_name + "1")

def test_findBoundingBoxCoordinates(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

prefix_name = "find_my_bb_coords_"

Expand Down Expand Up @@ -218,8 +208,8 @@ def test_findBoundingBoxCoordinates(self):
self.assertEqual(response[i]["FindBoundingBox"]["entities"][0]["_coordinates"]["h"], 100)

def test_addBoundingBoxWithImage(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

all_queries = []
imgs_arr = []
Expand Down Expand Up @@ -265,8 +255,8 @@ def test_addBoundingBoxWithImage(self):
self.assertEqual(response[1]["AddBoundingBox"]["status"], 0)

def test_findBoundingBoxesInImage(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

img_name = "my_brain_multiple"
imgprops = {}
Expand Down Expand Up @@ -312,8 +302,8 @@ def test_findBoundingBoxesInImage(self):


def test_findBoundingBoxByCoordinates(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

all_queries = []

Expand All @@ -340,15 +330,14 @@ def test_findBoundingBoxByCoordinates(self):
self.assertEqual(response[0]["FindBoundingBox"]["status"], 0)

def test_findBoundingBoxBlob(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

prefix_name = "my_brain_return_"
all_queries = []

for i in range(0, self.number_of_inserts):
db = vdms.vdms()
db.connect(hostname, port)
db = self.create_connection()

img_name = prefix_name + str(i)
imgprops = {}
Expand Down Expand Up @@ -381,15 +370,14 @@ def test_findBoundingBoxBlob(self):
self.assertEqual(response[i]["FindBoundingBox"]["entities"][0]["name"], prefix_name + str(i) + "_bb_0")

def test_findBoundingBoxBlobComplex(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

prefix_name = "my_brain_complex_"
all_queries = []

for i in range(0, self.number_of_inserts):
db = vdms.vdms()
db.connect(hostname, port)
db = self.create_connection()

img_name = prefix_name + str(i)
imgprops = {}
Expand Down Expand Up @@ -425,8 +413,8 @@ def test_findBoundingBoxBlobComplex(self):
self.assertIn(test, response[0]["FindBoundingBox"]["entities"])

def test_updateBoundingBox(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

prefix_name = "update_bb_"

Expand Down Expand Up @@ -473,14 +461,14 @@ def test_updateBoundingBox(self):

all_queries.append(query)

response, img_array = db.query(all_queries)
response, img_array = db.query(all_queries)

self.assertEqual(response[0]["FindBoundingBox"]["status"], 0)
self.assertEqual(response[0]["FindBoundingBox"]["entities"][0]["name"], "updated_bb_0")

def test_updateBoundingBoxCoords(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

prefix_name = "update_bb_"

Expand Down Expand Up @@ -530,7 +518,7 @@ def test_updateBoundingBoxCoords(self):

all_queries.append(query)

response, img_array = db.query(all_queries)
response, img_array = db.query(all_queries)

self.assertEqual(response[0]["FindBoundingBox"]["status"], 0)
self.assertEqual(response[0]["FindBoundingBox"]["entities"][0]["_coordinates"]["x"], 15)
Expand Down
87 changes: 87 additions & 0 deletions tests/python/TestCommand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#
# The MIT License
#
# @copyright Copyright (c) 2017 Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

import sys
import os
import urllib
import time
import json
import unittest
import vdms

class TestCommand(unittest.TestCase):

def __init__(self, *args, **kwargs):
super(TestCommand, self).__init__(*args, **kwargs)

# VDMS Server Info
self.hostname = "localhost"
self.port = 55557

def create_connection(self):

db = vdms.vdms()
db.connect(self.hostname, self.port)

return db

def addEntity(self, class_name, properties=None,
constraints=None,
blob = False, # Generic blob
check_status=True):

addEntity = {}
addEntity["class"] = class_name

if properties != None:
addEntity["properties"] = properties
if constraints != None:
addEntity["constraints"] = constraints

query = {}
query["AddEntity"] = addEntity

all_queries = []
all_queries.append(query)

db = self.create_connection()

if not blob:
response, res_arr = db.query(all_queries)
else:
blob_arr = []
fd = open("../test_images/brain.png", 'rb')
blob_arr.append(fd.read())
fd.close()

addEntity["blob"] = True

response, res_arr = db.query(all_queries, [blob_arr])

if check_status:
self.assertEqual(response[0]["AddEntity"]["status"], 0)

return response, res_arr
71 changes: 43 additions & 28 deletions tests/python/TestDescriptors.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
from threading import Thread
import sys
import os
import urllib
import time
import json
import unittest
#
# The MIT License
#
# @copyright Copyright (c) 2017 Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

import TestCommand
import numpy as np
import vdms # Yeah, baby

hostname = "localhost"
port = 55557

class TestDescriptors(unittest.TestCase):
class TestDescriptors(TestCommand.TestCommand):

def addSet(self, name, dim, metric, engine):

db = vdms.vdms()
db.connect(hostname, port)
db = self.create_connection()

all_queries = []

Expand All @@ -37,8 +52,8 @@ def addSet(self, name, dim, metric, engine):
self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0)

def test_addSet(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

all_queries = []

Expand Down Expand Up @@ -72,8 +87,8 @@ def test_addDifferentSets(self):
self.addSet("4075-L2-TileDBDense", 4075, "L2", "TileDBDense")

def test_addSetAndDescriptors(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

all_queries = []

Expand Down Expand Up @@ -116,8 +131,8 @@ def test_addSetAndDescriptors(self):
self.assertEqual(response[0]["AddDescriptor"]["status"], 0)

def test_addDescriptorsx1000(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

all_queries = []

Expand Down Expand Up @@ -163,8 +178,8 @@ def test_addDescriptorsx1000(self):
self.assertEqual(response[x]["AddDescriptor"]["status"], 0)

def test_addDescriptorsx1000FaissIVFFlat(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

all_queries = []

Expand Down Expand Up @@ -213,8 +228,8 @@ def test_addDescriptorsx1000FaissIVFFlat(self):


def test_addDescriptorsx1000TileDBSparse(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

all_queries = []

Expand Down Expand Up @@ -262,8 +277,8 @@ def test_addDescriptorsx1000TileDBSparse(self):
self.assertEqual(response[x]["AddDescriptor"]["status"], 0)

def test_addDescriptorsx1000TileDBDense(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

all_queries = []

Expand Down Expand Up @@ -312,8 +327,8 @@ def test_addDescriptorsx1000TileDBDense(self):
self.assertEqual(response[x]["AddDescriptor"]["status"], 0)

def test_classifyDescriptor(self):
db = vdms.vdms()
db.connect(hostname, port)

db = self.create_connection()

all_queries = []

Expand Down
Loading