Skip to content

Commit

Permalink
100% coverage for [test_]htmlsplitter.py
Browse files Browse the repository at this point in the history
Almost all the tests were copies of those in test_lexicon.TestSplitter so use inheritance.
  • Loading branch information
jamadden committed Nov 2, 2017
1 parent 4654559 commit f579f1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 71 deletions.
10 changes: 4 additions & 6 deletions src/zope/index/text/htmlsplitter.py
Expand Up @@ -21,12 +21,10 @@

MARKUP = re.compile(r"(<[^<>]*>|&[A-Za-z]+;)")

_flags = 0
if bytes is str:
# On python 2, we want locale aware splitting. This is the default
# on Python 3 when the pattern is text/unicode and in fact is
# forbidden unless the pattern is bytes (starting) in 3.6
_flags = re.LOCALE
# On python 2, we want locale aware splitting. This is the default
# on Python 3 when the pattern is text/unicode and in fact is
# forbidden unless the pattern is bytes (starting) in 3.6
_flags = re.LOCALE if bytes is str else 0

WORDS = re.compile(r"\w+", _flags)
GLOBS = re.compile(r"\w+[\w*?]*", _flags)
Expand Down
67 changes: 2 additions & 65 deletions src/zope/index/text/tests/test_htmlsplitter.py
Expand Up @@ -13,15 +13,10 @@
##############################################################################
"""Test zope.index.text.htmlsplitter
"""
import unittest

class HTMLWordSplitterTests(unittest.TestCase):
_old_locale = None
from zope.index.text.tests.test_lexicon import SplitterTests

def tearDown(self):
if self._old_locale is not None:
import locale
locale.setlocale(locale.LC_ALL, self._old_locale)
class HTMLWordSplitterTests(SplitterTests):

def _getTargetClass(self):
from zope.index.text.htmlsplitter import HTMLWordSplitter
Expand All @@ -30,41 +25,6 @@ def _getTargetClass(self):
def _makeOne(self):
return self._getTargetClass()()

def test_class_conforms_to_ISplitter(self):
from zope.interface.verify import verifyClass
from zope.index.text.interfaces import ISplitter
verifyClass(ISplitter, self._getTargetClass())

def test_instance_conforms_to_ISplitter(self):
from zope.interface.verify import verifyObject
from zope.index.text.interfaces import ISplitter
verifyObject(ISplitter, self._makeOne())

def test_process_empty_string(self):
splitter = self._makeOne()
self.assertEqual(splitter.process(['']), [])

def test_process_no_markup(self):
splitter = self._makeOne()
self.assertEqual(splitter.process(['abc def']), ['abc', 'def'])

def test_process_w_locale_awareness(self):
import locale
import sys
self._old_locale = locale.setlocale(locale.LC_ALL)
# set German locale
try:
if sys.platform == 'win32':
locale.setlocale(locale.LC_ALL, 'German_Germany.1252')
else:
locale.setlocale(locale.LC_ALL, 'de_DE.ISO8859-1')
except locale.Error:
return # This test doesn't work here :-(
expected = ['m\xfclltonne', 'waschb\xe4r',
'beh\xf6rde', '\xfcberflieger']
splitter = self._makeOne()
self.assertEqual(splitter.process([' '.join(expected)]), expected)

def test_process_w_markup(self):
splitter = self._makeOne()
self.assertEqual(splitter.process(['<h1>abc</h1> &nbsp; <p>def</p>']),
Expand All @@ -75,31 +35,8 @@ def test_process_w_markup_no_spaces(self):
self.assertEqual(splitter.process(['<h1>abc</h1>&nbsp;<p>def</p>']),
['abc', 'def'])

def test_process_no_markup_w_glob(self):
splitter = self._makeOne()
self.assertEqual(splitter.process(['abc?def hij*klm nop* qrs?']),
['abc', 'def', 'hij', 'klm', 'nop', 'qrs'])

def test_processGlob_empty_string(self):
splitter = self._makeOne()
self.assertEqual(splitter.processGlob(['']), [])

def test_processGlob_no_markup_no_glob(self):
splitter = self._makeOne()
self.assertEqual(splitter.processGlob(['abc def']), ['abc', 'def'])

def test_processGlob_w_markup_no_glob(self):
splitter = self._makeOne()
self.assertEqual(splitter.processGlob(['<h1>abc</h1> &nbsp; '
'<p>def</p>']),
['abc', 'def'])

def test_processGlob_no_markup_w_glob(self):
splitter = self._makeOne()
self.assertEqual(splitter.processGlob(['abc?def hij*klm nop* qrs?']),
['abc?def', 'hij*klm', 'nop*', 'qrs?'])

def test_suite():
return unittest.TestSuite((
unittest.makeSuite(HTMLWordSplitterTests),
))

0 comments on commit f579f1d

Please sign in to comment.