Skip to content

Commit

Permalink
Update qa tests with fixed cases (baidubce#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolvever authored and yinjiaqi committed Sep 4, 2024
1 parent fa28b9b commit f7751a1
Show file tree
Hide file tree
Showing 18 changed files with 231 additions and 1,558 deletions.
91 changes: 10 additions & 81 deletions appbuilder/tests/test_qa_aicape_animal_rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,93 +13,22 @@
# limitations under the License.

import unittest
import os
import appbuilder
import requests
from parameterized import parameterized, param
import appbuilder

from tests.pytest_config import LoadConfig
conf = LoadConfig()

from tests.pytest_utils import Utils
util = Utils()

from appbuilder.utils.logger_util import get_logger
log = get_logger(__name__)

image_url = "https://bj.bcebos.com/v1/appbuilder/animal_recognize_test.png?" \
"authorization=bce-auth-v1%2FALTAKGa8m4qCUasgoljdEDAzLm%2F2024-01-24T" \
"12%3A19%3A16Z%2F-1%2Fhost%2F411bad53034fa8f9c6edbe5c4909d76ecf6fad68" \
"62cf937c03f8c5260d51c6ae"
raw_image = requests.get(image_url).content

@unittest.skip("Open api request limit reached")
class TestAnimalRecognition(unittest.TestCase):
@parameterized.expand([
param(image_url, None, None),
param(image_url, None, 0),
param(image_url, float(120), None),
param(image_url, None, 1),
param(image_url, 120.5, 1),
param(image_url, float(12000), None),
])
def test_normal(self, image, timeout, retry):
self.normal_case_url(image, timeout, retry)


def normal_case_url(self, image, timeout, retry):
"""
正常用例
"""
# 创建动物识别组件实例

def test_run(self):
image_url = ("https://bj.bcebos.com/v1/appbuilder/animal_recognize_test.png?"
"authorization=bce-auth-v1%2FALTAKGa8m4qCUasgoljdEDAzLm%2F2024-01-24T"
"12%3A19%3A16Z%2F-1%2Fhost%2F411bad53034fa8f9c6edbe5c4909d76ecf6fad68"
"62cf937c03f8c5260d51c6ae")

animal_recognition = appbuilder.AnimalRecognition()
# 执行识别操作并获取结果
if timeout is None and retry is None:
out = animal_recognition.run(appbuilder.Message(content={"url": image}))
elif timeout is None:
out = animal_recognition.run(appbuilder.Message(content={"url": image}), retry=retry)
elif retry is None:
out = animal_recognition.run(appbuilder.Message(content={"url": image}), timeout=timeout)
else:
out = animal_recognition.run(appbuilder.Message(content={"url": image}), timeout=timeout, retry=retry)

@parameterized.expand([
# timeout为0
param(image_url, 0, 0, "ValueError", "timeout", 'but the timeout cannot be set to a value '
'less than or equal to 0.'),
# timeout为字符串
param(image_url, "a", 0, "appbuilder.core._exception.InvalidRequestArgumentError", "timeout",
'timeout must be float or tuple of float'),
# timeout为0.1,太短了
param(image_url, float(0.1), 0, "requests.exceptions.ReadTimeout", "timeout",
"Read timed out. (read timeout=0.1)"),
# retry为字符串
param(image_url, float(10), "a", "TypeError", "str", "'<' not supported between instances of"
" 'str' and 'int'"),
# image_url错误
param("https://bj.bcebos.com/v1/appbuilder/xxx", 12.5, 1,
"appbuilder.core._exception.AppBuilderServerException", "url",
"service_err_message=url format illegal"),
])
def test_abnormal(self, image, timeout, retry, err_type, err_param, err_msg):
self.abnormal_case(image, timeout, retry, err_type, err_param, err_msg)
out = animal_recognition.run(appbuilder.Message(content={"url": image_url}))

self.assertIn("熊猫", str(out.content))

def abnormal_case(self, image, timeout, retry, err_type, err_param, err_msg):
"""
异常用例
"""
try:
# 创建动物识别组件实例
animal_recognition = appbuilder.AnimalRecognition()
# 执行识别操作并获取结果
out = animal_recognition.run(appbuilder.Message(content={"url": image}), timeout=timeout, retry=retry)
log.info(out.content)
self.assertFalse(True, "未捕获到错误信息")
except Exception as e:
self.assertIsInstance(e, eval(err_type), "捕获的异常不是预期的类型 实际:{}, 预期:{}".format(e, err_type))
self.assertIn(err_param, str(e), "捕获的异常参数类型不正确, 预期 参数:{}, 实际:{}".format(err_param, str(e)))
self.assertIn(err_msg, str(e), "捕获的异常消息不正确, 预期:{}, 实际:{}".format(err_msg, str(e)))

if __name__ == '__main__':
unittest.main()
103 changes: 10 additions & 93 deletions appbuilder/tests/test_qa_aicape_doc_crop_enhance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,107 +13,24 @@
# limitations under the License.

import unittest
import os
import appbuilder
import requests
from parameterized import parameterized, param
import appbuilder

from tests.pytest_config import LoadConfig
conf = LoadConfig()

from tests.pytest_utils import Utils
util = Utils()

from appbuilder.utils.logger_util import get_logger
log = get_logger(__name__)

image_url = "https://bj.bcebos.com/v1/appbuilder/doc_enhance_test.png?" \
"authorization=bce-auth-v1%2FALTAKGa8m4qCUasgoljdEDAzLm%2F2024-01" \
"-24T12%3A51%3A09Z%2F-1%2Fhost%2F2020d2433da471b40dafa933d557a1e" \
"be8abf28df78010f865e45dfcd6dc3951"
raw_image = requests.get(image_url).content

@unittest.skip("Open api request limit reached")
class TestDocCropEnhance(unittest.TestCase):
@parameterized.expand([
param(image_url, 0, None, None),
param(image_url, 0, None, 0),
param(image_url, 0, float(120), None),
param(image_url, 0, None, 1),
param(image_url, 0, 120.5, 1),
param(image_url, 0, float(12000), None),
param(image_url, 0, float(12000), None),
param(image_url, 1, None, None),
param(image_url, 2, None, None),
param(image_url, 3, None, None),
param(image_url, "0", None, None),
param(image_url, "1", None, None),
param(image_url, "2", None, None),
param(image_url, "3", None, None),
])
def test_normal_case(self, image, enhance_type, timeout, retry):
"""
正常用例
"""
# 创建二维码识别组件实例

def test_run(self):
image_url = (
"https://bj.bcebos.com/v1/appbuilder/doc_enhance_test.png?"
"authorization=bce-auth-v1%2FALTAKGa8m4qCUasgoljdEDAzLm%2F2024-01"
"-24T12%3A51%3A09Z%2F-1%2Fhost%2F2020d2433da471b40dafa933d557a1e"
"be8abf28df78010f865e45dfcd6dc3951")
enhance_type = 0
doc_enhance = appbuilder.DocCropEnhance()
# 执行识别操作并获取结果
if timeout is None and retry is None:
out = doc_enhance.run(appbuilder.Message(content={"url": image}, enhance_type=enhance_type, ))
elif timeout is None:
out = doc_enhance.run(appbuilder.Message(content={"url": image}), enhance_type=enhance_type, retry=retry)
elif retry is None:
out = doc_enhance.run(appbuilder.Message(content={"url": image}), enhance_type=enhance_type,
timeout=timeout)
else:
out = doc_enhance.run(appbuilder.Message(content={"url": image}), enhance_type=enhance_type,
timeout=timeout, retry=retry)
out = doc_enhance.run(appbuilder.Message(content={"url": image_url}, enhance_type=enhance_type))

res = out.content
self.assertIsNotNone(res["image_processed"])
self.assertIsNotNone(res["points"])

@parameterized.expand([
# timeout为0
param(image_url, 0, 0, 0, "ValueError", "timeout",
'but the timeout cannot be set to a value '
'less than or equal to 0.'),
# timeout为字符串
param(image_url, 1, "a", 0, "appbuilder.core._exception.InvalidRequestArgumentError", "timeout",
'timeout must be float or tuple of float'),
# timeout为0.1,太短了
param(image_url, 2, float(0.1), 0, "requests.exceptions.ReadTimeout", "timeout",
"Read timed out. (read timeout=0.1)"),
# retry为字符串
param(image_url, 3, float(10), "a", "TypeError", "str", "'<' not supported between instances of"
" 'str' and 'int'"),
# image_url错误
param("https://bj.bcebos.com/v1/appbuilder/xxx", 0, 12.5, 1,
"appbuilder.core._exception.AppBuilderServerException", "url",
"service_err_message=url format illegal"),
# enhance_type 为非0, 1, 2, 3
param(image_url, 10, float(10), 0, "appbuilder.core._exception.InvalidRequestArgumentError",
"enhance_type", "enhance_type only support [0, 1, 2, 3]"),
param(image_url, " ", float(10), 0, "appbuilder.core._exception.InvalidRequestArgumentError",
"enhance_type", "enhance_type only support [0, 1, 2, 3]"),
])
def test_abnormal_case(self, image, enhance_type, timeout, retry, err_type, err_param, err_msg):
"""
异常用例
"""
try:
# 创建表格识别组件实例
doc_enhance = appbuilder.DocCropEnhance()
# 执行识别操作并获取结果
out = doc_enhance.run(appbuilder.Message(content={"url": image}), enhance_type=enhance_type,
timeout=timeout, retry=retry)
res = out.content
assert False, "未捕获到错误信息"
except Exception as e:
self.assertIsInstance(e, eval(err_type), "捕获的异常不是预期的类型 实际:{}, 预期:{}".format(e, err_type))
self.assertIn(err_param, str(e), "捕获的异常参数类型不正确, 实际:{}, 预期:{}".format(e, err_param))
self.assertIn(err_msg, str(e), "捕获的异常消息不正确, 实际:{}, 预期:{}".format(e, err_msg))


if __name__ == '__main__':
unittest.main()
89 changes: 10 additions & 79 deletions appbuilder/tests/test_qa_aicape_handwriting_ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,90 +13,21 @@
# limitations under the License.

import unittest
import os
import appbuilder
import requests
from parameterized import parameterized, param
import appbuilder

from tests.pytest_config import LoadConfig
conf = LoadConfig()

from tests.pytest_utils import Utils
util = Utils()

from appbuilder.utils.logger_util import get_logger
log = get_logger(__name__)

image_url=("https://bj.bcebos.com/v1/appbuilder/test_handwrite_ocr.jpg?authorization=bce-auth-v1%2FALTAKGa8m4qCUasgol"
"jdEDAzLm%2F2024-01-23T11%3A58%3A09Z%2F-1%2Fhost%2F677f93445fb65157bee11cd492ce213d5c56e7a41827e45ce7e32b0"
"83d195c8b")
raw_image = requests.get(image_url).content

@unittest.skip("Open api request limit reached")
class TestHandwritingOcr(unittest.TestCase):
@parameterized.expand([
param(image_url, None, None),
param(image_url, None, 0),
param(image_url, float(120), None),
param(image_url, None, 1),
param(image_url, 120.5, 1),
param(image_url, float(12000), None),
])
def test_normal_case(self, image, timeout, retry):
"""
正常用例
"""
# 创建表格识别组件实例
def test_run(self):
image_url=("https://bj.bcebos.com/v1/appbuilder/test_handwrite_ocr.jpg?"
"authorization=bce-auth-v1%2FALTAKGa8m4qCUasgoljdEDAzLm%2F2024-01-23T"
"11%3A58%3A09Z%2F-1%2Fhost%2F677f93445fb65157bee11cd492ce213d5c56e7a41827e45ce7e32b0"
"83d195c8b")

image = image_url
handwrite_ocr = appbuilder.HandwriteOCR()
# 执行识别操作并获取结果
if timeout is None and retry is None:
out = handwrite_ocr.run(appbuilder.Message(content={"url": image}))
elif timeout is None:
out = handwrite_ocr.run(appbuilder.Message(content={"url": image}), retry=retry)
elif retry is None:
out = handwrite_ocr.run(appbuilder.Message(content={"url": image}), timeout=timeout)
else:
out = handwrite_ocr.run(appbuilder.Message(content={"url": image}), timeout=timeout, retry=retry)
res = out.content
self.assertIsNotNone(res["contents"], "识别结果为空")
self.assertEqual(len(res["contents"]), 6)

out = handwrite_ocr.run(appbuilder.Message(content={"url": image}))

self.assertIn("我们家住的小区里有很多银杏树", str(out.content))

@parameterized.expand([
# timeout为0
param(image_url, 0, 0, "ValueError", "timeout", 'but the timeout cannot be set to a value '
'less than or equal to 0.'),
# timeout为字符串
param(image_url, "a", 0, "appbuilder.core._exception.InvalidRequestArgumentError", "timeout",
'timeout must be float or tuple of float'),
# timeout为0.1,太短了
param(image_url, float(0.1), 0, "requests.exceptions.ReadTimeout", "timeout",
"Read timed out. (read timeout=0.1)"),
# retry为字符串
param(image_url, float(10), "a", "TypeError", "str", "'<' not supported between instances of"
" 'str' and 'int'"),
# image_url错误
param("https://bj.bcebos.com/v1/appbuilder/xxx", 12.5, 1,
"appbuilder.core._exception.AppBuilderServerException", "url",
"service_err_message=url format illegal"),
])
def test_abnormal_case(self, image, timeout, retry, err_type, err_param, err_msg):
"""
异常用例
"""
try:
# 创建表格识别组件实例
handwrite_ocr = appbuilder.HandwriteOCR()
# 执行识别操作并获取结果
out = handwrite_ocr.run(appbuilder.Message(content={"url": image}), timeout=timeout, retry=retry)
res = out.content
log.info(res)
assert False, "未捕获到错误信息"
except Exception as e:
self.assertIsInstance(e, eval(err_type), "捕获的异常不是预期的类型 实际:{}, 预期:{}".format(e, err_type))
self.assertIn(err_param, str(e), "捕获的异常参数类型不正确, 预期 参数:{}, 实际:{}".format(err_param, str(e)))
self.assertIn(err_msg, str(e), "捕获的异常消息不正确, 预期:{}, 实际:{}".format(err_msg, str(e)))

if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit f7751a1

Please sign in to comment.