Esempio n. 1
0
 def sudo_also_covered(self):
     c = MockContext(sudo=Result(stderr="super duper"))
     assert c.sudo("doesn't mattress").stderr == "super duper"
     try:
         MockContext().sudo("meh")
     except NotImplementedError:
         pass
     else:
         assert False, "Did not get a NotImplementedError for sudo!"
Esempio n. 2
0
 def sudo(self):
     mc = MockContext(sudo={"foo": Result("bar")})
     assert mc.sudo("foo").stdout == "bar"
     mc.set_result_for("sudo", "foo", Result("biz"))
     assert mc.sudo("foo").stdout == "biz"
Esempio n. 3
0
 def run(self):
     mc = MockContext(run={"foo": Result("bar")})
     assert mc.run("foo").stdout == "bar"
     mc.set_result_for("run", "foo", Result("biz"))
     assert mc.run("foo").stdout == "biz"
Esempio n. 4
0
 def sudo(self):
     mc = MockContext(sudo=[Result("foo")])
     with raises(TypeError):
         mc.set_result_for("sudo", "whatever", Result("bar"))
Esempio n. 5
0
 def run(self):
     mc = MockContext(run=[Result("foo")])
     with raises(TypeError):
         mc.set_result_for("run", "whatever", Result("bar"))
Esempio n. 6
0
 def mapping_to_iterable(self):
     self._expect_NotImplementedError(
         MockContext(run={"something": [Result("meh")]})
     )
Esempio n. 7
0
 def mapping_to_single_value(self):
     self._expect_NotImplementedError(
         MockContext(run={"something": Result("meh")})
     )
Esempio n. 8
0
 def iterable(self):
     self._expect_NotImplementedError(MockContext(run=[Result("meh")]))
Esempio n. 9
0
 def single_value(self):
     self._expect_NotImplementedError(MockContext(run=Result("meh")))
Esempio n. 10
0
 def return_value_map_kwargs_may_take_iterables_too(self):
     c = MockContext(run={"foo": [Result("bar"), Result("biz")]})
     assert c.run("foo").stdout == "bar"
     assert c.run("foo").stdout == "biz"
Esempio n. 11
0
 def return_value_kwargs_may_be_command_string_maps(self):
     c = MockContext(run={"foo": Result("bar")})
     assert c.run("foo").stdout == "bar"
Esempio n. 12
0
 def return_value_kwargs_can_take_iterables_too(self):
     c = MockContext(run=[Result("some output"), Result("more!")])
     assert c.run("doesn't mattress").stdout == "some output"
     assert c.run("still doesn't mattress").stdout == "more!"
Esempio n. 13
0
 def non_config_init_kwargs_used_as_return_values_for_methods(self):
     c = MockContext(run=Result("some output"))
     assert c.run("doesn't mattress").stdout == "some output"