From 8642b6e8ce0a02029acf34dfe6c127b7e1e0fce0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 24 Feb 2019 20:01:51 +0100 Subject: [PATCH] Fix JSTester.run_file() for new pkg_resources Read the file via open() instead of utils.read_file. --- tests/unit/javascript/conftest.py | 10 ++++++---- .../javascript/position_caret/test_position_caret.py | 2 +- tests/unit/javascript/stylesheet/test_stylesheet.py | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) 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, {})