<s> import os <EOL> import platform <EOL> import subprocess <EOL> from topaz . main import _entry_point <EOL> class TestMain ( object ) : <EOL> def run ( self , space , tmpdir , source = None , status = <NUM_LIT:0> , ruby_args = [ ] , argv = [ ] ) : <EOL> args = [ "<STR_LIT>" ] <EOL> args += ruby_args <EOL> if source is not None : <EOL> f = tmpdir . join ( "<STR_LIT>" ) <EOL> f . write ( source ) <EOL> args . append ( str ( f ) ) <EOL> else : <EOL> f = None <EOL> args += argv <EOL> res = _entry_point ( space , args ) <EOL> assert res == status <EOL> return f <EOL> def assert_traceback ( self , space , tmpdir , capfd , src , expected ) : <EOL> f = self . run ( space , tmpdir , src , status = <NUM_LIT:1> ) <EOL> out , err = capfd . readouterr ( ) <EOL> assert not out <EOL> actual_lines = err . splitlines ( ) <EOL> expected_lines = [ ] <EOL> for line in expected : <EOL> expected_lines . append ( line . format ( f ) ) <EOL> assert actual_lines == expected_lines <EOL> def test_simple ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , "<STR_LIT>" ) <EOL> out , err = capfd . readouterr ( ) <EOL> assert out == "<STR_LIT>" <EOL> assert not err <EOL> def test_expr ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , None , ruby_args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> out , err = capfd . readouterr ( ) <EOL> assert out == "<STR_LIT>" <EOL> self . run ( space , tmpdir , None , ruby_args = [ "<STR_LIT>" ] ) <EOL> out , err = capfd . readouterr ( ) <EOL> assert out == "<STR_LIT>" <EOL> def test_no_expr ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , None , ruby_args = [ "<STR_LIT>" ] , status = <NUM_LIT:1> ) <EOL> out , err = capfd . readouterr ( ) <EOL> assert err == u"<STR_LIT>" <EOL> assert out == "<STR_LIT>" <EOL> def test___FILE__ ( self , space , tmpdir , capfd ) : <EOL> f = self . run ( space , tmpdir , "<STR_LIT>" ) <EOL> out , err = capfd . readouterr ( ) <EOL> assert out == "<STR_LIT>" . format ( f ) <EOL> def test_verbose ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , "<STR_LIT>" , ruby_args = [ "<STR_LIT>" ] ) <EOL> out , err = capfd . readouterr ( ) <EOL> [ version , out ] = out . splitlines ( ) <EOL> assert version . startswith ( "<STR_LIT>" ) <EOL> assert "<STR_LIT>" in version <EOL> assert os . uname ( ) [ <NUM_LIT:4> ] in version <EOL> assert platform . system ( ) . lower ( ) in version <EOL> assert subprocess . check_output ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) . rstrip ( ) in version <EOL> assert out == "<STR_LIT:5>" <EOL> self . run ( space , tmpdir , ruby_args = [ "<STR_LIT>" ] ) <EOL> out , err = capfd . readouterr ( ) <EOL> [ version ] = out . splitlines ( ) <EOL> assert version . startswith ( "<STR_LIT>" ) <EOL> def test_debug_defaults_to_false ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , "<STR_LIT>" ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out . strip ( ) == "<STR_LIT:false>" <EOL> def test_debug_sets_verbose ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , "<STR_LIT>" , ruby_args = [ "<STR_LIT>" ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out . strip ( ) == "<STR_LIT:true>" <EOL> def test_debug_sets_dash_d ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , "<STR_LIT>" , ruby_args = [ "<STR_LIT>" ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out . strip ( ) == "<STR_LIT:true>" <EOL> def test_dash_w_defaults_to_false ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , "<STR_LIT>" ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out . strip ( ) == "<STR_LIT:false>" <EOL> def test_warnings_sets_dash_w ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , "<STR_LIT>" , ruby_args = [ "<STR_LIT>" ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out . strip ( ) == "<STR_LIT:true>" <EOL> def test_warning_level_defaults_to_verbose_true ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , "<STR_LIT>" , ruby_args = [ "<STR_LIT>" ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out . strip ( ) == "<STR_LIT:true>" <EOL> def test_help ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , ruby_args = [ "<STR_LIT>" ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out . splitlines ( ) [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> def test_copyright ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , ruby_args = [ "<STR_LIT>" ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> [ copyright ] = out . splitlines ( ) <EOL> assert copyright . startswith ( "<STR_LIT>" ) <EOL> assert "<STR_LIT>" in copyright <EOL> def test_version ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , ruby_args = [ "<STR_LIT>" ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> [ version ] = out . splitlines ( ) <EOL> assert version . startswith ( "<STR_LIT>" ) <EOL> assert "<STR_LIT>" in version <EOL> assert os . uname ( ) [ <NUM_LIT:4> ] in version <EOL> assert platform . system ( ) . lower ( ) in version <EOL> assert subprocess . check_output ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) . rstrip ( ) in version <EOL> def test_stop_consuming_args ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , ruby_args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out == "<STR_LIT>" <EOL> def test_load_path_multiple_args ( self , space , tmpdir , capfd ) : <EOL> d = tmpdir . mkdir ( "<STR_LIT>" ) <EOL> f1 = d . join ( "<STR_LIT>" ) <EOL> f1 . write ( """<STR_LIT>""" ) <EOL> self . run ( space , tmpdir , """<STR_LIT>""" , ruby_args = [ "<STR_LIT>" , str ( d ) ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out == "<STR_LIT>" <EOL> def test_load_path_joined_args ( self , space , tmpdir , capfd ) : <EOL> d = tmpdir . mkdir ( "<STR_LIT>" ) <EOL> f1 = d . join ( "<STR_LIT>" ) <EOL> f1 . write ( """<STR_LIT>""" ) <EOL> self . run ( space , tmpdir , """<STR_LIT>""" , ruby_args = [ "<STR_LIT>" % d ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out == "<STR_LIT>" <EOL> def test_load_path_path_separated ( self , space , tmpdir , capfd ) : <EOL> d1 = tmpdir . mkdir ( "<STR_LIT>" ) <EOL> d2 = tmpdir . mkdir ( "<STR_LIT>" ) <EOL> f1 = d1 . join ( "<STR_LIT>" ) <EOL> f1 . write ( """<STR_LIT>""" ) <EOL> f2 = d2 . join ( "<STR_LIT>" ) <EOL> f2 . write ( """<STR_LIT>""" ) <EOL> self . run ( space , tmpdir , """<STR_LIT>""" , ruby_args = [ "<STR_LIT>" % ( d1 , d2 ) ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out == "<STR_LIT>" <EOL> def test_require_multiple_args ( self , space , tmpdir , capfd ) : <EOL> d = tmpdir . mkdir ( "<STR_LIT>" ) <EOL> f = d . join ( "<STR_LIT>" ) <EOL> f . write ( """<STR_LIT>""" ) <EOL> self . run ( space , tmpdir , "<STR_LIT>" , ruby_args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , str ( d ) ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out == "<STR_LIT>" <EOL> def test_require_joined_args ( self , space , tmpdir , capfd ) : <EOL> d = tmpdir . mkdir ( "<STR_LIT>" ) <EOL> f = d . join ( "<STR_LIT>" ) <EOL> f . write ( """<STR_LIT>""" ) <EOL> self . run ( space , tmpdir , "<STR_LIT>" , ruby_args = [ "<STR_LIT>" , "<STR_LIT>" , str ( d ) ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out == "<STR_LIT>" <EOL> def test_search_path ( self , space , tmpdir , capfd , monkeypatch ) : <EOL> f = tmpdir . join ( "<STR_LIT:a>" ) <EOL> f . write ( "<STR_LIT>" ) <EOL> monkeypatch . setenv ( "<STR_LIT>" , "<STR_LIT>" % ( tmpdir , os . environ [ "<STR_LIT>" ] ) ) <EOL> self . run ( space , tmpdir , ruby_args = [ "<STR_LIT>" , "<STR_LIT:a>" ] ) <EOL> out , _ = capfd . readouterr ( ) <EOL> assert out == "<STR_LIT>" <EOL> def test_arguments ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , """<STR_LIT>""" , argv = [ "<STR_LIT:abc>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> out , err = capfd . readouterr ( ) <EOL> lines = out . splitlines ( ) <EOL> assert lines == [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> def test_traceback_printed ( self , space , tmpdir , capfd ) : <EOL> self . assert_traceback ( space , tmpdir , capfd , """<STR_LIT>""" , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] ) <EOL> def test_syntax_error ( self , space , tmpdir , capfd ) : <EOL> self . assert_traceback ( space , tmpdir , capfd , """<STR_LIT>""" , [ <EOL> "<STR_LIT>" , <EOL> ] ) <EOL> def test_traceback_load_const ( self , space , tmpdir , capfd ) : <EOL> self . assert_traceback ( space , tmpdir , capfd , """<STR_LIT>""" , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] ) <EOL> def test_traceback_class ( self , space , tmpdir , capfd ) : <EOL> self . assert_traceback ( space , tmpdir , capfd , """<STR_LIT>""" , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] ) <EOL> def test_traceback_default_arg ( self , space , tmpdir , capfd ) : <EOL> self . assert_traceback ( space , tmpdir , capfd , """<STR_LIT>""" , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] ) <EOL> def test_ruby_engine ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , "<STR_LIT>" ) <EOL> out , err = capfd . readouterr ( ) <EOL> assert out == "<STR_LIT>" <EOL> def test_ruby_description ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , "<STR_LIT>" ) <EOL> out1 , err1 = capfd . readouterr ( ) <EOL> self . run ( space , tmpdir , """<STR_LIT>""" ) <EOL> out2 , err2 = capfd . readouterr ( ) <EOL> assert out1 == out2 <EOL> def test_system_exit ( self , space , tmpdir ) : <EOL> self . run ( space , tmpdir , "<STR_LIT>" , <NUM_LIT:0> ) <EOL> self . run ( space , tmpdir , "<STR_LIT>" , <NUM_LIT:1> ) <EOL> def test_at_exit ( self , space , tmpdir , capfd ) : <EOL> f = self . run ( space , tmpdir , """<STR_LIT>""" , status = <NUM_LIT:1> ) <EOL> out , err = capfd . readouterr ( ) <EOL> assert out . splitlines ( ) == [ <EOL> "<STR_LIT:2>" , <EOL> "<STR_LIT:1>" , <EOL> ] <EOL> assert err . splitlines ( ) == [ <EOL> "<STR_LIT>" . format ( f ) , <EOL> "<STR_LIT>" . format ( f ) , <EOL> "<STR_LIT>" . format ( f ) , <EOL> "<STR_LIT>" . format ( f ) , <EOL> ] <EOL> def test_program_global ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , None , ruby_args = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> out1 , err1 = capfd . readouterr ( ) <EOL> assert out1 == "<STR_LIT>" <EOL> f = self . run ( space , tmpdir , "<STR_LIT>" ) <EOL> out2 , err2 = capfd . readouterr ( ) <EOL> assert out2 == "<STR_LIT>" . format ( f ) <EOL> f = self . run ( space , tmpdir , "<STR_LIT>" ) <EOL> out3 , _ = capfd . readouterr ( ) <EOL> assert out3 == "<STR_LIT>" . format ( f ) <EOL> def test_non_existent_file ( self , space , tmpdir , capfd ) : <EOL> self . run ( space , tmpdir , None , ruby_args = [ str ( tmpdir . join ( "<STR_LIT>" ) ) ] , status = <NUM_LIT:1> ) <EOL> out , err = capfd . readouterr ( ) <EOL> assert err == "<STR_LIT>" % tmpdir . join ( "<STR_LIT>" ) </s>
