[Python-modules-commits] [sphinx] 01/01: Update jstests for compatibility with WebKitGTK+ 2.16.
Dmitry Shachnev
mitya57 at moszumanska.debian.org
Sat May 13 15:55:57 UTC 2017
This is an automated email from the git hooks/post-receive script.
mitya57 pushed a commit to branch debian/master
in repository sphinx.
commit 75bf800a885febb0d425358a628528e28baf2fb2
Author: Dmitry Shachnev <mitya57 at gmail.com>
Date: Sat May 13 18:55:19 2017 +0300
Update jstests for compatibility with WebKitGTK+ 2.16.
Now the title property can be no longer than 1000 characters, so we
cannot fetch the whole page using it. Instead, we compute the needed
numbers with JavaScript and then fetch them using the title property.
---
debian/changelog | 9 +++++++++
debian/jstest/jstest.py | 34 +++++++++++++++-------------------
2 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 0987606..be0714b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,12 @@
+sphinx (1.5.5-2) UNRELEASED; urgency=medium
+
+ * Update jstests for compatibility with WebKitGTK+ 2.16.
+ Now the title property can be no longer than 1000 characters, so we
+ cannot fetch the whole page using it. Instead, we compute the needed
+ numbers with JavaScript and then fetch them using the title property.
+
+ -- Dmitry Shachnev <mitya57 at debian.org> Sat, 13 May 2017 18:52:57 +0300
+
sphinx (1.5.5-1) experimental; urgency=medium
* New upstream release.
diff --git a/debian/jstest/jstest.py b/debian/jstest/jstest.py
index 2b00c57..0b5ae23 100644
--- a/debian/jstest/jstest.py
+++ b/debian/jstest/jstest.py
@@ -2,7 +2,7 @@
# encoding=UTF-8
# Copyright © 2011 Jakub Wilk <jwilk at debian.org>
-# © 2013-2015 Dmitry Shachnev <mitya57 at debian.org>
+# © 2013-2017 Dmitry Shachnev <mitya57 at debian.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
@@ -59,15 +59,19 @@ class Browser(object):
def _on_title_changed(self, webview, user_data):
contents = webview.get_property('title')
webview.run_javascript('document.title = ""')
- found = "Search finished" in contents
+ found = re.match(r"(?P<n_results>\d+) (?P<n_links>\d+) (?P<n_highlights>\d+)", contents)
if found:
- self._result = contents
+ self._result = found.groupdict()
Gtk.main_quit()
GLib.source_remove(self._id)
self._id = 0
def _quit(self):
- self._view.run_javascript('document.title = document.documentElement.innerHTML')
+ self._view.run_javascript(
+ "var n_results = $('#search-results > p:first').text().match(/found (\d+) page/)[1];\n"
+ "var n_links = $('#search-results a').length;\n"
+ "var n_highlights = $('#search-results .highlighted').length;\n"
+ "document.title = `${n_results} ${n_links} ${n_highlights}`;")
if self._time_limit < 0:
self._result = None
Gtk.main_quit()
@@ -79,7 +83,7 @@ class Browser(object):
def wget(self, url, time_limit=default_time_limit):
self._view.load_uri(url)
self._time_limit = time_limit
- self._id = GLib.timeout_add_seconds(time_limit, self._quit)
+ self._id = GLib.timeout_add_seconds(1, self._quit)
Gtk.main()
if self._result is None:
raise Timeout
@@ -89,31 +93,23 @@ class Browser(object):
# Actual tests
# ============
-re_done = re.compile(r'Search finished, found ([0-9]+) page')
-re_link = re.compile(r'<a href="[^"]+?highlight=[^"?]+">')
-re_highlight = re.compile(r'<span class="highlighted">')
-
-def test_html(html, options):
+def test_html(result, options):
class TestCase(unittest.TestCase):
if options.n_results is not None:
def test_n_results(self):
- match = re_done.search(html)
- self.assertIsNotNone(match)
- n_results = int(match.group(1))
+ n_results = int(result['n_results'])
self.assertEqual(n_results, options.n_results)
if options.n_links is not None:
def test_n_links(self):
- matches = re_link.findall(html)
- n_links = len(matches)
+ n_links = int(result['n_links'])
self.assertEqual(n_links, options.n_links)
if options.n_highlights is not None:
def test_n_highlights(self):
- matches = re_highlight.findall(html)
- n_highlights = len(matches)
+ n_highlights = int(result['n_highlights'])
self.assertEqual(n_highlights, options.n_highlights)
TestCase.__name__ = 'TestCase(%r)' % options.search_term
@@ -125,8 +121,8 @@ def test_directory(directory, options, time_limit=default_time_limit):
url = urllib.parse.urljoin('file:', urllib.request.pathname2url(directory))
url = urllib.parse.urljoin(url, 'html/search.html?q=' + urllib.parse.quote_plus(options.search_term))
browser = Browser(options)
- html = browser.wget(url, time_limit)
- return test_html(html, options)
+ result = browser.wget(url, time_limit)
+ return test_html(result, options)
def main():
import argparse
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/sphinx.git
More information about the Python-modules-commits
mailing list