<s> import pypdfocr . pypdfocr_tesseract as P <EOL> import pytest <EOL> import os <EOL> import hashlib <EOL> from mock import patch , call <EOL> class TestTesseract : <EOL> @ pytest . mark . skipif ( os . name == '<STR_LIT>' , reason = '<STR_LIT>' ) <EOL> def test_version_shorter_older ( self ) : <EOL> with patch ( "<STR_LIT>" ) as mock_subprocess : <EOL> p = P . PyTesseract ( { } ) <EOL> p . required = "<STR_LIT>" <EOL> mock_subprocess . return_value = """<STR_LIT>""" <EOL> uptodate , ver = p . _is_version_uptodate ( ) <EOL> assert ( not uptodate ) <EOL> def test_version_minor_older ( self ) : <EOL> with patch ( "<STR_LIT>" ) as mock_subprocess : <EOL> p = P . PyTesseract ( { } ) <EOL> p . required = "<STR_LIT>" <EOL> mock_subprocess . return_value = """<STR_LIT>""" <EOL> uptodate , ver = p . _is_version_uptodate ( ) <EOL> assert ( not uptodate ) <EOL> def test_version_major_older ( self ) : <EOL> with patch ( "<STR_LIT>" ) as mock_subprocess : <EOL> p = P . PyTesseract ( { } ) <EOL> p . required = "<STR_LIT>" <EOL> mock_subprocess . return_value = """<STR_LIT>""" <EOL> uptodate , ver = p . _is_version_uptodate ( ) <EOL> assert ( not uptodate ) <EOL> @ pytest . mark . skipif ( os . name == '<STR_LIT>' , reason = '<STR_LIT>' ) <EOL> def test_version_major_equal ( self ) : <EOL> with patch ( "<STR_LIT>" ) as mock_subprocess : <EOL> p = P . PyTesseract ( { } ) <EOL> p . required = "<STR_LIT>" <EOL> mock_subprocess . return_value = """<STR_LIT>""" <EOL> uptodate , ver = p . _is_version_uptodate ( ) <EOL> assert ( uptodate ) <EOL> def test_version_major_newer ( self ) : <EOL> with patch ( "<STR_LIT>" ) as mock_subprocess : <EOL> p = P . PyTesseract ( { } ) <EOL> p . required = "<STR_LIT>" <EOL> mock_subprocess . return_value = """<STR_LIT>""" <EOL> uptodate , ver = p . _is_version_uptodate ( ) <EOL> assert ( uptodate ) <EOL> def test_version_minor_newer ( self ) : <EOL> with patch ( "<STR_LIT>" ) as mock_subprocess : <EOL> p = P . PyTesseract ( { } ) <EOL> p . required = "<STR_LIT>" <EOL> mock_subprocess . return_value = """<STR_LIT>""" <EOL> uptodate , ver = p . _is_version_uptodate ( ) <EOL> assert ( uptodate ) <EOL> def test_tesseract_presence ( self , capsys ) : <EOL> p = P . PyTesseract ( { } ) <EOL> p . binary = "<STR_LIT>" <EOL> with pytest . raises ( SystemExit ) : <EOL> p . _is_version_uptodate ( ) <EOL> out , err = capsys . readouterr ( ) <EOL> assert p . msgs [ '<STR_LIT>' ] in out <EOL> def test_tesseract_version ( self , capsys ) : <EOL> p = P . PyTesseract ( { } ) <EOL> p . required = "<STR_LIT:100>" <EOL> with pytest . raises ( SystemExit ) : <EOL> p . make_hocr_from_pnms ( "<STR_LIT>" ) <EOL> out , err = capsys . readouterr ( ) <EOL> assert p . msgs [ '<STR_LIT>' ] in out <EOL> def test_tiff_file_check ( self , capsys ) : <EOL> p = P . PyTesseract ( { } ) <EOL> with pytest . raises ( SystemExit ) : <EOL> p . make_hocr_from_pnm ( "<STR_LIT>" ) <EOL> out , err = capsys . readouterr ( ) <EOL> assert p . msgs [ '<STR_LIT>' ] in out <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_tesseract_version_nt ( self , mock_subprocess , mock_os_name ) : <EOL> """<STR_LIT>""" <EOL> mock_os_name . __str__ . return_value = '<STR_LIT>' <EOL> p = P . PyTesseract ( { } ) <EOL> p . required = "<STR_LIT>" <EOL> mock_subprocess . return_value = """<STR_LIT>""" <EOL> uptodate , ver = p . _is_version_uptodate ( ) <EOL> assert ( uptodate ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_force_Nt ( self , mock_os_path_exists , mock_os_name , mock_uptodate , capsys ) : <EOL> mock_os_name . __str__ . return_value = '<STR_LIT>' <EOL> p = P . PyTesseract ( { } ) <EOL> assert ( '<STR_LIT>' in p . binary ) <EOL> mock_os_path_exists . return_value = True <EOL> mock_uptodate . return_value = ( True , "<STR_LIT>" ) <EOL> p . binary = "<STR_LIT>" <EOL> print ( "<STR_LIT>" ) <EOL> with pytest . raises ( SystemExit ) : <EOL> p . make_hocr_from_pnm ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_tesseract_fail ( self , mock_os_path_exists , mock_os_name , mock_uptodate , mock_subprocess_call , capsys ) : <EOL> """<STR_LIT>""" <EOL> mock_os_name . __str__ . return_value = '<STR_LIT>' <EOL> p = P . PyTesseract ( { } ) <EOL> assert ( '<STR_LIT>' in p . binary ) <EOL> mock_os_path_exists . return_value = True <EOL> mock_uptodate . return_value = ( True , "<STR_LIT>" ) <EOL> mock_subprocess_call . return_value = - <NUM_LIT:1> <EOL> with pytest . raises ( SystemExit ) : <EOL> p . make_hocr_from_pnm ( '<STR_LIT>' ) <EOL> out , err = capsys . readouterr ( ) <EOL> assert p . msgs [ '<STR_LIT>' ] in out </s>
