def test_en_simple(self): # Trigger reference-counting bug that was fixed in PyICU 1.0.1: # https://github.com/ovalhub/pyicu/commit/515e076682e29d806aeb5f6b1016b799d03d92a9 icu = get_icu() assert_not_equal(icu, None) t = list(word_break_iterator('eggs', icu.Locale('en'))) assert_equal(t, [4])
def test_en(self): icu = get_icu() assert_not_equal(icu, None) t = list(word_break_iterator(text, icu.Locale('en'))) s = [1, 7, 8, 9, 10, 15, 16, 24, 25, 26, 30, 31, 32, 33, 37, 38, 43, 44, 45, 46, 47, 48, 54, 55, 57, 58, 61, 62, 65, 66, 67] assert_equal(t, s) assert_equal(s[-1], len(text))
def test_help(): stdout = io.BytesIO() stderr = io.BytesIO() with interim(sys, stdout=stdout, stderr=stderr): rc = try_run(hocr2djvused.main, ['', '--help']) assert_equal(stderr.getvalue(), '') assert_equal(rc, 0) assert_not_equal(stdout.getvalue(), '')
def test_bad_options(): stdout = io.BytesIO() stderr = io.BytesIO() with interim(sys, stdout=stdout, stderr=stderr): rc = try_run(hocr2djvused.main, ['', '--bad-option']) assert_equal(rc, errors.EXIT_FATAL) assert_not_equal(stderr.getvalue(), '') assert_equal(stdout.getvalue(), '')
def _test_list_languages(engine): stdout = io.BytesIO() stderr = io.BytesIO() with interim(sys, stdout=stdout, stderr=stderr): rc = try_run(ocrodjvu.main, ['', '--engine', engine, '--list-languages']) assert_equal(stderr.getvalue(), '') assert_equal(rc, 0) assert_not_equal(stdout.getvalue(), '')
def test_help(): stdout = io.BytesIO() stderr = io.BytesIO() with interim(sys, stdout=stdout, stderr=stderr): rc = try_run(djvu2hocr.main, ['', '--help']) assert_equal(rc, 0) assert_equal(stderr.getvalue(), '') assert_not_equal(stdout.getvalue(), '')
def test_bad_options(): stdout = io.BytesIO() stderr = io.BytesIO() with interim(sys, stdout=stdout, stderr=stderr): rc = try_run(djvu2hocr.main, ['']) assert_equal(rc, errors.EXIT_FATAL) assert_not_equal(stderr.getvalue(), '') assert_equal(stdout.getvalue(), '')
def _test_list_languages(engine): stdout = io.BytesIO() stderr = io.BytesIO() with interim(sys, stdout=stdout, stderr=stderr): rc = try_run(ocrodjvu.main, ['', '--engine', engine, '--list-languages']) assert_equal(rc, 0) assert_equal(stderr.getvalue(), '') assert_not_equal(stdout.getvalue(), '')
def test_version(): # https://bugs.debian.org/573496 stdout = io.BytesIO() stderr = io.BytesIO() with interim(sys, stdout=stdout, stderr=stderr): rc = try_run(hocr2djvused.main, ['', '--version']) assert_equal(stderr.getvalue(), '') assert_equal(rc, 0) assert_not_equal(stdout.getvalue(), '')
def test_version(): # https://bugs.debian.org/573496 stdout = io.BytesIO() stderr = io.BytesIO() with interim(sys, stdout=stdout, stderr=stderr): rc = try_run(djvu2hocr.main, ['', '--version']) assert_equal(rc, 0) assert_equal(stderr.getvalue(), '') assert_not_equal(stdout.getvalue(), '')
def _rough_test_from_file(base_filename, args): args = ['#'] + shlex.split(args) if base_filename.endswith(('cuneiform0.7', 'cuneiform0.8')): # Add dummy page-size information args += ['--page-size=1000x1000'] base_filename = os.path.join(here, base_filename) html_filename = '{base}.html'.format(base=base_filename) with contextlib.closing(io.BytesIO()) as output_file: with open(html_filename, 'rb') as html_file: with interim(sys, stdin=html_file, stdout=output_file): rc = try_run(hocr2djvused.main, args) assert_equal(rc, 0) output = output_file.getvalue() assert_not_equal(output, '')
def test_nonascii_path(): require_locale_encoding('UTF-8') # djvused breaks otherwise remove_logging_handlers('ocrodjvu.') here = os.path.dirname(__file__) here = os.path.abspath(here) path = os.path.join(here, '..', 'data', 'empty.djvu') stdout = io.BytesIO() stderr = io.BytesIO() with temporary.directory() as tmpdir: tmp_path = os.path.join(tmpdir, 'тмп.djvu') os.symlink(path, tmp_path) with interim(sys, stdout=stdout, stderr=stderr): rc = try_run(djvu2hocr.main, ['', tmp_path]) assert_equal(stderr.getvalue(), '') assert_equal(rc, 0) assert_not_equal(stdout.getvalue(), '')
def test_en_empty(self): icu = get_icu() assert_not_equal(icu, None) t = list(word_break_iterator('', icu.Locale('en'))) assert_equal(t, [])