tests: fix tests for misc.editor

Due to the change to NamedTemporaryFile, the _filename attribute was
removed. We now have to use _file.name.
This commit is contained in:
Daniel Schadt 2016-08-07 00:18:22 +02:00
parent 9a4655443f
commit 4d00b8fce9

View File

@ -69,14 +69,14 @@ class TestArg:
config_stub.data['general']['editor'] = ['bin', 'foo', '{}', 'bar']
editor.edit("")
editor._proc._proc.start.assert_called_with(
"bin", ["foo", editor._filename, "bar"])
"bin", ["foo", editor._file.name, "bar"])
def test_placeholder_inline(self, config_stub, editor):
"""Test starting editor with placeholder arg inside of another arg."""
config_stub.data['general']['editor'] = ['bin', 'foo{}', 'bar']
editor.edit("")
editor._proc._proc.start.assert_called_with(
"bin", ["foo" + editor._filename, "bar"])
"bin", ["foo" + editor._file.name, "bar"])
class TestFileHandling:
@ -86,7 +86,7 @@ class TestFileHandling:
def test_ok(self, editor):
"""Test file handling when closing with an exit status == 0."""
editor.edit("")
filename = editor._filename
filename = editor._file.name
assert os.path.exists(filename)
assert os.path.basename(filename).startswith('qutebrowser-editor-')
editor._proc.finished.emit(0, QProcess.NormalExit)
@ -95,7 +95,7 @@ class TestFileHandling:
def test_error(self, editor):
"""Test file handling when closing with an exit status != 0."""
editor.edit("")
filename = editor._filename
filename = editor._file.name
assert os.path.exists(filename)
editor._proc._proc.exitStatus = mock.Mock(
@ -109,7 +109,7 @@ class TestFileHandling:
def test_crash(self, editor):
"""Test file handling when closing with a crash."""
editor.edit("")
filename = editor._filename
filename = editor._file.name
assert os.path.exists(filename)
editor._proc._proc.exitStatus = mock.Mock(
@ -125,7 +125,7 @@ class TestFileHandling:
def test_unreadable(self, message_mock, editor):
"""Test file handling when closing with an unreadable file."""
editor.edit("")
filename = editor._filename
filename = editor._file.name
assert os.path.exists(filename)
os.chmod(filename, 0o077)
editor._proc.finished.emit(0, QProcess.NormalExit)
@ -160,10 +160,10 @@ def test_modify(editor, initial_text, edited_text):
"""Test if inputs get modified correctly."""
editor.edit(initial_text)
with open(editor._filename, 'r', encoding='utf-8') as f:
with open(editor._file.name, 'r', encoding='utf-8') as f:
assert f.read() == initial_text
with open(editor._filename, 'w', encoding='utf-8') as f:
with open(editor._file.name, 'w', encoding='utf-8') as f:
f.write(edited_text)
editor._proc.finished.emit(0, QProcess.NormalExit)