MCPcopy Create free account
hub / github.com/pyinvoke/invoke / cd

Class cd

tests/context.py:157–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155 assert self.c.cwd == os.path.join("~b", "c")
156
157 class cd:
158 _escaped_prompt = re.escape(Config().sudo.prompt)
159
160 @patch(local_path)
161 def should_apply_to_run(self, Local):
162 runner = Local.return_value
163 c = Context()
164 with c.cd("foo"):
165 c.run("whoami")
166
167 cmd = "cd foo && whoami"
168 assert runner.run.called, "run() never called runner.run()!"
169 assert runner.run.call_args[0][0] == cmd
170
171 @patch(local_path)
172 def should_apply_to_sudo(self, Local):
173 runner = Local.return_value
174 c = Context()
175 with c.cd("foo"):
176 c.sudo("whoami")
177
178 cmd = "sudo -S -p '[sudo] password: ' cd foo && whoami"
179 assert runner.run.called, "sudo() never called runner.run()!"
180 assert runner.run.call_args[0][0] == cmd
181
182 @patch(local_path)
183 def should_occur_before_prefixes(self, Local):
184 runner = Local.return_value
185 c = Context()
186 with c.prefix("source venv"):
187 with c.cd("foo"):
188 c.run("whoami")
189
190 cmd = "cd foo && source venv && whoami"
191 assert runner.run.called, "run() never called runner.run()!"
192 assert runner.run.call_args[0][0] == cmd
193
194 @patch(local_path)
195 def should_use_finally_to_revert_changes_on_exceptions(self, Local):
196 class Oops(Exception):
197 pass
198
199 runner = Local.return_value
200 c = Context()
201 try:
202 with c.cd("foo"):
203 c.run("whoami")
204 assert runner.run.call_args[0][0] == "cd foo && whoami"
205 raise Oops
206 except Oops:
207 pass
208 c.run("ls")
209 # When bug present, this would be "cd foo && ls"
210 assert runner.run.call_args[0][0] == "ls"
211
212 @patch(local_path)
213 def cd_should_accept_any_stringable_object(self, Local):
214 class Path:

Callers

nothing calls this directly

Calls 1

ConfigClass · 0.90

Tested by

no test coverage detected