def test_system_default_application(self, caplog, config_stub, openurl_mock): utils.open_file('/foo/bar') result = caplog.messages[0] assert re.fullmatch( r"Opening /foo/bar with the system application", result) openurl_mock.assert_called_with(QUrl('file:///foo/bar'))
def test_cmdline_with_argument(self, caplog, config_stub): executable = shlex.quote(sys.executable) cmdline = '{} -c pass {{}} raboof'.format(executable) utils.open_file('/foo/bar', cmdline) result = caplog.messages[0] assert re.fullmatch( r"Opening /foo/bar with \[.*python.*/foo/bar.*'raboof'\]", result)
def test_cmdline_without_argument(self, caplog, config_stub): executable = shlex.quote(sys.executable) cmdline = '{} -c pass'.format(executable) utils.open_file('/foo/bar', cmdline) result = caplog.messages[0] assert re.fullmatch( r'Opening /foo/bar with \[.*python.*/foo/bar.*\]', result)
def test_cmdline_with_argument(self, caplog, config_stub): executable = shlex.quote(sys.executable) cmdline = '{} -c pass {{}} raboof'.format(executable) utils.open_file('/foo/bar', cmdline) result = caplog.records[0].message assert re.fullmatch( r"Opening /foo/bar with \[.*python.*/foo/bar.*'raboof'\]", result)
def test_cmdline_without_argument(self, caplog, config_stub): executable = shlex.quote(sys.executable) cmdline = '{} -c pass'.format(executable) utils.open_file('/foo/bar', cmdline) result = caplog.records[0].message assert re.match( r'Opening /foo/bar with \[.*python.*/foo/bar.*\]', result)
def test_cmdline_with_argument(self, caplog, config_stub): config_stub.data = {'general': {'default-open-dispatcher': ''}} executable = shlex.quote(sys.executable) cmdline = '{} -c pass {{}} raboof'.format(executable) utils.open_file('/foo/bar', cmdline) result = caplog.records[0].message assert re.match( r"Opening /foo/bar with \[.*python.*/foo/bar.*'raboof'\]", result)
def test_system_default_application(self, caplog, config_stub, mocker): m = mocker.patch('PyQt5.QtGui.QDesktopServices.openUrl', spec={}, new_callable=mocker.Mock) utils.open_file('/foo/bar') result = caplog.messages[0] assert re.fullmatch( r"Opening /foo/bar with the system application", result) m.assert_called_with(QUrl('file:///foo/bar'))
def test_setting_override(self, caplog, config_stub): executable = shlex.quote(sys.executable) cmdline = '{} -c pass'.format(executable) config_stub.val.downloads.open_dispatcher = cmdline utils.open_file('/foo/bar') result = caplog.messages[1] assert re.fullmatch( r"Opening /foo/bar with \[.*python.*/foo/bar.*\]", result)
def test_setting_override(self, caplog, config_stub): executable = shlex.quote(sys.executable) cmdline = '{} -c pass'.format(executable) config_stub.data = {'general': {'default-open-dispatcher': cmdline}} utils.open_file('/foo/bar') result = caplog.records[0].message assert re.match(r"Opening /foo/bar with \[.*python.*/foo/bar.*\]", result)
def test_system_default_application(self, caplog, config_stub, mocker): m = mocker.patch('PyQt5.QtGui.QDesktopServices.openUrl', spec={}, new_callable=mocker.Mock) utils.open_file('/foo/bar') result = caplog.records[0].message assert re.fullmatch( r"Opening /foo/bar with the system application", result) m.assert_called_with(QUrl('file:///foo/bar'))
def test_setting_override(self, caplog, config_stub): executable = shlex.quote(sys.executable) cmdline = '{} -c pass'.format(executable) config_stub.val.downloads.open_dispatcher = cmdline utils.open_file('/foo/bar') result = caplog.records[1].message assert re.fullmatch( r"Opening /foo/bar with \[.*python.*/foo/bar.*\]", result)
def test_setting_override(self, caplog, config_stub): executable = shlex.quote(sys.executable) cmdline = '{} -c pass'.format(executable) config_stub.data = {'general': {'default-open-dispatcher': cmdline}} utils.open_file('/foo/bar') result = caplog.records[0].message assert re.match( r"Opening /foo/bar with \[.*python.*/foo/bar.*\]", result)
def test_system_default_application(self, caplog, config_stub, mocker): config_stub.data = {'general': {'default-open-dispatcher': ''}} m = mocker.patch('PyQt5.QtGui.QDesktopServices.openUrl', spec={}, new_callable=mocker.Mock) utils.open_file('/foo/bar') result = caplog.records[0].message assert re.match( r"Opening /foo/bar with the system application", result) m.assert_called_with(QUrl('file:///foo/bar'))
def test_setting_override_sandboxed(self, fake_flatpak, openurl_mock, caplog, config_stub): config_stub.val.downloads.open_dispatcher = 'test' with caplog.at_level(logging.WARNING): utils.open_file('/foo/bar') assert caplog.messages[1] == ('Ignoring download dispatcher from ' 'config in sandbox environment') openurl_mock.assert_called_with(QUrl('file:///foo/bar'))
def test_cmdline_sandboxed(self, fake_flatpak, config_stub, message_mock, caplog): with caplog.at_level(logging.ERROR): utils.open_file('/foo/bar', 'custom_cmd') msg = message_mock.getmsg(usertypes.MessageLevel.error) assert msg.text == 'Cannot spawn download dispatcher from sandbox'
def test_system_default_sandboxed(self, config_stub, openurl_mock, fake_flatpak): utils.open_file('/foo/bar') openurl_mock.assert_called_with(QUrl('file:///foo/bar'))