def test_view(platform, Popen, startfile): # noqa: N803 if platform == 'nonplatform': with pytest.raises(RuntimeError, match=r'platform'): view('nonfilepath') else: view('nonfilepath') if platform == 'darwin': Popen.assert_called_once_with(['open', 'nonfilepath']) elif platform in ('linux', 'freebsd'): Popen.assert_called_once_with(['xdg-open', 'nonfilepath']) elif platform == 'windows': startfile.assert_called_once_with('nonfilepath') else: raise RuntimeError
def test_view(mocker, py2, mock_platform, Popen, startfile, quiet): # noqa: N803 if quiet and py2: open_ = mocker.patch('__builtin__.open', mocker.mock_open()) assert view('nonfilepath', quiet=quiet) is None if mock_platform == 'windows': startfile.assert_called_once_with('nonfilepath') return if quiet and py2: open_.assert_called_once_with(os.devnull, 'w') kwargs = {'stderr': open_.return_value} elif quiet: kwargs = {'stderr': subprocess.DEVNULL} else: kwargs = {} if mock_platform == 'darwin': Popen.assert_called_once_with(['open', 'nonfilepath'], **kwargs) elif mock_platform in ('linux', 'freebsd'): Popen.assert_called_once_with(['xdg-open', 'nonfilepath'], **kwargs) else: raise RuntimeError
def test_view(platform, Popen, startfile): # noqa: N803 assert view('nonfilepath') is None if platform == 'darwin': Popen.assert_called_once_with(['open', 'nonfilepath']) elif platform in ('linux', 'freebsd'): Popen.assert_called_once_with(['xdg-open', 'nonfilepath']) elif platform == 'windows': startfile.assert_called_once_with('nonfilepath') else: raise RuntimeError
def test_view(mocker, mock_platform, Popen, startfile, quiet): # noqa: N803 assert view('nonfilepath', quiet=quiet) is None if mock_platform == 'windows': startfile.assert_called_once_with('nonfilepath') return if quiet: kwargs = {'stderr': subprocess.DEVNULL} else: kwargs = {} if mock_platform == 'darwin': Popen.assert_called_once_with(['open', 'nonfilepath'], **kwargs) elif mock_platform in ('linux', 'freebsd'): Popen.assert_called_once_with(['xdg-open', 'nonfilepath'], **kwargs) else: raise RuntimeError
def test_view_unknown_platform(unknown_platform): with pytest.raises(RuntimeError, match=r'platform'): view('nonfilepath')
def view(self): tmp = tempfile.gettempdir() svgfilename = f"{tmp}/DTreeViz_{getpid()}.svg" self.save(svgfilename) view(svgfilename)
def view(self): svgfilename = self.save_svg() view(svgfilename)