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!"
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"
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"
def sudo(self): mc = MockContext(sudo=[Result("foo")]) with raises(TypeError): mc.set_result_for("sudo", "whatever", Result("bar"))
def run(self): mc = MockContext(run=[Result("foo")]) with raises(TypeError): mc.set_result_for("run", "whatever", Result("bar"))
def mapping_to_iterable(self): self._expect_NotImplementedError( MockContext(run={"something": [Result("meh")]}) )
def mapping_to_single_value(self): self._expect_NotImplementedError( MockContext(run={"something": Result("meh")}) )
def iterable(self): self._expect_NotImplementedError(MockContext(run=[Result("meh")]))
def single_value(self): self._expect_NotImplementedError(MockContext(run=Result("meh")))
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"
def return_value_kwargs_may_be_command_string_maps(self): c = MockContext(run={"foo": Result("bar")}) assert c.run("foo").stdout == "bar"
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!"
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"