def testSubsituteNonExistChar(self): tokens = ['AAAAA', 'KKKKK'] aug = OcrAug() for t in tokens: augmented_text = aug.augment(t) self.assertEqual(t, augmented_text) self.assertTrue(len(tokens) > 0)
def test_ocr_single_word(self): texts = ['Zoology', 'roku123456'] aug = OcrAug() for text in texts: augmented_text = aug.augment(text) self.assertNotEqual(text, augmented_text) self.assertTrue(len(texts) > 0)
def testSubsituteExistChar(self): tokens = ['Zoology', 'roku123456'] aug = OcrAug() for t in tokens: augmented_text = aug.augment(t) self.assertNotEqual(t, augmented_text) self.assertTrue(len(tokens) > 0)
def test_ocr_single_word_nonexist_char(self): texts = ['AAAAA', 'KKKKK'] aug = OcrAug() for text in texts: augmented_text = aug.augment(text) self.assertEqual(text, augmented_text) self.assertTrue(len(texts) > 0)
def test_empty_input(self): # Empty input tokens = [''] aug = OcrAug() for t in tokens: augmented_text = aug.augment(t) self.assertEqual(augmented_text, '') self.assertEqual(len(tokens[0]), 0) self.assertTrue(len(tokens) > 0) tokens = [None] aug = OcrAug() for t in tokens: augmented_text = aug.augment(t) self.assertEqual(augmented_text, None) self.assertEqual(len(tokens), 1)
def test_ocr_model_from_json(self): sample_path = os.path.abspath( os.path.join(os.path.dirname(__file__), '..', '..', 'res', 'common', 'sample.json')) aug = OcrAug(dict_of_path=sample_path) augmented_text = aug.augment('0000000') self.assertIn('3', augmented_text) with self.assertRaises(Exception) as error: sample_path = os.path.abspath( os.path.join(os.path.dirname(__file__), '..', '..', 'res', 'common', 'non_exist.json')) aug = OcrAug(dict_of_path=sample_path) self.assertIn('The dict_of_path does not exist', str(error.exception))
def test_ocr_multi_words(self): texts = ['The quick brown fox jumps over the lazy dog'] aug = OcrAug() for text in texts: # Since non-exist mapping word may be drawn, try several times is_augmented = False for _ in range(10): augmented_text = aug.augment(text) is_equal = text == augmented_text if not is_equal: is_augmented = True break self.assertTrue(is_augmented) self.assertTrue(len(texts) > 0)
def test_ocr_model_from_dict(self): mapping = {'0': ['2']} aug = OcrAug(dict_of_path=mapping) augmented_text = aug.augment('0000000') self.assertIn('2', augmented_text)
def test_ocr_empty(self): texts = ['', None] aug = OcrAug() for text in texts: augmented_text = aug.augment(text) self.assertEqual(text, augmented_text)