|
1 | 1 | from unittest.mock import patch |
2 | 2 |
|
3 | | - |
4 | 3 | def test_ensure_api_key_env(monkeypatch): |
5 | | -<<<<<<< HEAD |
6 | 4 | monkeypatch.setenv("SERPAPI_KEY","secret") |
7 | | - from src.main import ensure_api_key |
8 | | - assert ensure_api_key()=="secret" |
9 | | - |
10 | | -def test_ensure_api_key_prompt(tmp_path, monkeypatch): |
11 | | - monkeypatch.setenv("APPDATA", str(tmp_path)) |
12 | | - from src.main import ensure_api_key |
13 | | -======= |
14 | | - monkeypatch.setenv("SERPAPI_KEY", "secret") |
15 | | - from main import ensure_api_key |
16 | | - |
| 5 | + from src.app_gui import ensure_api_key |
17 | 6 | assert ensure_api_key() == "secret" |
18 | 7 |
|
19 | | - |
20 | 8 | def test_ensure_api_key_prompt(tmp_path, monkeypatch): |
| 9 | + monkeypatch.delenv("SERPAPI_KEY", raising=False) |
21 | 10 | monkeypatch.setenv("APPDATA", str(tmp_path)) |
22 | | - from main import ensure_api_key |
23 | | - |
24 | | ->>>>>>> e772c4167010570baed9b34907b8a8834fe77e81 |
25 | | - with patch("ginio.simpledialog.askstring", return_value="abc"): |
26 | | - key = ensure_api_key() |
27 | | - assert key == "abc" |
28 | | - |
| 11 | + from src.app_gui import ensure_api_key |
| 12 | + with patch("src.app_gui.simpledialog.askstring", return_value="abc"): |
| 13 | + assert ensure_api_key() == "abc" |
29 | 14 |
|
30 | 15 | def test_start_calls_run_without_threading(monkeypatch): |
31 | | -<<<<<<< HEAD |
32 | 16 | import src.app_gui as g |
33 | | -======= |
34 | | - import app_gui as g |
35 | | - |
36 | | ->>>>>>> e772c4167010570baed9b34907b8a8834fe77e81 |
37 | 17 | g.build_ui() |
38 | | - g.entry_query.delete(0, "end") |
39 | | - g.entry_query.insert(0, "kawa") |
40 | | - monkeypatch.setenv("SERPAPI_KEY", "x") |
| 18 | + g.entry_query.delete(0,'end'); g.entry_query.insert(0,"kawa") |
| 19 | + monkeypatch.setenv("SERPAPI_KEY","x") |
41 | 20 |
|
42 | 21 | class DummyThread: |
43 | | - def __init__(self, target, daemon): |
44 | | - self.target = target |
45 | | - |
46 | | - def start(self): |
47 | | - self.target() |
48 | | - |
49 | | - monkeypatch.setattr("ginio_gui.threading.Thread", DummyThread) |
50 | | - monkeypatch.setattr( |
51 | | - "ginio_gui.run", |
52 | | - lambda q: [ |
53 | | - {"url": "u", "title": "t", "emails": [], "phones": [], "contact_url": None} |
54 | | - ], |
55 | | - ) |
| 22 | + def __init__(self, target, daemon): self.target = target |
| 23 | + def start(self): self.target() |
| 24 | + |
| 25 | + monkeypatch.setattr("src.app_gui.threading.Thread", DummyThread) |
| 26 | + monkeypatch.setattr(g.root, "after", lambda ms, fn: fn(), raising=False) |
| 27 | + |
| 28 | + async def fake_run(q): |
| 29 | + return [{"url":"u","title":"t","emails":[],"phones":[],"contact_url":None}] |
| 30 | + monkeypatch.setattr("src.app_gui.run", fake_run) |
| 31 | + |
56 | 32 | with patch.object(g, "messagebox"): |
57 | 33 | g.start() |
58 | 34 | assert g.btn_start["state"] == "normal" |
59 | 35 | assert "OK — zapisano" in g.status.get() |
| 36 | + |
0 commit comments