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