Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/fake_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def scenario(s):

def make_config(**overrides):
values = {
"host": "10.0.0.2",
"host": "192.0.2.2",
"port": 4455,
"password": "",
"scene_item_name": OVERLAY,
Expand Down
20 changes: 10 additions & 10 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)

BASE = {
"host": "10.0.0.2",
"host": "192.0.2.2",
"port": 4455,
"password": "secret",
"scene_item_name": "Overlay",
Expand Down Expand Up @@ -129,23 +129,23 @@ def test_a_config_file_holding_null_is_unreadable(tmp_path):
def test_save_then_load_round_trips(tmp_path):
path = tmp_path / "config.json"
cfg = AppConfig.from_dict(
{**default_config().to_dict(), "host": "10.0.0.5", "scene_item_name": "Map"}
{**default_config().to_dict(), "host": "192.0.2.5", "scene_item_name": "Map"}
)
save_config(cfg, path)
assert load_config(path) == cfg


def test_a_save_cut_short_leaves_the_old_settings_intact(tmp_path, monkeypatch):
path = tmp_path / "config.json"
old = AppConfig.from_dict({**default_config().to_dict(), "host": "10.0.0.5"})
old = AppConfig.from_dict({**default_config().to_dict(), "host": "192.0.2.5"})
save_config(old, path)

def dump_then_fail(data, file, **_options):
file.write('{"host": "10.0.')
raise OSError("disk full")

monkeypatch.setattr(config_module.json, "dump", dump_then_fail)
new = AppConfig.from_dict({**default_config().to_dict(), "host": "192.168.1.9"})
new = AppConfig.from_dict({**default_config().to_dict(), "host": "198.51.100.9"})

with pytest.raises(OSError):
save_config(new, path)
Expand All @@ -160,7 +160,7 @@ def test_a_save_waits_out_something_holding_the_file_for_a_moment(tmp_path):
# scanner or backup tool reading the file would.
path = tmp_path / "config.json"
save_config(default_config(), path)
new = AppConfig.from_dict({**default_config().to_dict(), "host": "192.168.1.9"})
new = AppConfig.from_dict({**default_config().to_dict(), "host": "198.51.100.9"})
held = open(path, "rb") # noqa: SIM115 - closed by the timer below
release = threading.Timer(0.2, held.close)
release.start()
Expand All @@ -176,10 +176,10 @@ def test_a_save_waits_out_something_holding_the_file_for_a_moment(tmp_path):

def test_a_file_held_for_good_still_fails_and_keeps_the_old_settings(tmp_path, monkeypatch):
path = tmp_path / "config.json"
old = AppConfig.from_dict({**default_config().to_dict(), "host": "10.0.0.5"})
old = AppConfig.from_dict({**default_config().to_dict(), "host": "192.0.2.5"})
save_config(old, path)
monkeypatch.setattr(config_module, "SAVE_RETRY_SECONDS", 0.01)
new = AppConfig.from_dict({**default_config().to_dict(), "host": "192.168.1.9"})
new = AppConfig.from_dict({**default_config().to_dict(), "host": "198.51.100.9"})

with open(path, "rb"), pytest.raises(PermissionError):
save_config(new, path)
Expand Down Expand Up @@ -237,7 +237,7 @@ def test_to_loggable_dict_excludes_the_password_and_the_network_address():
# --- building settings from what a form holds ---

FORM = {
"host": " 10.0.0.2 ",
"host": " 192.0.2.2 ",
"port": " 4455 ",
"password": " pass ",
"scene_item_name": " Overlay ",
Expand All @@ -255,7 +255,7 @@ def test_a_filled_in_form_becomes_settings():
cfg = config_from_form(**FORM)

assert cfg == AppConfig(
host="10.0.0.2",
host="192.0.2.2",
port=4455,
password=" pass ",
scene_item_name="Overlay",
Expand Down Expand Up @@ -368,7 +368,7 @@ def test_checking_for_updates_is_on_unless_turned_off(tmp_path):
({"auto_connect": True}, False),
({"check_updates": False}, False),
({"hotkey": "M"}, True),
({"host": "10.0.0.9"}, True),
({"host": "192.0.2.9"}, True),
({"log_enabled": True}, True),
({"auto_reconnect": False}, True),
],
Expand Down
12 changes: 6 additions & 6 deletions tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

def make_config(**overrides):
values = {
"host": "10.0.0.2",
"host": "192.0.2.2",
"port": 4455,
"password": "",
"scene_item_name": "Overlay",
Expand Down Expand Up @@ -482,7 +482,7 @@ def test_the_test_button_is_passed_to_the_worker(h):
assert h.service.manual_inputs == [True, False]


def run_check(h, check, host="10.0.0.2", port="4455", source=" Overlay "):
def run_check(h, check, host="192.0.2.2", port="4455", source=" Overlay "):
results = []
controller = AppController(schedule=h.schedule, service=h.service, check=check)
started = controller.check_connection(host, port, "pw", source, results.append)
Expand All @@ -507,7 +507,7 @@ def check(host, port, password, source_name):
assert controller.checking_connection is True
finish_check(h, controller)

assert calls == [("10.0.0.2", 4455, "pw", "Overlay")]
assert calls == [("192.0.2.2", 4455, "pw", "Overlay")]
assert results == [ConnectionCheck(ok=True, source_scene_count=2)]
assert controller.checking_connection is False

Expand All @@ -516,15 +516,15 @@ def test_a_connection_check_with_an_unusable_port_says_so_without_trying(h):
controller = AppController(schedule=h.schedule, service=h.service, check=None)

with pytest.raises(ValueError, match="OBS Port must be a number."):
controller.check_connection("10.0.0.2", "44a5", "", "", lambda _result: None)
controller.check_connection("192.0.2.2", "44a5", "", "", lambda _result: None)
assert controller.checking_connection is False


def test_test_link_refuses_a_port_out_of_range_without_trying(h):
controller = AppController(schedule=h.schedule, service=h.service, check=None)

with pytest.raises(ValueError, match="between 1 and 65535"):
controller.check_connection("10.0.0.2", "70000", "", "", lambda _result: None)
controller.check_connection("192.0.2.2", "70000", "", "", lambda _result: None)
assert controller.checking_connection is False


Expand All @@ -536,7 +536,7 @@ def slow_check(*_args):
return ConnectionCheck(ok=True)

controller, results, _ = run_check(h, slow_check)
assert controller.check_connection("10.0.0.2", "4455", "", "", results.append) is False
assert controller.check_connection("192.0.2.2", "4455", "", "", results.append) is False

release.set()
finish_check(h, controller)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fieldlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_a_stop_after_an_unexpected_error_says_so():
def test_no_connection_line_ever_names_the_obs_address():
# The window may be captured on stream, so the streaming PC's address
# must not appear in it even if a message happens to mention it.
message = "Failed to connect to 192.168.1.42:4455"
message = "Failed to connect to 198.51.100.42:4455"
for code in (EVENT_CONNECTED, EVENT_CONNECT_FAILED, EVENT_LINK_LOST, EVENT_STOPPED):
assert "192.168" not in line(code, message).text

Expand Down
2 changes: 1 addition & 1 deletion tests/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_describe_exception_gives_type_message_and_place_without_the_home_folder
def test_describe_cause_names_the_underlying_failure_and_its_code():
try:
try:
raise ConnectionResetError(10054, "reset by peer, host 10.0.0.2")
raise ConnectionResetError(10054, "reset by peer, host 192.0.2.2")
except OSError as inner:
raise RuntimeError("outer") from inner
except RuntimeError as exc:
Expand Down
14 changes: 7 additions & 7 deletions tests/test_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_request_timeout_is_shorter_than_the_connect_timeout():

def test_connect_holds_the_long_timeout_then_shortens_the_socket(monkeypatch):
monkeypatch.setattr(obs, "ReqClient", FakeReqClient)
client = connect_obs("10.0.0.2", 4455, "pw")
client = connect_obs("192.0.2.2", 4455, "pw")
assert client.timeout == CONNECT_TIMEOUT
assert client.base_client.ws.timeout == REQUEST_TIMEOUT

Expand All @@ -56,7 +56,7 @@ def refuse(_value):
self.base_client.ws.settimeout = refuse

monkeypatch.setattr(obs, "ReqClient", Grumpy)
assert connect_obs("10.0.0.2", 4455, "pw") is not None
assert connect_obs("192.0.2.2", 4455, "pw") is not None


class RaisingClient:
Expand Down Expand Up @@ -124,7 +124,7 @@ def boom(**kwargs):

monkeypatch.setattr(obs, "ReqClient", boom)
with pytest.raises(expected):
connect_obs("10.0.0.2", 4455, "pw")
connect_obs("192.0.2.2", 4455, "pw")


# --- the one-off connection check ---------------------------------------------
Expand All @@ -139,7 +139,7 @@ def checked_obs():
def test_a_connection_check_counts_the_scenes_carrying_the_source():
fake = checked_obs()

result = obs.check_connection("10.0.0.2", 4455, "", "Overlay", connect=lambda *_: fake)
result = obs.check_connection("192.0.2.2", 4455, "", "Overlay", connect=lambda *_: fake)

assert result == ConnectionCheck(ok=True, source_scene_count=2)
assert fake.disconnected is True
Expand All @@ -148,7 +148,7 @@ def test_a_connection_check_counts_the_scenes_carrying_the_source():
def test_a_connection_check_without_a_source_name_only_connects():
fake = checked_obs()

result = obs.check_connection("10.0.0.2", 4455, "", "", connect=lambda *_: fake)
result = obs.check_connection("192.0.2.2", 4455, "", "", connect=lambda *_: fake)

assert result == ConnectionCheck(ok=True)
assert fake.calls == []
Expand All @@ -159,7 +159,7 @@ def test_a_failed_connection_check_gives_the_reason():
def refuse(*_args):
raise ObsAuthError(obs.OBS_BAD_PASSWORD)

result = obs.check_connection("10.0.0.2", 4455, "wrong", "Overlay", connect=refuse)
result = obs.check_connection("192.0.2.2", 4455, "wrong", "Overlay", connect=refuse)

assert result == ConnectionCheck(ok=False, message=obs.OBS_BAD_PASSWORD)

Expand All @@ -168,7 +168,7 @@ def test_a_check_that_fails_after_connecting_still_disconnects():
fake = checked_obs()
fake.rule("GetSceneList", raises=OBSSDKTimeoutError("timed out"))

result = obs.check_connection("10.0.0.2", 4455, "", "Overlay", connect=lambda *_: fake)
result = obs.check_connection("192.0.2.2", 4455, "", "Overlay", connect=lambda *_: fake)

assert result == ConnectionCheck(ok=False, message=obs.OBS_LINK_LOST)
assert fake.disconnected is True
10 changes: 5 additions & 5 deletions tests/test_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def at(ms):

def hold_config(hide_delay_ms=120):
return AppConfig(
host="10.0.0.2",
host="192.0.2.2",
port=4455,
password="",
scene_item_name="Overlay",
Expand Down Expand Up @@ -295,7 +295,7 @@ def fail_fast(host, port, password):
monkeypatch.setattr(overlay_module, "connect_obs", fail_fast)

cfg = AppConfig(
host="10.0.0.2",
host="192.0.2.2",
port=4455,
password="wrong",
scene_item_name="Overlay",
Expand Down Expand Up @@ -325,7 +325,7 @@ def fail_fast(host, port, password):
service = MapHideService()
service._running = True
cfg = AppConfig(
host="10.0.0.2",
host="192.0.2.2",
port=4455,
password="wrong",
scene_item_name="Overlay",
Expand Down Expand Up @@ -359,7 +359,7 @@ def fail_fast(host, port, password):
service = MapHideService()
service._running = True
cfg = AppConfig(
host="10.0.0.2",
host="192.0.2.2",
port=4455,
password="super secret",
scene_item_name="Overlay",
Expand All @@ -375,7 +375,7 @@ def fail_fast(host, port, password):
contents = (tmp_path / "maphide-debug.log").read_text(encoding="utf-8")
assert "Overlay" in contents
assert "hotkey=M" in contents
assert "10.0.0.2" not in contents
assert "192.0.2.2" not in contents
assert "super secret" not in contents


Expand Down
32 changes: 16 additions & 16 deletions tests/test_qt_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def h():


def fill_form(backend, **values):
defaults = {"host": "10.0.0.2", "port": "4455", "scene_item_name": "Overlay"}
defaults = {"host": "192.0.2.2", "port": "4455", "scene_item_name": "Overlay"}
for name, value in {**defaults, **values}.items():
backend.setField(name, value)

Expand All @@ -118,9 +118,9 @@ def save_form(backend, **values):


def test_loading_fills_the_form_from_the_saved_settings(h):
h.load(lambda: make_config(host="10.0.0.9", port=4456))
h.load(lambda: make_config(host="192.0.2.9", port=4456))

assert h.backend.form["host"] == "10.0.0.9"
assert h.backend.form["host"] == "192.0.2.9"
assert h.backend.form["port"] == "4456"


Expand All @@ -139,21 +139,21 @@ def run_scheduled(h):


def test_connect_on_startup_starts_maphide_with_the_saved_settings(h):
h.load(lambda: make_config(host="10.0.0.9", auto_connect=True, check_updates=False))
h.load(lambda: make_config(host="192.0.2.9", auto_connect=True, check_updates=False))
assert h.service.started_with == []

run_scheduled(h)

assert [cfg.host for cfg in h.service.started_with] == ["10.0.0.9"]
assert [cfg.host for cfg in h.service.started_with] == ["192.0.2.9"]


def test_connect_on_startup_ignores_an_edit_made_before_it_starts(h):
h.load(lambda: make_config(host="10.0.0.9", auto_connect=True, check_updates=False))
fill_form(h.backend, host="10.0.0.5")
h.load(lambda: make_config(host="192.0.2.9", auto_connect=True, check_updates=False))
fill_form(h.backend, host="192.0.2.5")

run_scheduled(h)

assert [cfg.host for cfg in h.service.started_with] == ["10.0.0.9"]
assert [cfg.host for cfg in h.service.started_with] == ["192.0.2.9"]


def test_maphide_waits_for_start_when_connect_on_startup_is_off(h):
Expand Down Expand Up @@ -211,7 +211,7 @@ def test_saving_writes_the_form_and_says_so(h):

h.backend.save()

assert h.saved[-1].host == "10.0.0.2"
assert h.saved[-1].host == "192.0.2.2"
assert h.saves == [True]
assert h.lines[-1][1] == "> settings saved"

Expand Down Expand Up @@ -294,12 +294,12 @@ def test_start_ignores_and_never_saves_unsaved_changes(h):

def test_closing_settings_puts_the_saved_settings_back(h):
save_form(h.backend, hotkey="M")
h.backend.setField("host", "192.168.1.50")
h.backend.setField("host", "198.51.100.50")
h.backend.setField("hotkey", "K")

h.backend.discardChanges()

assert h.backend.form["host"] == "10.0.0.2"
assert h.backend.form["host"] == "192.0.2.2"
assert h.backend.form["hotkey"] == "M"
assert h.backend.hasUnsavedChanges is False

Expand Down Expand Up @@ -328,16 +328,16 @@ def test_a_change_counts_as_unsaved_until_saved(h):
def test_changing_a_field_back_is_not_an_unsaved_change(h):
save_form(h.backend)

h.backend.setField("host", "192.168.1.50")
h.backend.setField("host", "10.0.0.2")
h.backend.setField("host", "198.51.100.50")
h.backend.setField("host", "192.0.2.2")

assert h.backend.hasUnsavedChanges is False


def test_spaces_around_a_value_are_not_an_unsaved_change(h):
save_form(h.backend)

h.backend.setField("host", " 10.0.0.2 ")
h.backend.setField("host", " 192.0.2.2 ")

assert h.backend.hasUnsavedChanges is False

Expand All @@ -352,7 +352,7 @@ def test_a_captured_key_is_an_unsaved_change(h):

def test_reset_leaves_nothing_unsaved(h):
save_form(h.backend)
h.backend.setField("host", "192.168.1.50")
h.backend.setField("host", "198.51.100.50")

h.backend.resetDefaults()

Expand Down Expand Up @@ -396,7 +396,7 @@ def test_test_link_reports_the_scenes_carrying_the_source(h):
assert h.backend.testState == "busy"
h.run_check()

assert h.checks == [("10.0.0.2", 4455, "", "Overlay")]
assert h.checks == [("192.0.2.2", 4455, "", "Overlay")]
assert h.backend.testState == "ok"
assert h.backend.sourceText == f"Found in 3 scenes. {SOURCE_FOLLOWS}"

Expand Down
Loading