<s> import os <EOL> import pytest <EOL> from mock import Mock <EOL> from doit . exceptions import InvalidCommand <EOL> from doit . cmd_run import Run <EOL> from doit . cmd_list import List <EOL> from doit import doit_cmd <EOL> def cmd_main ( args ) : <EOL> return doit_cmd . DoitMain ( ) . run ( args ) <EOL> class TestRun ( object ) : <EOL> def test_version ( self , capsys ) : <EOL> cmd_main ( [ "<STR_LIT>" ] ) <EOL> out , err = capsys . readouterr ( ) <EOL> assert "<STR_LIT>" in out <EOL> def test_usage ( self , capsys ) : <EOL> cmd_main ( [ "<STR_LIT>" ] ) <EOL> out , err = capsys . readouterr ( ) <EOL> assert "<STR_LIT>" in out <EOL> def test_run_is_default ( self , monkeypatch ) : <EOL> mock_run = Mock ( ) <EOL> monkeypatch . setattr ( Run , "<STR_LIT>" , mock_run ) <EOL> cmd_main ( [ ] ) <EOL> assert <NUM_LIT:1> == mock_run . call_count <EOL> def test_run_other_subcommand ( self , monkeypatch ) : <EOL> mock_list = Mock ( ) <EOL> monkeypatch . setattr ( List , "<STR_LIT>" , mock_list ) <EOL> cmd_main ( [ "<STR_LIT:list>" ] ) <EOL> assert <NUM_LIT:1> == mock_list . call_count <EOL> def test_cmdline_vars ( self , monkeypatch ) : <EOL> mock_run = Mock ( ) <EOL> monkeypatch . setattr ( Run , "<STR_LIT>" , mock_run ) <EOL> cmd_main ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> assert '<STR_LIT:1>' == doit_cmd . get_var ( '<STR_LIT:x>' ) <EOL> assert '<STR_LIT:abc>' == doit_cmd . get_var ( '<STR_LIT:y>' ) <EOL> def test_cmdline_vars_not_opts ( self , monkeypatch ) : <EOL> mock_run = Mock ( ) <EOL> monkeypatch . setattr ( Run , "<STR_LIT>" , mock_run ) <EOL> cmd_main ( [ '<STR_LIT>' ] ) <EOL> assert None == doit_cmd . get_var ( '<STR_LIT>' ) <EOL> def test_task_loader_has_cmd_list ( self , monkeypatch ) : <EOL> cmd_names = [ ] <EOL> def save_cmd_names ( self , params , args ) : <EOL> cmd_names . extend ( self . loader . cmd_names ) <EOL> monkeypatch . setattr ( Run , "<STR_LIT>" , save_cmd_names ) <EOL> cmd_main ( [ ] ) <EOL> assert '<STR_LIT:list>' in cmd_names <EOL> def test_extra_config ( self , monkeypatch , depfile_name ) : <EOL> outfile_val = [ ] <EOL> def monkey_run ( self , opt_values , pos_args ) : <EOL> outfile_val . append ( opt_values [ '<STR_LIT>' ] ) <EOL> monkeypatch . setattr ( Run , "<STR_LIT>" , monkey_run ) <EOL> extra_config = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : depfile_name , <EOL> } <EOL> doit_cmd . DoitMain ( extra_config = { '<STR_LIT>' : extra_config } ) . run ( [ ] ) <EOL> assert outfile_val [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> class TestErrors ( object ) : <EOL> def test_interrupt ( self , monkeypatch ) : <EOL> def my_raise ( * args ) : <EOL> raise KeyboardInterrupt ( ) <EOL> mock_cmd = Mock ( side_effect = my_raise ) <EOL> monkeypatch . setattr ( Run , "<STR_LIT>" , mock_cmd ) <EOL> pytest . raises ( KeyboardInterrupt , cmd_main , [ ] ) <EOL> def test_user_error ( self , capsys , monkeypatch ) : <EOL> mock_cmd = Mock ( side_effect = InvalidCommand ) <EOL> monkeypatch . setattr ( Run , "<STR_LIT>" , mock_cmd ) <EOL> got = cmd_main ( [ ] ) <EOL> assert <NUM_LIT:3> == got <EOL> out , err = capsys . readouterr ( ) <EOL> assert "<STR_LIT>" in err <EOL> def test_internal_error ( self , capsys , monkeypatch ) : <EOL> mock_cmd = Mock ( side_effect = Exception ) <EOL> monkeypatch . setattr ( Run , "<STR_LIT>" , mock_cmd ) <EOL> got = cmd_main ( [ ] ) <EOL> assert <NUM_LIT:3> == got <EOL> out , err = capsys . readouterr ( ) <EOL> assert "<STR_LIT>" in err <EOL> class TestConfig ( object ) : <EOL> def test_no_ini_config_file ( self ) : <EOL> main = doit_cmd . DoitMain ( config_filenames = ( ) ) <EOL> main . run ( [ '<STR_LIT>' ] ) <EOL> def test_load_plugins_command ( self ) : <EOL> config_filename = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> main = doit_cmd . DoitMain ( config_filenames = config_filename ) <EOL> assert <NUM_LIT:1> == len ( main . config [ '<STR_LIT>' ] ) <EOL> assert '<STR_LIT:foo>' in main . get_cmds ( ) <EOL> def test_merge_api_ini_config ( self ) : <EOL> config_filename = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> api_config = { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } } <EOL> main = doit_cmd . DoitMain ( config_filenames = config_filename , <EOL> extra_config = api_config ) <EOL> assert <NUM_LIT:1> == len ( main . config [ '<STR_LIT>' ] ) <EOL> assert '<STR_LIT:foo>' in main . get_cmds ( ) <EOL> assert main . config [ '<STR_LIT>' ] == { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> def test_execute_command_plugin ( self , capsys ) : <EOL> config_filename = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> main = doit_cmd . DoitMain ( config_filenames = config_filename ) <EOL> main . run ( [ '<STR_LIT:foo>' ] ) <EOL> got = capsys . readouterr ( ) [ <NUM_LIT:0> ] <EOL> assert got == '<STR_LIT>' </s>
