MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / test_command_line

Method test_command_line

test_openocr.py:194–329  ·  view source on GitHub ↗

Test OpenOCR using command-line interface

(self)

Source from the content-addressed store, hash-verified

192 logger.info('=' * 80)
193
194 def test_command_line(self):
195 """Test OpenOCR using command-line interface"""
196 logger.info('\n' + '=' * 80)
197 logger.info('💻 Testing Command-Line Interface')
198 logger.info('=' * 80)
199
200 # Test 1: Detection task
201 logger.info('\n[Test 1/4] Testing Detection Command...')
202 try:
203 test_img = self.get_test_image(self.ocr_images)
204 if test_img:
205 output_path = self.output_dir / 'cli_det'
206 cmd = [
207 sys.executable, 'openocr.py',
208 '--task', 'det',
209 '--input_path', test_img,
210 '--output_path', str(output_path),
211 '--is_vis'
212 ]
213 logger.info(f"Running: {' '.join(cmd)}")
214 result = subprocess.run(cmd, cwd=__dir__, capture_output=True, text=True)
215 if result.returncode == 0:
216 logger.info('✅ Detection CLI: Success')
217 else:
218 logger.error(f'❌ Detection CLI failed: {result.stderr}')
219 else:
220 logger.warning('⚠️ Detection CLI: No test image available')
221 except Exception as e:
222 logger.error(f'❌ Detection CLI failed: {e}')
223
224 # Test 2: Recognition task
225 logger.info('\n[Test 2/4] Testing Recognition Command...')
226 try:
227 test_img = self.get_test_image(self.rec_images)
228 if not test_img:
229 test_img = self.get_test_image(self.ocr_images)
230
231 if test_img:
232 output_path = self.output_dir / 'cli_rec'
233 cmd = [
234 sys.executable, 'openocr.py',
235 '--task', 'rec',
236 '--input_path', test_img,
237 '--output_path', str(output_path),
238 '--mode', 'mobile'
239 ]
240 logger.info(f"Running: {' '.join(cmd)}")
241 result = subprocess.run(cmd, cwd=__dir__, capture_output=True, text=True)
242 if result.returncode == 0:
243 logger.info('✅ Recognition CLI: Success')
244 else:
245 logger.error(f'❌ Recognition CLI failed: {result.stderr}')
246 else:
247 logger.warning('⚠️ Recognition CLI: No test image available')
248 except Exception as e:
249 logger.error(f'❌ Recognition CLI failed: {e}')
250
251 # Test 3: OCR task

Callers 2

run_all_testsMethod · 0.95
mainFunction · 0.95

Calls 2

get_test_imageMethod · 0.95
runMethod · 0.80

Tested by

no test coverage detected