Fix ipc test coverage

This commit is contained in:
Florian Bruhin 2017-07-09 22:09:31 +02:00
parent 6c0ceeac7f
commit bb567a61b6
2 changed files with 12 additions and 5 deletions

View File

@ -51,7 +51,7 @@ def _get_socketname_windows(basedir):
def _get_socketname(basedir):
"""Get a socketname to use."""
if os.name == 'nt':
if os.name == 'nt': # pragma: no cover
return _get_socketname_windows(basedir)
parts_to_hash = [getpass.getuser()]

View File

@ -186,19 +186,26 @@ class TestSocketName:
('/x', 'ipc-{}'.format(md5('testusername-/x'))),
]
WINDOWS_TESTS = [
(None, 'qutebrowser-testusername'),
('/x', 'qutebrowser-testusername-{}'.format(md5('/x'))),
]
@pytest.fixture(autouse=True)
def patch_user(self, monkeypatch):
monkeypatch.setattr(ipc.getpass, 'getuser', lambda: 'testusername')
@pytest.mark.parametrize('basedir, expected', [
(None, 'qutebrowser-testusername'),
('/x', 'qutebrowser-testusername-{}'.format(md5('/x'))),
])
@pytest.mark.parametrize('basedir, expected', WINDOWS_TESTS)
@pytest.mark.windows
def test_windows(self, basedir, expected):
socketname = ipc._get_socketname(basedir)
assert socketname == expected
@pytest.mark.parametrize('basedir, expected', WINDOWS_TESTS)
def test_windows_on_posix(self, basedir, expected):
socketname = ipc._get_socketname_windows(basedir)
assert socketname == expected
@pytest.mark.mac
@pytest.mark.parametrize('basedir, expected', POSIX_TESTS)
def test_mac(self, basedir, expected):