@@ -33,3 +33,50 @@ def print_prompt(self):
33
33
return 'echo "%PROMPT%"'
34
34
35
35
activation_tester (Batch )
36
+
37
+
38
+ @pytest .mark .usefixtures ("activation_python" )
39
+ def test_batch_output (activation_tester_class , activation_tester , tmp_path ):
40
+ version_script = tmp_path / "version.bat"
41
+ version_script .write_text ("ver" , encoding = "utf-8" )
42
+
43
+ class Batch (activation_tester_class ):
44
+ def __init__ (self , session ) -> None :
45
+ super ().__init__ (BatchActivator , session , None , "activate.bat" , "bat" )
46
+ self ._version_cmd = [str (version_script )]
47
+ self ._invoke_script = []
48
+ self .deactivate = "call deactivate"
49
+ self .activate_cmd = "call"
50
+ self .pydoc_call = f"call { self .pydoc_call } "
51
+ self .unix_line_ending = False
52
+
53
+ def _get_test_lines (self , activate_script ):
54
+ """
55
+ Build intermediary script which will be then called.
56
+ In the script just activate environment, call echo to get current
57
+ echo setting, and then deactivate. This ensures that echo setting
58
+ is preserved and no unwanted output appears.
59
+ """
60
+ intermediary_script_path = str (tmp_path / "intermediary.bat" )
61
+ activate_script_quoted = self .quote (str (activate_script ))
62
+ return [
63
+ "@echo on" ,
64
+ f"@echo @call { activate_script_quoted } > { intermediary_script_path } " ,
65
+ f"@echo @echo >> { intermediary_script_path } " ,
66
+ f"@echo @deactivate >> { intermediary_script_path } " ,
67
+ f"@call { intermediary_script_path } " ,
68
+ ]
69
+
70
+ def assert_output (self , out , raw , tmp_path ): # noqa: ARG002
71
+ assert out [0 ] == "ECHO is on." , raw
72
+
73
+ def quote (self , s ):
74
+ if '"' in s or " " in s :
75
+ text = s .replace ('"' , r"\"" )
76
+ return f'"{ text } "'
77
+ return s
78
+
79
+ def print_prompt (self ):
80
+ return 'echo "%PROMPT%"'
81
+
82
+ activation_tester (Batch )
0 commit comments