Fix unittests

This commit is contained in:
Rebecca Breu 2021-05-14 14:03:44 +02:00
parent 6a9605694e
commit f7c0b3078e
3 changed files with 8 additions and 5 deletions

View file

@ -40,7 +40,7 @@ class BeeSettingsRecentFilesTestCase(BeeTestCase):
self.settings.get_recent_files() == []
def test_get_existing_only(self):
with tempfile.NamedTemporaryFile() as f:
with tempfile.NamedTemporaryFile(mode='r') as f:
self.settings.update_recent_files('foo.bee')
self.settings.update_recent_files(f.name)
self.settings.get_recent_files(existing_only=True) == [f.name]

View file

@ -1,3 +1,4 @@
import logging
import os.path
import pytest
import tempfile
@ -36,13 +37,14 @@ def test_round_to(number, base, expected):
assert utils.round_to(number, base) == expected
class BeeRotatingFileHandler(BeeTestCase):
class BeeRotatingFileHandlerTestCase(BeeTestCase):
def test_creates_new_dir(self):
with tempfile.TemporaryDirectory() as tmpdir:
logfile = os.path.join(tmpdir, 'foo', 'bar.log')
handler = utils.BeeRotatingFileHandler(logfile)
handler.emit('foo')
handler.emit(logging.LogRecord(
'foo', logging.INFO, 'bar', 66, 'baz', [], None))
handler.close()
assert os.path.exists(logfile)
@ -50,6 +52,7 @@ class BeeRotatingFileHandler(BeeTestCase):
with tempfile.TemporaryDirectory() as tmpdir:
logfile = os.path.join(tmpdir, 'bar.log')
handler = utils.BeeRotatingFileHandler(logfile)
handler.emit('foo')
handler.emit(logging.LogRecord(
'foo', logging.INFO, 'bar', 66, 'baz', [], None))
handler.close()
assert os.path.exists(logfile)

View file

@ -286,7 +286,7 @@ class BeeGraphicsViewTestCase(ViewBaseTestCase):
@patch('beeref.gui.DebugLogDialog.show')
def test_on_action_debuglog(self, show_mock):
with tempfile.NamedTemporaryFile() as f:
with tempfile.NamedTemporaryFile(mode='r') as f:
with patch('beeref.gui.logfile_name', return_value=f.name):
self.view.on_action_debuglog()
show_mock.assert_called_once()