diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-06-24 10:26:46 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-06-24 10:26:46 +0200 |
commit | 4b9ddfb85b4758fba6fd792b8e96d5555c5b09e5 (patch) | |
tree | c18cae97dcb05dd73c30045caceca3cf6ecca0d9 | |
parent | 82203682e7b4e8926f5083b9bdfc6545697e8e59 (diff) | |
download | qutebrowser-4b9ddfb85b4758fba6fd792b8e96d5555c5b09e5.tar.gz qutebrowser-4b9ddfb85b4758fba6fd792b8e96d5555c5b09e5.zip |
tests: Simplify some open() calls
-rw-r--r-- | tests/end2end/test_mhtml_e2e.py | 4 | ||||
-rw-r--r-- | tests/unit/components/test_adblock.py | 2 | ||||
-rw-r--r-- | tests/unit/javascript/test_greasemonkey.py | 3 |
3 files changed, 3 insertions, 6 deletions
diff --git a/tests/end2end/test_mhtml_e2e.py b/tests/end2end/test_mhtml_e2e.py index 5da9602ae..faf4127d7 100644 --- a/tests/end2end/test_mhtml_e2e.py +++ b/tests/end2end/test_mhtml_e2e.py @@ -66,9 +66,7 @@ class DownloadDir: def read_file(self): files = self._tmpdir.listdir() assert len(files) == 1 - - with open(str(files[0]), 'r', encoding='utf-8') as f: - return f.readlines() + return files[0].read_text(encoding='utf-8').splitlines() def sanity_check_mhtml(self): assert 'Content-Type: multipart/related' in '\n'.join(self.read_file()) diff --git a/tests/unit/components/test_adblock.py b/tests/unit/components/test_adblock.py index 8dbd0ce29..6ee236765 100644 --- a/tests/unit/components/test_adblock.py +++ b/tests/unit/components/test_adblock.py @@ -96,7 +96,7 @@ def create_blocklist(directory, blocked_hosts=BLOCKLIST_HOSTS, 'not_correct' --> Not a correct hosts file format. """ blocklist_file = directory / name - with open(str(blocklist_file), 'w', encoding='UTF-8') as blocklist: + with blocklist_file.open('w', encoding='UTF-8') as blocklist: # ensure comments are ignored when processing blocklist blocklist.write('# Blocked Hosts List #\n\n') if line_format == 'etc_hosts': # /etc/hosts like format diff --git a/tests/unit/javascript/test_greasemonkey.py b/tests/unit/javascript/test_greasemonkey.py index 26da7e342..c066ab479 100644 --- a/tests/unit/javascript/test_greasemonkey.py +++ b/tests/unit/javascript/test_greasemonkey.py @@ -230,8 +230,7 @@ def test_required_scripts_are_included(download_stub, tmpdir): console.log("Script is running."); """) _save_script(test_require_script, 'requiring.user.js') - with open(str(tmpdir / 'test.js'), 'w', encoding='UTF-8') as f: - f.write("REQUIRED SCRIPT") + (tmpdir / 'test.js').write_text('REQUIRED SCRIPT', encoding='UTF-8') gm_manager = greasemonkey.GreasemonkeyManager() assert len(gm_manager._in_progress_dls) == 1 |