def test_captcha_success_save(self): captcha_solver = CaptchaSolver(None) test_img = cv2.imread(os.path.join(os.getcwd(), 'test_ocr_valid.png')) captcha_solver.solve_captcha(test_img) captcha_solver.notify_last_captcha_success() assert os.path.exists(os.path.join(os.getcwd(), 'captcha', 'correct', '12+3=.png')) os.remove(os.path.join(os.getcwd(), 'captcha', 'correct', '12+3=.png'))
def test_captcha_success_save(self, tmpdir, testdatadir): td = tmpdir.mkdir('captcha') captcha_solver = CaptchaSolver(None, outdir=td) test_img = cv2.imread(testdatadir.join('test_ocr_valid.png').strpath) captcha_solver.solve_captcha(test_img) captcha_solver.notify_last_captcha_success() assert os.path.exists(tmpdir.join('captcha', 'correct', '12+3=.png'))
def test_first_second_separation_invalid(self): # Tests the case where only 2 out of 3 digits are read by OCR. Should return 0. captcha_solver = CaptchaSolver(None) test_img = cv2.imread(os.path.join(os.getcwd(), 'test_ocr_invalid.png')) assert captcha_solver.solve_captcha(test_img) == 0 assert captcha_solver.first_number is None assert captcha_solver.second_number is None
def test_first_second_separation(self): # Tests correct separation of first_number (first 2 digits) and second_number (last digit) captcha_solver = CaptchaSolver(None) test_img = cv2.imread(os.path.join(os.getcwd(), 'test_ocr_valid.png')) assert captcha_solver.solve_captcha(test_img) == 15 assert captcha_solver.first_number == 12 assert captcha_solver.second_number == 3
def test_first_second_separation_invalid(self, tmpdir, testdatadir): # Tests the case where only 2 out of 3 digits are read by OCR. Should return 0. td = tmpdir.mkdir('captcha') captcha_solver = CaptchaSolver(None, outdir=td) test_img = cv2.imread(testdatadir.join('test_ocr_invalid.png').strpath) assert captcha_solver.solve_captcha(test_img) == 0 assert captcha_solver.first_number is None assert captcha_solver.second_number is None
def test_first_second_separation(self, tmpdir, testdatadir): # Tests correct separation of first_number (first 2 digits) and second_number (last digit) td = tmpdir.mkdir('captcha') captcha_solver = CaptchaSolver(None, outdir=td) test_img = cv2.imread(testdatadir.join('test_ocr_valid.png').strpath) assert captcha_solver.solve_captcha(test_img) == 15 assert captcha_solver.first_number == 12 assert captcha_solver.second_number == 3