@@ -1252,7 +1252,7 @@ def test_command_line(self, settings=None):
12521252
12531253 self .assertEqual (get_command ("groups" ).echo (message = "hey!" ).strip (), "hey!" )
12541254
1255- result = run_command ("groups" , * settings , "echo" , "hey!" , "5" )
1255+ result = run_command ("groups" , "--no-color" , * settings , "echo" , "hey!" , "5" )
12561256 if override :
12571257 self .assertEqual (result [0 ].strip (), ("hey! " * 5 ).strip ())
12581258 self .assertEqual (
@@ -1413,7 +1413,15 @@ def test_command_line(self, settings=None):
14131413 self .assertEqual (grp_cmd .lower (4 , 9 ), "ANNAmonteS" )
14141414
14151415 result = run_command (
1416- "groups" , * settings , "string" , "annamontes" , "case" , "upper" , "4" , "9"
1416+ "groups" ,
1417+ "--no-color" ,
1418+ * settings ,
1419+ "string" ,
1420+ "annamontes" ,
1421+ "case" ,
1422+ "upper" ,
1423+ "4" ,
1424+ "9" ,
14171425 )
14181426 if override :
14191427 self .assertIn (
@@ -2634,12 +2642,12 @@ class TracebackTests(TestCase):
26342642 """
26352643
26362644 def test_usage_error_no_tb (self ):
2637- stdout , stderr , retcode = run_command ("tb" , "wrong" )
2645+ stdout , stderr , retcode = run_command ("tb" , "--no-color" , " wrong" )
26382646 self .assertTrue ("Usage: ./manage.py tb [OPTIONS] COMMAND [ARGS]" in stdout )
26392647 self .assertTrue ("No such command" in stderr )
26402648 self .assertTrue (retcode > 0 )
26412649
2642- stdout , stderr , retcode = run_command ("tb" , "error" , "wrong" )
2650+ stdout , stderr , retcode = run_command ("tb" , "--no-color" , " error" , "wrong" )
26432651 self .assertTrue ("Usage: ./manage.py tb error [OPTIONS]" in stdout )
26442652 self .assertTrue ("Got unexpected extra argument" in stderr )
26452653 self .assertTrue (retcode > 0 )
@@ -2652,7 +2660,9 @@ def test_usage_error_no_tb(self):
26522660
26532661 def test_usage_error_with_tb_if_requested (self ):
26542662
2655- stdout , stderr , retcode = run_command ("tb" , "--traceback" , "wrong" )
2663+ stdout , stderr , retcode = run_command (
2664+ "tb" , "--no-color" , "--traceback" , "wrong"
2665+ )
26562666 self .assertFalse (stdout .strip ())
26572667 self .assertTrue ("Traceback" in stderr )
26582668 if rich_installed :
@@ -2662,7 +2672,9 @@ def test_usage_error_with_tb_if_requested(self):
26622672 self .assertTrue ("No such command 'wrong'" in stderr )
26632673 self .assertTrue (retcode > 0 )
26642674
2665- stdout , stderr , retcode = run_command ("tb" , "--traceback" , "error" , "wrong" )
2675+ stdout , stderr , retcode = run_command (
2676+ "tb" , "--no-color" , "--traceback" , "error" , "wrong"
2677+ )
26662678 self .assertFalse (stdout .strip ())
26672679 self .assertTrue ("Traceback" in stderr )
26682680 if rich_installed :
@@ -2705,3 +2717,31 @@ def test_exit_on_call(self):
27052717
27062718 with self .assertRaises (SystemExit ):
27072719 call_command ("tb" , "exit" , "--code=1" )
2720+
2721+
2722+ class TestHandleAsInit (TestCase ):
2723+
2724+ def test_handle_as_init_run (self ):
2725+
2726+ stdout , stderr , retcode = run_command ("handle_as_init" )
2727+ self .assertTrue ("handle" in stdout )
2728+ self .assertFalse (stderr .strip ())
2729+ self .assertEqual (retcode , 0 )
2730+
2731+ stdout , stderr , retcode = run_command ("handle_as_init" , "subcommand" )
2732+ self .assertTrue ("subcommand" in stdout )
2733+ self .assertFalse (stderr .strip ())
2734+ self .assertEqual (retcode , 0 )
2735+
2736+ def test_handle_as_init_call (self ):
2737+
2738+ self .assertEqual (call_command ("handle_as_init" ).strip (), "handle" )
2739+ self .assertEqual (
2740+ call_command ("handle_as_init" , "subcommand" ).strip (), "subcommand"
2741+ )
2742+
2743+ def test_handle_as_init_direct (self ):
2744+
2745+ self .assertEqual (get_command ("handle_as_init" )(), "handle" )
2746+ self .assertEqual (get_command ("handle_as_init" , "subcommand" )(), "subcommand" )
2747+ self .assertEqual (get_command ("handle_as_init" ).subcommand (), "subcommand" )
0 commit comments