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
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
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
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
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
def execute(self, monkeypatch): monkeypatch.setattr(valve.rcon, "execute", pytest.Mock()) return valve.rcon.execute
def shell(self, monkeypatch): monkeypatch.setattr(valve.rcon, "shell", pytest.Mock()) return valve.rcon.shell
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
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
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