diff --git a/tests/unit/javascript/conftest.py b/tests/unit/javascript/conftest.py index 3f0b412bf..29c69d360 100644 --- a/tests/unit/javascript/conftest.py +++ b/tests/unit/javascript/conftest.py @@ -27,6 +27,7 @@ import jinja2 from PyQt5.QtCore import QUrl +import qutebrowser from qutebrowser.utils import utils @@ -90,15 +91,16 @@ class JSTester: if not force: assert blocker.args == [True] - def run_file(self, filename: str, expected=None) -> None: + def run_file(self, path: str, expected=None) -> None: """Run a javascript file. Args: - filename: The javascript filename, relative to - qutebrowser/javascript. + path: The path to the JS file, relative to the qutebrowser package. expected: The value expected return from the javascript execution """ - source = utils.read_file(os.path.join('javascript', filename)) + 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() self.run(source, expected) def run(self, source: str, expected, world=None) -> None: diff --git a/tests/unit/javascript/position_caret/test_position_caret.py b/tests/unit/javascript/position_caret/test_position_caret.py index f6ff499ca..6b50e5f62 100644 --- a/tests/unit/javascript/position_caret/test_position_caret.py +++ b/tests/unit/javascript/position_caret/test_position_caret.py @@ -50,7 +50,7 @@ class CaretTester: def check(self): """Check whether the caret is before the MARKER text.""" - self.js.run_file('position_caret.js') + self.js.run_file('javascript/position_caret.js') self.js.tab.caret.toggle_selection() self.js.tab.caret.move_to_next_word() diff --git a/tests/unit/javascript/stylesheet/test_stylesheet.py b/tests/unit/javascript/stylesheet/test_stylesheet.py index 28c56f34c..768ffaeb9 100644 --- a/tests/unit/javascript/stylesheet/test_stylesheet.py +++ b/tests/unit/javascript/stylesheet/test_stylesheet.py @@ -131,6 +131,6 @@ def test_set_error(stylesheet_tester, config_stub): def test_appendchild(stylesheet_tester): stylesheet_tester.js.load('stylesheet/simple.html') stylesheet_tester.init_stylesheet() - js_test_file_path = ('../../tests/unit/javascript/stylesheet/' + js_test_file_path = ('../tests/unit/javascript/stylesheet/' 'test_appendchild.js') stylesheet_tester.js.run_file(js_test_file_path, {})