68
68
)
69
69
70
70
71
- TEST_PY_COMMANDS = "\n " .join ([
71
+ TEST_PY_DEFAULTS = "\n " .join ([
72
72
"[defaults]" ,
73
- * [f"{ k [3 :].lower ()} ={ v } " for k , v in TEST_PY_ENV .items ()]
73
+ * [f"{ k [3 :].lower ()} ={ v } " for k , v in TEST_PY_ENV .items ()],
74
74
])
75
75
76
76
77
+ TEST_PY_COMMANDS = "\n " .join ([
78
+ "[commands]" ,
79
+ "test-command=TEST_EXE.exe" ,
80
+ ])
81
+
77
82
def create_registry_data (root , data ):
78
83
def _create_registry_data (root , key , value ):
79
84
if isinstance (value , dict ):
@@ -430,21 +435,21 @@ def test_search_major_2(self):
430
435
self .assertTrue (data ["env.tag" ].startswith ("2." ), data ["env.tag" ])
431
436
432
437
def test_py_default (self ):
433
- with self .py_ini (TEST_PY_COMMANDS ):
438
+ with self .py_ini (TEST_PY_DEFAULTS ):
434
439
data = self .run_py (["-arg" ])
435
440
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
436
441
self .assertEqual ("3.100" , data ["SearchInfo.tag" ])
437
442
self .assertEqual ("X.Y.exe -arg" , data ["stdout" ].strip ())
438
443
439
444
def test_py2_default (self ):
440
- with self .py_ini (TEST_PY_COMMANDS ):
445
+ with self .py_ini (TEST_PY_DEFAULTS ):
441
446
data = self .run_py (["-2" , "-arg" ])
442
447
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
443
448
self .assertEqual ("3.100-32" , data ["SearchInfo.tag" ])
444
449
self .assertEqual ("X.Y-32.exe -arg" , data ["stdout" ].strip ())
445
450
446
451
def test_py3_default (self ):
447
- with self .py_ini (TEST_PY_COMMANDS ):
452
+ with self .py_ini (TEST_PY_DEFAULTS ):
448
453
data = self .run_py (["-3" , "-arg" ])
449
454
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
450
455
self .assertEqual ("3.100-arm64" , data ["SearchInfo.tag" ])
@@ -469,7 +474,7 @@ def test_py3_default_env(self):
469
474
self .assertEqual ("X.Y-arm64.exe -X fake_arg_for_test -arg" , data ["stdout" ].strip ())
470
475
471
476
def test_py_default_short_argv0 (self ):
472
- with self .py_ini (TEST_PY_COMMANDS ):
477
+ with self .py_ini (TEST_PY_DEFAULTS ):
473
478
for argv0 in ['"py.exe"' , 'py.exe' , '"py"' , 'py' ]:
474
479
with self .subTest (argv0 ):
475
480
data = self .run_py (["--version" ], argv = f'{ argv0 } --version' )
@@ -519,63 +524,63 @@ def test_virtualenv_with_env(self):
519
524
self .assertNotEqual (data2 ["SearchInfo.lowPriorityTag" ], "True" )
520
525
521
526
def test_py_shebang (self ):
522
- with self .py_ini (TEST_PY_COMMANDS ):
527
+ with self .py_ini (TEST_PY_DEFAULTS ):
523
528
with self .script ("#! /usr/bin/python -prearg" ) as script :
524
529
data = self .run_py ([script , "-postarg" ])
525
530
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
526
531
self .assertEqual ("3.100" , data ["SearchInfo.tag" ])
527
532
self .assertEqual (f"X.Y.exe -prearg { script } -postarg" , data ["stdout" ].strip ())
528
533
529
534
def test_python_shebang (self ):
530
- with self .py_ini (TEST_PY_COMMANDS ):
535
+ with self .py_ini (TEST_PY_DEFAULTS ):
531
536
with self .script ("#! python -prearg" ) as script :
532
537
data = self .run_py ([script , "-postarg" ])
533
538
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
534
539
self .assertEqual ("3.100" , data ["SearchInfo.tag" ])
535
540
self .assertEqual (f"X.Y.exe -prearg { script } -postarg" , data ["stdout" ].strip ())
536
541
537
542
def test_py2_shebang (self ):
538
- with self .py_ini (TEST_PY_COMMANDS ):
543
+ with self .py_ini (TEST_PY_DEFAULTS ):
539
544
with self .script ("#! /usr/bin/python2 -prearg" ) as script :
540
545
data = self .run_py ([script , "-postarg" ])
541
546
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
542
547
self .assertEqual ("3.100-32" , data ["SearchInfo.tag" ])
543
548
self .assertEqual (f"X.Y-32.exe -prearg { script } -postarg" , data ["stdout" ].strip ())
544
549
545
550
def test_py3_shebang (self ):
546
- with self .py_ini (TEST_PY_COMMANDS ):
551
+ with self .py_ini (TEST_PY_DEFAULTS ):
547
552
with self .script ("#! /usr/bin/python3 -prearg" ) as script :
548
553
data = self .run_py ([script , "-postarg" ])
549
554
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
550
555
self .assertEqual ("3.100-arm64" , data ["SearchInfo.tag" ])
551
556
self .assertEqual (f"X.Y-arm64.exe -X fake_arg_for_test -prearg { script } -postarg" , data ["stdout" ].strip ())
552
557
553
558
def test_py_shebang_nl (self ):
554
- with self .py_ini (TEST_PY_COMMANDS ):
559
+ with self .py_ini (TEST_PY_DEFAULTS ):
555
560
with self .script ("#! /usr/bin/python -prearg\n " ) as script :
556
561
data = self .run_py ([script , "-postarg" ])
557
562
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
558
563
self .assertEqual ("3.100" , data ["SearchInfo.tag" ])
559
564
self .assertEqual (f"X.Y.exe -prearg { script } -postarg" , data ["stdout" ].strip ())
560
565
561
566
def test_py2_shebang_nl (self ):
562
- with self .py_ini (TEST_PY_COMMANDS ):
567
+ with self .py_ini (TEST_PY_DEFAULTS ):
563
568
with self .script ("#! /usr/bin/python2 -prearg\n " ) as script :
564
569
data = self .run_py ([script , "-postarg" ])
565
570
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
566
571
self .assertEqual ("3.100-32" , data ["SearchInfo.tag" ])
567
572
self .assertEqual (f"X.Y-32.exe -prearg { script } -postarg" , data ["stdout" ].strip ())
568
573
569
574
def test_py3_shebang_nl (self ):
570
- with self .py_ini (TEST_PY_COMMANDS ):
575
+ with self .py_ini (TEST_PY_DEFAULTS ):
571
576
with self .script ("#! /usr/bin/python3 -prearg\n " ) as script :
572
577
data = self .run_py ([script , "-postarg" ])
573
578
self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
574
579
self .assertEqual ("3.100-arm64" , data ["SearchInfo.tag" ])
575
580
self .assertEqual (f"X.Y-arm64.exe -X fake_arg_for_test -prearg { script } -postarg" , data ["stdout" ].strip ())
576
581
577
582
def test_py_shebang_short_argv0 (self ):
578
- with self .py_ini (TEST_PY_COMMANDS ):
583
+ with self .py_ini (TEST_PY_DEFAULTS ):
579
584
with self .script ("#! /usr/bin/python -prearg" ) as script :
580
585
# Override argv to only pass "py.exe" as the command
581
586
data = self .run_py ([script , "-postarg" ], argv = f'"py.exe" "{ script } " -postarg' )
@@ -592,7 +597,7 @@ def test_py_handle_64_in_ini(self):
592
597
593
598
def test_search_path (self ):
594
599
stem = Path (sys .executable ).stem
595
- with self .py_ini (TEST_PY_COMMANDS ):
600
+ with self .py_ini (TEST_PY_DEFAULTS ):
596
601
with self .script (f"#! /usr/bin/env { stem } -prearg" ) as script :
597
602
data = self .run_py (
598
603
[script , "-postarg" ],
@@ -603,7 +608,7 @@ def test_search_path(self):
603
608
def test_search_path_exe (self ):
604
609
# Leave the .exe on the name to ensure we don't add it a second time
605
610
name = Path (sys .executable ).name
606
- with self .py_ini (TEST_PY_COMMANDS ):
611
+ with self .py_ini (TEST_PY_DEFAULTS ):
607
612
with self .script (f"#! /usr/bin/env { name } -prearg" ) as script :
608
613
data = self .run_py (
609
614
[script , "-postarg" ],
@@ -613,7 +618,7 @@ def test_search_path_exe(self):
613
618
614
619
def test_recursive_search_path (self ):
615
620
stem = self .get_py_exe ().stem
616
- with self .py_ini (TEST_PY_COMMANDS ):
621
+ with self .py_ini (TEST_PY_DEFAULTS ):
617
622
with self .script (f"#! /usr/bin/env { stem } " ) as script :
618
623
data = self .run_py (
619
624
[script ],
@@ -674,3 +679,21 @@ def test_literal_shebang_quoted_escape(self):
674
679
f'"{ script .parent } \\ some\\ random app" -witharg { script } ' ,
675
680
data ["stdout" ].strip (),
676
681
)
682
+
683
+ def test_literal_shebang_command (self ):
684
+ with self .py_ini (TEST_PY_COMMANDS ):
685
+ with self .script ('#! test-command arg1' ) as script :
686
+ data = self .run_py ([script ])
687
+ self .assertEqual (
688
+ f"TEST_EXE.exe arg1 { script } " ,
689
+ data ["stdout" ].strip (),
690
+ )
691
+
692
+ def test_literal_shebang_invalid_template (self ):
693
+ with self .script ('#! /usr/bin/not-python arg1' ) as script :
694
+ data = self .run_py ([script ])
695
+ expect = script .parent / "/usr/bin/not-python"
696
+ self .assertEqual (
697
+ f"{ expect } arg1 { script } " ,
698
+ data ["stdout" ].strip (),
699
+ )
0 commit comments