def test_step_context_overload(mocker): class NoopStep(Step): def run(self, another=None): pass # Waiting step context noop_step = NoopStep(another="context1") spy = mocker.spy(noop_step, 'run') noop_step.run_with_context(Host("local", add="context")) spy.assert_called_once_with(another='context1') # Waiting no context noop_step = NoopStep() spy = mocker.spy(noop_step, 'run') noop_step.run_with_context(Host("local", add="context")) spy.assert_called_once_with() # Waiting host context noop_step = NoopStep() spy = mocker.spy(noop_step, 'run') noop_step.run_with_context(Host("local", another="host_context")) spy.assert_called_once_with(another="host_context") # Waiting step and host context, step context overloading step context noop_step = NoopStep(another="context1") spy = mocker.spy(noop_step, 'run') noop_step.run_with_context(Host("local", another="host_context")) spy.assert_called_once_with(another="context1")
def run(self): self.step(noop_step, Host("local")) self.step([ noop_step, ], [ Host("local"), ])
class DryTask(SimpleTask): hosts = [ Host("local"), ] steps = [ noop_step, ]
def test_global_context(): h = Host("local") assert global_context.host is None assert global_context.conn is None with global_context.SetContext(h): assert global_context.host == h assert global_context.conn is not None assert isinstance(global_context.conn, Context) assert global_context.host is None assert global_context.conn is None
def run(self): self.step(noop_step, Host("local"))
def centos_ssh_host(): return Host("127.0.0.1", ssh_user="******", ssh_password="******", ssh_port=22223)
def ubuntu_ssh_host(): return Host("127.0.0.1", ssh_user="******", ssh_password="******", ssh_port=22222)
def local_host(): return Host("local")
def test_step_abc(mocker): spy = mocker.spy(Step, 'run') with pytest.raises(NotImplementedError): Step(another="context1").run_with_context(Host("local", add="context")) spy.assert_called_once()
def test_log(capsys): with global_context.SetContext(Host("local")): utils.log("Hellotest") captured = capsys.readouterr() assert captured.out == "💃💃💃 local> Hellotest\n"
def test_host_create(): assert Host("[email protected]:22").host == "1.2.3.4" assert Host("1.2.3.4:22").host == "1.2.3.4" assert Host("1.2.3.4").host == "1.2.3.4" assert Host("abc.example:22").host == "abc.example" assert Host("[email protected]:22").host == "abc.example" assert Host("local").is_connection_local() is True assert Host("localhost").is_connection_local() is True assert Host("user@localhost").is_connection_local() is True assert Host("1.2.3.4").is_connection_local() is False assert Host("[email protected]").is_connection_local() is False assert Host("*****@*****.**").is_connection_local() is False
def test_host_hash(): h1 = Host("1.2.3.4") h2 = Host("1.2.3.4") assert h1.__hash__() == h2.__hash__()