Use shorter names.

The typical test path for a legacy FIFO was something like:

    /tmp/pytest-92/test_correct_socket_name0/qutebrowser_test/qutebrowser-ipc-dfc627b5be8602ea0e9cd258b73c0bc3

This is probably too long for a Unix local domain socket (104 chars max).
This commit is contained in:
Florian Bruhin 2015-09-08 22:14:39 +02:00
parent 4daa7e6979
commit 34bd000442
3 changed files with 29 additions and 30 deletions

View File

@ -98,7 +98,7 @@ def pytest_runtest_setup(item):
@pytest.fixture(autouse=True, scope='session') @pytest.fixture(autouse=True, scope='session')
def change_qapp_name(qapp): def change_qapp_name(qapp):
"""Change the name of the QApplication instance.""" """Change the name of the QApplication instance."""
qapp.setApplicationName('qutebrowser_test') qapp.setApplicationName('qute_test')
class WinRegistryHelper: class WinRegistryHelper:

View File

@ -43,7 +43,7 @@ Args = collections.namedtuple('Args', 'basedir')
@pytest.yield_fixture @pytest.yield_fixture
def ipc_server(qapp, qtbot): def ipc_server(qapp, qtbot):
server = ipc.IPCServer('qutebrowser-test') server = ipc.IPCServer('qute-test')
yield server yield server
if (server._socket is not None and if (server._socket is not None and
server._socket.state() != QLocalSocket.UnconnectedState): server._socket.state() != QLocalSocket.UnconnectedState):
@ -197,14 +197,14 @@ class TestSocketName:
def test_os_x(self, basedir, expected): def test_os_x(self, basedir, expected):
socketname = ipc._get_socketname(basedir) socketname = ipc._get_socketname(basedir)
parts = socketname.split(os.sep) parts = socketname.split(os.sep)
assert parts[-2] == 'qutebrowser_test' assert parts[-2] == 'qute_test'
assert parts[-1] == expected assert parts[-1] == expected
@pytest.mark.linux @pytest.mark.linux
@pytest.mark.parametrize('basedir, expected', POSIX_TESTS) @pytest.mark.parametrize('basedir, expected', POSIX_TESTS)
def test_linux(self, basedir, fake_runtime_dir, expected): def test_linux(self, basedir, fake_runtime_dir, expected):
socketname = ipc._get_socketname(basedir) socketname = ipc._get_socketname(basedir)
expected_path = str(fake_runtime_dir / 'qutebrowser_test' / expected) expected_path = str(fake_runtime_dir / 'qute_test' / expected)
assert socketname == expected_path assert socketname == expected_path
def test_other_unix(self): def test_other_unix(self):
@ -272,7 +272,7 @@ class TestListen:
def test_in_use(self, qlocalserver, ipc_server, monkeypatch): def test_in_use(self, qlocalserver, ipc_server, monkeypatch):
monkeypatch.setattr('qutebrowser.misc.ipc.QLocalServer.removeServer', monkeypatch.setattr('qutebrowser.misc.ipc.QLocalServer.removeServer',
lambda self: True) lambda self: True)
qlocalserver.listen('qutebrowser-test') qlocalserver.listen('qute-test')
with pytest.raises(ipc.AddressInUseError): with pytest.raises(ipc.AddressInUseError):
ipc_server.listen() ipc_server.listen()
@ -399,7 +399,7 @@ class TestHandleConnection:
def connected_socket(qtbot, qlocalsocket, ipc_server): def connected_socket(qtbot, qlocalsocket, ipc_server):
ipc_server.listen() ipc_server.listen()
with qtbot.waitSignal(ipc_server._server.newConnection, raising=True): with qtbot.waitSignal(ipc_server._server.newConnection, raising=True):
qlocalsocket.connectToServer('qutebrowser-test') qlocalsocket.connectToServer('qute-test')
yield qlocalsocket yield qlocalsocket
qlocalsocket.disconnectFromServer() qlocalsocket.disconnectFromServer()
@ -468,7 +468,7 @@ def test_multiline(qtbot, ipc_server, connected_socket):
class TestSendToRunningInstance: class TestSendToRunningInstance:
def test_no_server(self, caplog): def test_no_server(self, caplog):
sent = ipc.send_to_running_instance('qutebrowser-test', []) sent = ipc.send_to_running_instance('qute-test', [])
assert not sent assert not sent
msg = caplog.records()[-1].message msg = caplog.records()[-1].message
assert msg == "No existing instance present (error 2)" assert msg == "No existing instance present (error 2)"
@ -486,8 +486,7 @@ class TestSendToRunningInstance:
if not has_cwd: if not has_cwd:
m = mocker.patch('qutebrowser.misc.ipc.os') m = mocker.patch('qutebrowser.misc.ipc.os')
m.getcwd.side_effect = OSError m.getcwd.side_effect = OSError
sent = ipc.send_to_running_instance('qutebrowser-test', sent = ipc.send_to_running_instance('qute-test', ['foo'])
['foo'])
assert sent assert sent
@ -509,20 +508,20 @@ class TestSendToRunningInstance:
def test_socket_error(self): def test_socket_error(self):
socket = FakeSocket(error=QLocalSocket.ConnectionError) socket = FakeSocket(error=QLocalSocket.ConnectionError)
with pytest.raises(ipc.Error) as excinfo: with pytest.raises(ipc.Error) as excinfo:
ipc.send_to_running_instance('qutebrowser-test', [], socket=socket) ipc.send_to_running_instance('qute-test', [], socket=socket)
msg = "Error while writing to running instance: Error string (error 7)" msg = "Error while writing to running instance: Error string (error 7)"
assert str(excinfo.value) == msg assert str(excinfo.value) == msg
def test_not_disconnected_immediately(self): def test_not_disconnected_immediately(self):
socket = FakeSocket() socket = FakeSocket()
ipc.send_to_running_instance('qutebrowser-test', [], socket=socket) ipc.send_to_running_instance('qute-test', [], socket=socket)
def test_socket_error_no_server(self): def test_socket_error_no_server(self):
socket = FakeSocket(error=QLocalSocket.ConnectionError, socket = FakeSocket(error=QLocalSocket.ConnectionError,
connect_successful=False) connect_successful=False)
with pytest.raises(ipc.Error) as excinfo: with pytest.raises(ipc.Error) as excinfo:
ipc.send_to_running_instance('qutebrowser-test', [], socket=socket) ipc.send_to_running_instance('qute-test', [], socket=socket)
msg = ("Error while connecting to running instance: Error string " msg = ("Error while connecting to running instance: Error string "
"(error 7)") "(error 7)")
@ -534,7 +533,7 @@ def test_timeout(qtbot, caplog, qlocalsocket, ipc_server):
ipc_server.listen() ipc_server.listen()
with qtbot.waitSignal(ipc_server._server.newConnection, raising=True): with qtbot.waitSignal(ipc_server._server.newConnection, raising=True):
qlocalsocket.connectToServer('qutebrowser-test') qlocalsocket.connectToServer('qute-test')
with caplog.atLevel(logging.ERROR): with caplog.atLevel(logging.ERROR):
with qtbot.waitSignal(qlocalsocket.disconnected, raising=True): with qtbot.waitSignal(qlocalsocket.disconnected, raising=True):
@ -762,5 +761,5 @@ def test_connect_inexistant(qlocalsocket):
If this test fails, our connection logic checking for the old naming scheme If this test fails, our connection logic checking for the old naming scheme
would not work properly. would not work properly.
""" """
qlocalsocket.connectToServer('qutebrowser-test-inexistent') qlocalsocket.connectToServer('qute-test-inexistent')
assert qlocalsocket.error() == QLocalSocket.ServerNotFoundError assert qlocalsocket.error() == QLocalSocket.ServerNotFoundError

