示例#1
0
 def send_file_curl(self, file_name):
     post_cmd = 'curl -F "image=@{}" -XPOST {}'.format(
         lfile(file_name), self.url)
     proc = os.popen(post_cmd)
     out = json.loads(proc.read())
     proc.close()
     return out
示例#2
0
    def test_text_file_example(self):

        f1 = open(lfile('test_text2.txt'), 'rb')
        files = {'doc': ('test_text2.txt', f1)}
        r = requests.post(self.url + '?threshold=0.1', files=files)
        f1.close()
        out = r.json()

        self.assertTrue('text' in out.keys())

        self.assertTrue('variables' in out.keys())

        self.assertTrue('threshold' in out['variables'].keys())

        with open(lfile('test_text2.txt'), "r") as f:
            t = f.read()
            f.close()

        self.assertTrue(out['text'] == t)
    def test_from_file_png(self):
        f = open(lfile('./example_qr_code.png'), 'rb')
        files = {'image': ('example_qr_code.png', f)}

        r = requests.post(self.url + '?threshold=0.5', files=files)
        f.close()
        out = r.json()

        self.assertTrue('text' in out.keys())

        self.assertTrue('variables' in out.keys())

        self.assertTrue('shape' in out.keys())

        self.assertTrue(out['text'] == "Example image")
示例#4
0
    def test_text_from_server(self):

        out = self.send_json({
            "contentUrl": self.file_url('test_text3.txt'),
            "clean_text": 0
        })

        self.assertTrue('text' in out.keys())
        self.assertTrue('variables' in out.keys())

        with open(lfile('test_text3.txt'), "r") as f:
            t = f.read()
            f.close()

        self.assertTrue(out['text'] == t)
示例#5
0
    def test_from_file_xlsx(self):
        f = open(lfile('./example.xlsx'), 'rb')
        files = {'xlsx': ('./example.xlsx', f)}

        r = requests.post(self.url + '?threshold=0.5', files=files)
        f.close()
        out = r.json()

        self.assertTrue('text' in out.keys())

        self.assertTrue('variables' in out.keys())

        self.assertTrue('shape' in out.keys())

        self.assertTrue(out['shape'] == [2, 3])
    def test_from_file_bmp(self):

        with open(lfile('./example_qr_code.bmp'), 'rb') as f:
            files = {'image': ('./example_qr_code.bmp', f)}

            r = requests.post(self.url + '?threshold=0.5', files=files)

            out = r.json()

            self.assertTrue('text' in out.keys())

            self.assertTrue('variables' in out.keys())

            self.assertTrue('shape' in out.keys())

            self.assertTrue(out['text'] == "Example image")