示例#1
0
def test_pack_single_pass(monkeypatch):
    def dummy_pack(_, to_pack):
        return []

    monkeypatch.setattr(cage.Cage, 'pack', dummy_pack)
    cages = main.pack([pytest.Mock(), pytest.Mock(), pytest.Mock()])
    assert len(cages) == 1
示例#2
0
def test_pack_multiple_pass(monkeypatch):
    p0 = pytest.Mock()
    p1 = pytest.Mock()
    p2 = pytest.Mock()
    p0.packed = False
    p1.packed = False
    p2.packed = False

    def dummy_pack(_, to_pack):
        to_pack.pop()
        return to_pack

    monkeypatch.setattr(cage.Cage, 'pack', dummy_pack)
    cages = main.pack([p0, p1, p2])
    assert len(cages) == 3
示例#3
0
 def test_address_and_password(self, monkeypatch):
     monkeypatch.setattr(valve.rcon, "_RCONShell", pytest.Mock())
     shell = valve.rcon._RCONShell.return_value
     valve.rcon.shell(("localhost", "9001"), "password")
     assert shell.onecmd.call_args[0] == (
         "!connect localhost:9001 password", )
     assert shell.cmdloop.called
示例#4
0
 def test_subscribe_default_silence(self):
     subscriber = pytest.Mock()
     assert Pipeline.subscribe("test",
                               unpack=True)(subscriber) is subscriber
     subscriber_specs = subscriber.__pipeline_subscriptions__[Pipeline]
     assert len(subscriber_specs) == 1
     assert subscriber_specs[0].type == "test"
     assert subscriber_specs[0].function is subscriber
     assert subscriber_specs[0].silence is False
示例#5
0
 def test_scan_object(self, monkeypatch):
     monkeypatch.setattr(Pipeline, "__init__",
                         pytest.Mock(return_value=None))
     obj = types.SimpleNamespace(subscriber=pytest.Mock)
     Pipeline.subscribe("test")(obj.subscriber)
     assert isinstance(Pipeline.scan(obj), Pipeline)
     assert len(Pipeline.__init__.call_args[0][0]) == 1
     subscriber = Pipeline.__init__.call_args[0][0][0]
     assert subscriber.type == "test"
     assert subscriber._function is obj.subscriber
     assert subscriber._unpack is False
     assert subscriber._silence is False
示例#6
0
 def execute(self, monkeypatch):
     monkeypatch.setattr(valve.rcon, "execute", pytest.Mock())
     return valve.rcon.execute
示例#7
0
 def shell(self, monkeypatch):
     monkeypatch.setattr(valve.rcon, "shell", pytest.Mock())
     return valve.rcon.shell
示例#8
0
 def test_ignore_interrupt(self, monkeypatch):
     monkeypatch.setattr(valve.rcon, "_RCONShell", pytest.Mock())
     shell = valve.rcon._RCONShell.return_value
     shell.cmdloop.side_effect = KeyboardInterrupt
     valve.rcon.shell()
     assert shell.cmdloop.called
示例#9
0
 def test_password_only(self, monkeypatch):
     monkeypatch.setattr(valve.rcon, "_RCONShell", pytest.Mock())
     shell = valve.rcon._RCONShell.return_value
     valve.rcon.shell(password="******")
     assert not shell.onecmd.called
     assert shell.cmdloop.called
示例#10
0
 def test_no_address(self, monkeypatch):
     monkeypatch.setattr(valve.rcon, "_RCONShell", pytest.Mock())
     shell = valve.rcon._RCONShell.return_value
     valve.rcon.shell()
     assert not shell.onecmd.called
     assert shell.cmdloop.called