View File

@ -37,10 +37,10 @@ def change_qapp_name(qapp):
"""Change the name of the QApplication instance. """Change the name of the QApplication instance.
This changes the applicationName for all tests in this module to This changes the applicationName for all tests in this module to
"qutebrowser_test". "qute_test".
""" """
old_name = qapp.applicationName() old_name = qapp.applicationName()
qapp.setApplicationName('qutebrowser_test') qapp.setApplicationName('qute_test')
yield yield
qapp.setApplicationName(old_name) qapp.setApplicationName(old_name)
@ -112,48 +112,48 @@ class TestGetStandardDirLinux:
def test_data_explicit(self, monkeypatch, tmpdir): def test_data_explicit(self, monkeypatch, tmpdir):
"""Test data dir with XDG_DATA_HOME explicitly set.""" """Test data dir with XDG_DATA_HOME explicitly set."""
monkeypatch.setenv('XDG_DATA_HOME', str(tmpdir)) monkeypatch.setenv('XDG_DATA_HOME', str(tmpdir))
assert standarddir.data() == str(tmpdir / 'qutebrowser_test') assert standarddir.data() == str(tmpdir / 'qute_test')
def test_config_explicit(self, monkeypatch, tmpdir): def test_config_explicit(self, monkeypatch, tmpdir):
"""Test config dir with XDG_CONFIG_HOME explicitly set.""" """Test config dir with XDG_CONFIG_HOME explicitly set."""
monkeypatch.setenv('XDG_CONFIG_HOME', str(tmpdir)) monkeypatch.setenv('XDG_CONFIG_HOME', str(tmpdir))
assert standarddir.config() == str(tmpdir / 'qutebrowser_test') assert standarddir.config() == str(tmpdir / 'qute_test')
def test_cache_explicit(self, monkeypatch, tmpdir): def test_cache_explicit(self, monkeypatch, tmpdir):
"""Test cache dir with XDG_CACHE_HOME explicitly set.""" """Test cache dir with XDG_CACHE_HOME explicitly set."""
monkeypatch.setenv('XDG_CACHE_HOME', str(tmpdir)) monkeypatch.setenv('XDG_CACHE_HOME', str(tmpdir))
assert standarddir.cache() == str(tmpdir / 'qutebrowser_test') assert standarddir.cache() == str(tmpdir / 'qute_test')
def test_temp_explicit(self, monkeypatch, tmpdir): def test_temp_explicit(self, monkeypatch, tmpdir):
"""Test temp dir with TMPDIR explicitly set.""" """Test temp dir with TMPDIR explicitly set."""
monkeypatch.setenv('TMPDIR', str(tmpdir)) monkeypatch.setenv('TMPDIR', str(tmpdir))
assert standarddir.temp() == str(tmpdir / 'qutebrowser_test-user') assert standarddir.temp() == str(tmpdir / 'qute_test-user')
def test_data(self, monkeypatch, tmpdir): def test_data(self, monkeypatch, tmpdir):
"""Test data dir with XDG_DATA_HOME not set.""" """Test data dir with XDG_DATA_HOME not set."""
monkeypatch.setenv('HOME', str(tmpdir)) monkeypatch.setenv('HOME', str(tmpdir))
monkeypatch.delenv('XDG_DATA_HOME', raising=False) monkeypatch.delenv('XDG_DATA_HOME', raising=False)
expected = tmpdir / '.local' / 'share' / 'qutebrowser_test' expected = tmpdir / '.local' / 'share' / 'qute_test'
assert standarddir.data() == str(expected) assert standarddir.data() == str(expected)
def test_config(self, monkeypatch, tmpdir): def test_config(self, monkeypatch, tmpdir):
"""Test config dir with XDG_CONFIG_HOME not set.""" """Test config dir with XDG_CONFIG_HOME not set."""
monkeypatch.setenv('HOME', str(tmpdir)) monkeypatch.setenv('HOME', str(tmpdir))
monkeypatch.delenv('XDG_CONFIG_HOME', raising=False) monkeypatch.delenv('XDG_CONFIG_HOME', raising=False)
expected = tmpdir / '.config' / 'qutebrowser_test' expected = tmpdir / '.config' / 'qute_test'
assert standarddir.config() == str(expected) assert standarddir.config() == str(expected)
def test_cache(self, monkeypatch, tmpdir): def test_cache(self, monkeypatch, tmpdir):
"""Test cache dir with XDG_CACHE_HOME not set.""" """Test cache dir with XDG_CACHE_HOME not set."""
monkeypatch.setenv('HOME', str(tmpdir)) monkeypatch.setenv('HOME', str(tmpdir))
monkeypatch.delenv('XDG_CACHE_HOME', raising=False) monkeypatch.delenv('XDG_CACHE_HOME', raising=False)
expected = tmpdir / '.cache' / 'qutebrowser_test' expected = tmpdir / '.cache' / 'qute_test'
assert standarddir.cache() == expected assert standarddir.cache() == expected
def test_temp(self, monkeypatch, tmpdir): def test_temp(self, monkeypatch, tmpdir):
"""Test temp dir with TMPDIR not set.""" """Test temp dir with TMPDIR not set."""
monkeypatch.delenv('TMPDIR', raising=False) monkeypatch.delenv('TMPDIR', raising=False)
assert standarddir.temp().split(os.sep)[-1] == 'qutebrowser_test-user' assert standarddir.temp().split(os.sep)[-1] == 'qute_test-user'
@pytest.mark.windows @pytest.mark.windows
@ -164,20 +164,20 @@ class TestGetStandardDirWindows:
def test_data(self): def test_data(self):
"""Test data dir.""" """Test data dir."""
expected = ['qutebrowser_test', 'data'] expected = ['qute_test', 'data']
assert standarddir.data().split(os.sep)[-2:] == expected assert standarddir.data().split(os.sep)[-2:] == expected
def test_config(self): def test_config(self):
"""Test config dir.""" """Test config dir."""
assert standarddir.config().split(os.sep)[-1] == 'qutebrowser_test' assert standarddir.config().split(os.sep)[-1] == 'qute_test'
def test_cache(self): def test_cache(self):
"""Test cache dir.""" """Test cache dir."""
expected = ['qutebrowser_test', 'cache'] expected = ['qute_test', 'cache']
assert standarddir.cache().split(os.sep)[-2:] == expected assert standarddir.cache().split(os.sep)[-2:] == expected
def test_temp(self): def test_temp(self):
assert standarddir.temp().split(os.sep)[-1] == 'qutebrowser_test-user' assert standarddir.temp().split(os.sep)[-1] == 'qute_test-user'
DirArgTest = collections.namedtuple('DirArgTest', 'arg, expected') DirArgTest = collections.namedtuple('DirArgTest', 'arg, expected')
@ -223,7 +223,7 @@ class TestArguments:
"""Test --confdir with None given.""" """Test --confdir with None given."""
args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None) args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None)
standarddir.init(args) standarddir.init(args)
assert standarddir.config().split(os.sep)[-1] == 'qutebrowser_test' assert standarddir.config().split(os.sep)[-1] == 'qute_test'
def test_runtimedir(self, tmpdir, monkeypatch): def test_runtimedir(self, tmpdir, monkeypatch):
"""Test runtime dir (which has no args).""" """Test runtime dir (which has no args)."""
@ -232,7 +232,7 @@ class TestArguments:
lambda _typ: str(tmpdir)) lambda _typ: str(tmpdir))
args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None) args = types.SimpleNamespace(confdir=None, cachedir=None, datadir=None)
standarddir.init(args) standarddir.init(args)
assert standarddir.runtime() == str(tmpdir / 'qutebrowser_test') assert standarddir.runtime() == str(tmpdir / 'qute_test')
@pytest.mark.parametrize('typ', ['config', 'data', 'cache', 'download', @pytest.mark.parametrize('typ', ['config', 'data', 'cache', 'download',
'runtime']) 'runtime'])