summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2019-02-24 20:01:51 +0100
committerFlorian Bruhin <me@the-compiler.org>2019-02-25 09:28:25 +0100
commit8642b6e8ce0a02029acf34dfe6c127b7e1e0fce0 (patch)
tree3830eda8104811d4128a06541b2dbcb495ccc85d
parent0e11b85474197d143cd04aec93cc6475c27b2cf7 (diff)
downloadqutebrowser-8642b6e8ce0a02029acf34dfe6c127b7e1e0fce0.tar.gz
qutebrowser-8642b6e8ce0a02029acf34dfe6c127b7e1e0fce0.zip
Fix JSTester.run_file() for new pkg_resources
Read the file via open() instead of utils.read_file.
-rw-r--r--tests/unit/javascript/conftest.py10
-rw-r--r--tests/unit/javascript/position_caret/test_position_caret.py2
-rw-r--r--tests/unit/javascript/stylesheet/test_stylesheet.py2
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, {})