GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add tests for opening log viewer · jerry-git/logplot@ed54bd9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tests
    • test_plot.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tests/test_plot.py‎

Copy file name to clipboard
+57-2Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
1+
from unittest.mock import MagicMock, patch
2+
import pytest
3+
4+
5+
from logplot.plot import Plot
6+
7+
8+
@pytest.fixture
9+
def mock_pyplot(monkeypatch):
10+
monkeypatch.setattr("logplot.plot.plt", MagicMock())
11+
12+
13+
@pytest.fixture
14+
def no_plot_initialise(monkeypatch):
15+
monkeypatch.setattr("logplot.plot.Plot._initialise", MagicMock())
16+
17+
18+
@pytest.mark.usefixtures("mock_pyplot", "no_plot_initialise")
19+
@patch("logplot.plot.sys")
120
class TestOpenLogViewer:
2-
# TODO
3-
pass
21+
# fmt: off
22+
@pytest.mark.parametrize(
23+
"open_cmd, shell, platform, log_path, expected",
24+
[
25+
("", False, "linux", "foo/bar/log.txt", ["xdg-open", "foo/bar/log.txt"]),
26+
("", False, "darwin", "foo/bar/log.txt", ["open", "foo/bar/log.txt"]),
27+
("custom_cmd '{path}'", True, "darwin", "/foo/bar space/log.txt",
28+
["custom_cmd", "/foo/bar space/log.txt"]),
29+
("custom_cmd '{path}':{line_number} ", True, "win32", "somewhere/log.txt",
30+
["custom_cmd", "somewhere/log.txt:99"])
31+
]
32+
)
33+
# fmt: on
34+
@patch("logplot.plot.subprocess.Popen")
35+
def test_it_passes_correct_params_to_popen(
36+
self, popen, sys_mock, open_cmd, shell, platform, log_path, expected
37+
):
38+
conf = MagicMock()
39+
conf.general.shell = shell
40+
conf.general.log_open_cmd = open_cmd
41+
sys_mock.platform = platform
42+
plot = Plot(entries=[], special_entries=[], log_path=log_path, conf=conf)
43+
44+
plot._open_log_viewer(line_number=99)
45+
46+
args, kwargs = popen.call_args
47+
assert args[0] == expected
48+
assert kwargs["shell"] == shell
49+
50+
@patch("logplot.plot.os")
51+
def test_it_calls_startfile_on_windows_as_default(self, os_mock, sys_mock):
52+
conf = MagicMock()
53+
conf.general.log_open_cmd = ''
54+
sys_mock.platform = "win32"
55+
plot = Plot(entries=[], special_entries=[], log_path="foo", conf=conf)
56+
57+
plot._open_log_viewer(line_number=99)
58+
os_mock.startfile.assert_called_with("foo")

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.