Ver código fonte

Changed screenshot location

Efren Yevale Varela 1 mês atrás
pai
commit
7982b071c5
3 arquivos alterados com 11 adições e 4 exclusões
  1. 1 0
      .gitignore
  2. 4 2
      src/stt_daemon/tui/app.py
  3. 6 2
      tests/test_tui_app.py

+ 1 - 0
.gitignore

@@ -12,6 +12,7 @@ models/
 .pytest_cache/
 config.toml
 questions.json
+screenshots/
 *.egg-info/
 .eggs/
 dist/

+ 4 - 2
src/stt_daemon/tui/app.py

@@ -256,13 +256,15 @@ class AssistantTUI(App):
 
     def action_screenshot(self) -> None:
         name = "stt-tui-%s.svg" % datetime.now().strftime("%Y%m%d-%H%M%S")
+        out_dir = "screenshots"
         try:
+            os.makedirs(out_dir, exist_ok=True)
             save = getattr(self, "save_screenshot", None)
             if callable(save):
-                path = save(name)
+                path = save(name, path=out_dir)
             else:
                 svg = self.export_screenshot()
-                path = os.path.join(os.getcwd(), name)
+                path = os.path.join(out_dir, name)
                 with open(path, "w", encoding="utf-8") as f:
                     f.write(svg)
         except Exception as e:

+ 6 - 2
tests/test_tui_app.py

@@ -1054,6 +1054,10 @@ def test_screenshot_saves_svg(server, tmp_path, monkeypatch):
             await pilot.pause()
 
     asyncio.run(scenario())
-    files = glob.glob(str(tmp_path / "stt-tui-*.svg"))
-    assert files, "no stt-tui-*.svg found in %s" % tmp_path
+    out_dir = tmp_path / "screenshots"
+    assert out_dir.is_dir(), "screenshots/ not created in %s" % tmp_path
+    files = glob.glob(str(out_dir / "stt-tui-*.svg"))
+    assert files, "no stt-tui-*.svg found in %s" % out_dir
     assert os.path.getsize(files[0]) > 0
+    assert glob.glob(str(tmp_path / "stt-tui-*.svg")) == [], \
+        "screenshot leaked into %s instead of screenshots/" % tmp_path