[Zope-CVS] CVS: Products/ZCTextIndex/tests - testStopper.py:1.1

Fred L. Drake, Jr. fdrake@acm.org
Tue, 14 May 2002 12:36:32 -0400


Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv32175

Added Files:
	testStopper.py 
Log Message:
Add test cases for the C version of StopWordRemover.

=== Added File Products/ZCTextIndex/tests/testStopper.py ===
"""Tests for the C version of the StopWordRemover."""

import unittest

from Products.ZCTextIndex import stopper


class StopperTest(unittest.TestCase):
    def test_constructor_empty(self):
        s = stopper.new()
        self.assertEqual(s.dict, {})

    def test_constructor_dict(self):
        d = {}
        s = stopper.new(d)
        self.assert_(s.dict is d)

    def test_constructor_error(self):
        self.assertRaises(TypeError, stopper.new, [])
        self.assertRaises(TypeError, stopper.new, {}, 'extra arg')

    def test_process_nostops(self):
        s = stopper.new()
        words = ['a', 'b', 'c', 'splat!']
        self.assertEqual(words, s.process(words))

    def test_process_somestops(self):
        s = stopper.new({'b':1, 'splat!':1})
        words = ['a', 'b', 'c', 'splat!']
        self.assertEqual(['a', 'c'], s.process(words))

    def test_process_allstops(self):
        s = stopper.new({'a':1, 'b':1, 'c':1, 'splat!':1})
        words = ['a', 'b', 'c', 'splat!']
        self.assertEqual([], s.process(words))


def test_suite():
    return unittest.makeSuite(StopperTest)

if __name__ == "__main__":
    unittest.main(defaultTest='test_suite')