File: test_viewing.py

package info (click to toggle)
python-graphviz 0.20.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,188 kB
  • sloc: python: 4,098; makefile: 13
file content (31 lines) | stat: -rw-r--r-- 885 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import subprocess

import pytest

import graphviz


@pytest.mark.usefixtures('unknown_platform')
def test_view_unknown_platform():
    with pytest.raises(RuntimeError, match=r'platform'):
        graphviz.view('nonfilepath')


def test_view_mocked(mocker, mock_platform, mock_popen, mock_startfile, quiet):
    assert graphviz.view('nonfilepath', quiet=quiet) is None

    if mock_platform == 'windows':
        mock_startfile.assert_called_once_with('nonfilepath')
        return

    if quiet:
        kwargs = {'stderr': subprocess.DEVNULL}
    else:
        kwargs = {}

    if mock_platform == 'darwin':
        mock_popen.assert_called_once_with(['open', 'nonfilepath'], **kwargs)
    elif mock_platform in ('linux', 'freebsd'):
        mock_popen.assert_called_once_with(['xdg-open', 'nonfilepath'], **kwargs)
    else:
        raise RuntimeError