Skip tests with permission changes if they didn't work

This e.g. wouldn't work inside of a Docker container otherwise.
This commit is contained in:
Florian Bruhin 2017-07-03 09:40:39 +02:00
parent 2f26490536
commit 3b53ec1cb6
3 changed files with 19 additions and 4 deletions

View File

@ -579,9 +579,9 @@ Feature: Downloading things from a website.
And I wait until the download is finished
Then the downloaded file content-size should exist
@posix
Scenario: Downloading to unwritable destination
When I set storage -> prompt-download-directory to false
When the unwritable dir is unwritable
And I set storage -> prompt-download-directory to false
And I run :download http://localhost:(port)/data/downloads/download.bin --dest (tmpdir)/downloads/unwritable
Then the error "Download error: Permission denied" should be shown

View File

@ -21,6 +21,7 @@ import os
import sys
import shlex
import pytest
import pytest_bdd as bdd
bdd.scenarios('downloads.feature')
@ -53,6 +54,14 @@ def clean_old_downloads(quteproc):
quteproc.send_cmd(':download-clear')
@bdd.when("the unwritable dir is unwritable")
def check_unwritable(tmpdir):
unwritable = tmpdir / 'downloads' / 'unwritable'
if os.access(str(unwritable), os.W_OK):
# Docker container or similar
pytest.skip("Unwritable dir was writable")
@bdd.when("I wait until the download is finished")
def wait_for_download_finished(quteproc):
quteproc.wait_for(category='downloads', message='Download * finished')

View File

@ -123,24 +123,30 @@ class TestFileHandling:
os.remove(filename)
@pytest.mark.posix
def test_unreadable(self, message_mock, editor, caplog):
"""Test file handling when closing with an unreadable file."""
editor.edit("")
filename = editor._file.name
assert os.path.exists(filename)
os.chmod(filename, 0o077)
if os.access(filename, os.R_OK):
# Docker container or similar
pytest.skip("File was still readable")
with caplog.at_level(logging.ERROR):
editor._proc.finished.emit(0, QProcess.NormalExit)
assert not os.path.exists(filename)
msg = message_mock.getmsg(usertypes.MessageLevel.error)
assert msg.text.startswith("Failed to read back edited file: ")
@pytest.mark.posix
def test_unwritable(self, monkeypatch, message_mock, editor, tmpdir,
caplog):
"""Test file handling when the initial file is not writable."""
tmpdir.chmod(0)
if os.access(str(tmpdir), os.W_OK):
# Docker container or similar
pytest.skip("File was still writable")
monkeypatch.setattr(editormod.tempfile, 'tempdir', str(tmpdir))
with caplog.at_level(logging.ERROR):