def test_LogSetLevel(self): not_set_msg = "NOT SET" self._msg = not_set_msg msg = "Hello, world" self._log.set_log_level(modelbox.Log.Level.ERROR) modelbox.info(msg) self.assertNotEqual(msg, self._msg) self.assertEqual(not_set_msg, self._msg)
def test_flow_for_buffer(self): conf_file = test_config.TEST_DATA_DIR + "/py_op_config.toml" driver_dir = test_config.TEST_DRIVER_DIR with open(conf_file, "w") as out: txt = r""" [driver] dir=["{}", "{}"] skip-default=true [log] level="INFO" [graph] graphconf = '''digraph demo {{ input1[type=input] python_buffer[type=flowunit, flowunit=python_buffer, device=cpu, deviceid=0, label="<buffer_in> | <buffer_out>", buffer_config = 0.2] output1[type=output] input1 -> python_buffer:buffer_in python_buffer:buffer_out -> output1 }}''' format = "graphviz" """.format(driver_dir, test_config.TEST_DATA_DIR + "/python_op") out.write(txt) conf = modelbox.Configuration() flow = modelbox.Flow() ret = flow.init(conf_file) os.remove(conf_file) if ret == False: modelbox.error(ret) self.assertTrue(ret) ret = flow.build() self.assertTrue(ret) ret = flow.run_async() self.assertTrue(ret) img = cv2.imread(test_config.TEST_SOURCE_DIR + "/../src/python/test/data/liu-x-160.jpg") img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) with Image.open(test_config.TEST_SOURCE_DIR + "/../src/python/test/data/liu-x-160.jpg") as img: img_np = np.array(img) extern_data_map = flow.create_external_data_map() buffer_list = extern_data_map.create_buffer_list() buffer_list.push_back(img_np) extern_data_map.send("input1", buffer_list) extern_data_map.shutdown() buffer_list_map = modelbox.ExtOutputBufferList() ret = extern_data_map.recv(buffer_list_map) self.assertTrue(ret) result_buffer_list = buffer_list_map.get_buffer_list("output1") for i in range(result_buffer_list.size()): buffer = result_buffer_list[i] np_image = np.array(buffer, copy= False) image = Image.fromarray(np_image) with Image.open(test_config.TEST_SOURCE_DIR + "/../src/python/test/data/liu-x-160.jpg") as check_image: try: check_image_np = np.array(check_image) diff = ImageChops.difference(image, Image.fromarray(check_image_np)) self.assertEqual(diff.getbbox(), None) except ValueError as e: flow.stop() self.assertTrue(False) data_type = buffer.get("type") if data_type != modelbox.Buffer.ModelBoxDataType.UINT8: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid type") float_test = buffer.get("float_test") if float_test != 0.5: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid float test") string_test = buffer.get("string_test") if string_test != "TEST": return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid string test") int_test = buffer.get("int_test") if int_test != 100: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid int test") bool_test = buffer.get("bool_test") if bool_test != False: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid bool test") int_list = buffer.get("list_int_test") if int_list != [1, 1, 1]: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid int list") float_list = buffer.get("list_float_test") if float_list != [0.1, 0.2, 0.3]: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid float list") bool_list = buffer.get("list_bool_test") if bool_list != [False, False, True]: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid bool list") string_list = buffer.get("list_string_test") if string_list != ["TEST1", "TEST2", "TEST3"]: return modelbox.Status(modelbox.Status.StatusCode.STATUS_SHUTDOWN, "invalid string list") try: dict_test = buffer.get("map_test") except ValueError as err: modelbox.info(str(err)) else: flow.stop() self.assertTrue(False) flow.stop()
def threadtest(self, index, loop): for i in range(loop): modelbox.info("loop" + str(index) + ": " + str(i))
def test_LogDefaultNoOutput(self): msg = "Hello, world" modelbox.info(msg)
def test_LogPrint(self): msg = "Hello, world" modelbox.info(msg) self.assertEqual(msg, self._msg)