mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refactor, add more tests #2516
This commit is contained in:
2
AUTHORS
2
AUTHORS
@@ -29,7 +29,7 @@ Other contributors, listed alphabetically, are:
|
||||
* Horst Gutmann -- internationalization support
|
||||
* Martin Hans -- autodoc improvements
|
||||
* Doug Hellmann -- graphviz improvements
|
||||
* Timotheus Kampik - JS enhancements, stop words language fix
|
||||
* Timotheus Kampik - JS theme & search enhancements
|
||||
* Takeshi Komiya -- numref feature
|
||||
* Dave Kuhlman -- original LaTeX writer
|
||||
* Blaise Laflamme -- pyramid theme
|
||||
|
||||
@@ -182,11 +182,10 @@ class WordCollector(NodeVisitor):
|
||||
|
||||
def is_meta_keywords(self, node, nodetype):
|
||||
is_meta = str(nodetype) == '<class \'sphinx.addnodes.meta\'>'
|
||||
if is_meta:
|
||||
language_match = re.search(r'lang\=\"(.*?)\"', str(node))
|
||||
is_correct_language =\
|
||||
language_match == None \
|
||||
or self.lang.lang == language_match.group(1)
|
||||
if is_meta and node.get('name', None) == 'keywords':
|
||||
node_lang = node.get('lang', None)
|
||||
is_correct_language = node_lang == None \
|
||||
or node_lang == self.lang.lang
|
||||
return is_meta and is_correct_language
|
||||
else:
|
||||
return False
|
||||
@@ -209,8 +208,9 @@ class WordCollector(NodeVisitor):
|
||||
elif issubclass(nodetype, title):
|
||||
self.found_title_words.extend(self.lang.split(node.astext()))
|
||||
elif self.is_meta_keywords(node, nodetype):
|
||||
keywords = re.search(r'content\=\"(.*?)\"', str(node)).group(1)
|
||||
self.found_words.extend(self.lang.split(keywords))
|
||||
keywords = node['content']
|
||||
keywords = [keyword.strip() for keyword in keywords.split(',')]
|
||||
self.found_words.extend(keywords)
|
||||
|
||||
|
||||
class IndexBuilder(object):
|
||||
|
||||
3
tests/roots/test-search-de/conf.py
Normal file
3
tests/roots/test-search-de/conf.py
Normal file
@@ -0,0 +1,3 @@
|
||||
master_doc = 'index'
|
||||
exclude_patterns = ['_build']
|
||||
html_search_language = 'de'
|
||||
8
tests/roots/test-search-de/index.rst
Normal file
8
tests/roots/test-search-de/index.rst
Normal file
@@ -0,0 +1,8 @@
|
||||
meta keywords
|
||||
=============
|
||||
|
||||
.. meta::
|
||||
:keywords lang=de: findthiskey, thistoo
|
||||
:keywords: thisonetoo
|
||||
:keywords lang=en: findnotthiskey
|
||||
:description: thisnoteither
|
||||
@@ -1,11 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.abspath('.'))
|
||||
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
|
||||
master_doc = 'index'
|
||||
exclude_patterns = ['_build']
|
||||
|
||||
html_search_language = 'en'
|
||||
|
||||
@@ -2,7 +2,7 @@ meta keywords
|
||||
=============
|
||||
|
||||
.. meta::
|
||||
:keywords lang=en: findthiskey
|
||||
:keywords lang=de: findnotthiskey
|
||||
:keywords: thisonetoo
|
||||
|
||||
:keywords lang=en: findthiskey, thistoo
|
||||
:keywords: thisonetoo
|
||||
:keywords lang=de: findnotthiskey
|
||||
:description: thisnoteither
|
||||
|
||||
@@ -53,10 +53,22 @@ def test_objects_are_escaped(app, status, warning):
|
||||
index = jsdump.loads(searchindex[16:-2])
|
||||
assert 'n::Array<T, d>' in index.get('objects').get('') # n::Array<T,d> is escaped
|
||||
|
||||
def assert_lang_agnostic_key_words(searchindex):
|
||||
assert 'findnotthiskey' not in searchindex
|
||||
assert 'thisnoteith' not in searchindex
|
||||
assert 'thistoo' in searchindex
|
||||
assert 'thisonetoo' in searchindex
|
||||
|
||||
@with_app(testroot='search')
|
||||
def test_meta_keys_are_handled_for_language(app, status, warning):
|
||||
def test_meta_keys_are_handled_for_language_en(app, status, warning):
|
||||
app.builder.build_all()
|
||||
searchindex = (app.outdir / 'searchindex.js').text()
|
||||
assert 'findnotthiskey' not in searchindex
|
||||
assert_lang_agnostic_key_words(searchindex)
|
||||
assert 'findthiskei' in searchindex
|
||||
assert 'thisonetoo' in searchindex
|
||||
|
||||
@with_app(testroot='search-de')
|
||||
def test_meta_keys_are_handled_for_language_de(app, status, warning):
|
||||
app.builder.build_all()
|
||||
searchindex = (app.outdir / 'searchindex.js').text()
|
||||
assert_lang_agnostic_key_words(searchindex)
|
||||
assert 'findthiskey' in searchindex
|
||||
Reference in New Issue
Block a user