diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-03-18 19:28:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-18 19:28:57 +0100 |
commit | f439e1644e27c629df000532dc58af653a4eac02 (patch) | |
tree | bb75bc5961055fab779c03fcb2eef0ef6b9b8b31 | |
parent | 6f567aff4aa5720db42a4fc3d4744c79615ad6b2 (diff) | |
parent | 880dd82be811baa34c5d390caf5796b869b2ab64 (diff) | |
download | qutebrowser-f439e1644e27c629df000532dc58af653a4eac02.tar.gz qutebrowser-f439e1644e27c629df000532dc58af653a4eac02.zip |
Merge pull request #6250 from Lembrun/pathlib-/unit/javascript
Pathlib /unit/javascript
-rw-r--r-- | tests/unit/javascript/conftest.py | 15 | ||||
-rw-r--r-- | tests/unit/javascript/stylesheet/test_stylesheet_js.py | 6 | ||||
-rw-r--r-- | tests/unit/javascript/test_greasemonkey.py | 4 |
3 files changed, 12 insertions, 13 deletions
diff --git a/tests/unit/javascript/conftest.py b/tests/unit/javascript/conftest.py index 85d5ebe0a..4a7f09204 100644 --- a/tests/unit/javascript/conftest.py +++ b/tests/unit/javascript/conftest.py @@ -19,9 +19,7 @@ """pytest conftest file for javascript tests.""" -import os -import os.path - +import pathlib import pytest import jinja2 @@ -30,6 +28,8 @@ from PyQt5.QtCore import QUrl import qutebrowser from qutebrowser.utils import usertypes +JS_DIR = pathlib.Path(__file__).parent + class JSTester: @@ -44,7 +44,7 @@ class JSTester: def __init__(self, tab, qtbot, config_stub): self.tab = tab self.qtbot = qtbot - loader = jinja2.FileSystemLoader(os.path.dirname(__file__)) + loader = jinja2.FileSystemLoader(JS_DIR) self._jinja_env = jinja2.Environment(loader=loader, autoescape=True) # Make sure error logging via JS fails tests config_stub.val.content.javascript.log = { @@ -87,7 +87,7 @@ class JSTester: force: Whether to force loading even if the file is invalid. """ self.load_url(QUrl.fromLocalFile( - os.path.join(os.path.dirname(__file__), path)), force) + str(JS_DIR / path)), force) def load_url(self, url: QUrl, force: bool = False): """Load a given QUrl. @@ -109,9 +109,8 @@ class JSTester: path: The path to the JS file, relative to the qutebrowser package. expected: The value expected return from the javascript execution """ - base_path = os.path.dirname(os.path.abspath(qutebrowser.__file__)) - with open(os.path.join(base_path, path), 'r', encoding='utf-8') as f: - source = f.read() + base_path = pathlib.Path(qutebrowser.__file__).resolve().parent + source = (base_path / path).read_text(encoding='utf-8') self.run(source, expected) def run(self, source: str, expected=usertypes.UNSET, world=None) -> None: diff --git a/tests/unit/javascript/stylesheet/test_stylesheet_js.py b/tests/unit/javascript/stylesheet/test_stylesheet_js.py index 13ec85cd5..1eebe3b7f 100644 --- a/tests/unit/javascript/stylesheet/test_stylesheet_js.py +++ b/tests/unit/javascript/stylesheet/test_stylesheet_js.py @@ -19,7 +19,7 @@ """Tests for stylesheet.js.""" -import os +import pathlib import pytest QtWebEngineWidgets = pytest.importorskip("PyQt5.QtWebEngineWidgets") @@ -49,8 +49,8 @@ class StylesheetTester: def init_stylesheet(self, css_file="green.css"): """Initialize the stylesheet with a provided css file.""" - css_path = os.path.join(os.path.dirname(__file__), css_file) - self.config_stub.val.content.user_stylesheets = css_path + css_path = pathlib.Path(__file__).parent / css_file + self.config_stub.val.content.user_stylesheets = str(css_path) def set_css(self, css): """Set document style to `css` via stylesheet.js.""" diff --git a/tests/unit/javascript/test_greasemonkey.py b/tests/unit/javascript/test_greasemonkey.py index 3a3ea0294..2bfb9ca83 100644 --- a/tests/unit/javascript/test_greasemonkey.py +++ b/tests/unit/javascript/test_greasemonkey.py @@ -198,7 +198,7 @@ class TestForceDocumentEnd: assert script.needs_document_end_workaround() == force -def test_required_scripts_are_included(download_stub, tmpdir): +def test_required_scripts_are_included(download_stub, tmp_path): test_require_script = textwrap.dedent(""" // ==UserScript== // @name qutebrowser test userscript @@ -212,7 +212,7 @@ def test_required_scripts_are_included(download_stub, tmpdir): console.log("Script is running."); """) _save_script(test_require_script, 'requiring.user.js') - (tmpdir / 'test.js').write_text('REQUIRED SCRIPT', encoding='UTF-8') + (tmp_path / 'test.js').write_text('REQUIRED SCRIPT', encoding='UTF-8') gm_manager = greasemonkey.GreasemonkeyManager() assert len(gm_manager._in_progress_dls) == 1 |