[Zope3-checkins] CVS: Products3/bugtracker/browser/tests - __init__.py:1.1 test_batcher.py:1.1

Stephan Richter srichter@cosmos.phy.tufts.edu
Mon, 28 Jul 2003 15:44:58 -0400


Update of /cvs-repository/Products3/bugtracker/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv4442/browser/tests

Added Files:
	__init__.py test_batcher.py 
Log Message:
Test for the Batch object.


=== Added File Products3/bugtracker/browser/tests/__init__.py ===


=== Added File Products3/bugtracker/browser/tests/test_batcher.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Bug Tracker Mail Subscription and Mailer Tests

$Id: test_batcher.py,v 1.1 2003/07/28 19:44:51 srichter Exp $
"""
import unittest

from zopeproducts.bugtracker.browser.tracker import Batch

class BatchTest(unittest.TestCase):

    def getData(self):
        return ['one', 'two', 'three', 'four', 'five', 'six',
                'seven', 'eight', 'nine', 'ten']

    def test_constructor(self):
        batch = Batch(self.getData(), 9, 3)
        self.assertRaises(IndexError, Batch, self.getData(), start=10, size=3)

    def test__len__(self):
        batch = Batch(self.getData(), 0, 3)
        self.assertEqual(len(batch), 3)
        batch = Batch(self.getData(), 9, 3)
        self.assertEqual(len(batch), 1)

    def test__getitem__(self):
        batch = Batch(self.getData(), 0, 3)
        self.assertEqual(batch[0], 'one')
        self.assertEqual(batch[1], 'two')
        self.assertEqual(batch[2], 'three')
        batch = Batch(self.getData(), 3, 3)
        self.assertEqual(batch[0], 'four')
        self.assertEqual(batch[1], 'five')
        self.assertEqual(batch[2], 'six')
        batch = Batch(self.getData(), 9, 3)
        self.assertRaises(IndexError, batch.__getitem__, 3)
        
    def test__iter__(self):
        batch = Batch(self.getData(), 0, 3)
        self.assertEqual(list(iter(batch)), ['one', 'two', 'three'])
        batch = Batch(self.getData(), 9, 3)
        self.assertEqual(list(iter(batch)), ['ten'])

    def test__contains__(self):
        batch = Batch(self.getData(), 0, 3)
        self.assert_(batch.__contains__('one'))
        self.assert_(batch.__contains__('two'))
        self.assert_(batch.__contains__('three'))
        self.assert_(not batch.__contains__('four'))
        batch = Batch(self.getData(), 6, 3)
        self.assert_(not batch.__contains__('one'))
        self.assert_(batch.__contains__('seven'))
        self.assert_(not batch.__contains__('ten'))

    def test_nextBatch(self):
        next = Batch(self.getData(), 0, 3).nextBatch()
        self.assertEqual(list(iter(next)), ['four', 'five', 'six'])
        nextnext = next.nextBatch()
        self.assertEqual(list(iter(nextnext)), ['seven', 'eight', 'nine'])
        next = Batch(self.getData(), 9, 3).nextBatch()
        self.assertEqual(next, None)

    def test_prevBatch(self):
        prev = Batch(self.getData(), 9, 3).prevBatch()
        self.assertEqual(list(iter(prev)), ['seven', 'eight', 'nine'])
        prevprev = prev.prevBatch()
        self.assertEqual(list(iter(prevprev)), ['four', 'five', 'six'])
        prev = Batch(self.getData(), 0, 3).prevBatch()
        self.assertEqual(prev, None)

    def test_batchRoundTrip(self):
        batch = Batch(self.getData(), 0, 3).nextBatch()
        self.assertEqual(list(iter(batch.nextBatch().prevBatch())),
                         list(iter(batch)))

    def test_first_last(self):
        batch = Batch(self.getData(), 0, 3)
        self.assertEqual(batch.first(), 'one')
        self.assertEqual(batch.last(), 'three')
        batch = Batch(self.getData(), 9, 3)
        self.assertEqual(batch.first(), 'ten')
        self.assertEqual(batch.last(), 'ten')
        
    def test_total(self):
        batch = Batch(self.getData(), 0, 3)
        self.assertEqual(batch.total(), 10)
        batch = Batch(self.getData(), 6, 3)
        self.assertEqual(batch.total(), 10)
    
    def test_startNumber(self):
        batch = Batch(self.getData(), 0, 3)
        self.assertEqual(batch.startNumber(), 1)
        batch = Batch(self.getData(), 9, 3)
        self.assertEqual(batch.startNumber(), 10)

    def test_endNumber(self):
        batch = Batch(self.getData(), 0, 3)
        self.assertEqual(batch.endNumber(), 3)
        batch = Batch(self.getData(), 9, 3)
        self.assertEqual(batch.endNumber(), 10)
        

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

if __name__ == '__main__':
    unittest.main()