File: testUtils.py

package info (click to toggle)
zope-cmfplone 2.5.1-4etch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 7,752 kB
  • ctags: 5,237
  • sloc: python: 28,264; xml: 3,723; php: 129; makefile: 99; sh: 2
file content (47 lines) | stat: -rw-r--r-- 1,526 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
# utils tests
#

import os, sys
if __name__ == '__main__':
    execfile(os.path.join(sys.path[0], 'framework.py'))

from Products.CMFPlone.tests import PloneTestCase

from Products.CMFPlone import utils


class TestUtils(PloneTestCase.PloneTestCase):

    def testVersionTupleAlgorithm(self):
        version_map = {'1.2.3': (1, 2, 3, 'final', 0),
                       '2.1-candidate3': (2, 1, 0, 'candidate', 3),
                       '3-beta': (3, 0, 0, 'beta', 0),
                       '2.1-final1 (SVN)': (2, 1, 0, 'final', 1),
                       'foo': None,
                       '2.0a3': (2, 0, 0, 'alpha', 3),
                       '1.2 final': (1, 2, 0, 'final', 0)}
        # TODO note that '2.0a3' will currently return (2, 0, 0, 'final', 0),
        #     when really it should return None.  my regex foo is tapped. (ra)
        for v_str, v_tpl in version_map.items():
            self.failUnless(v_tpl == utils.versionTupleFromString(v_str))

    def testIndexIteratorInMainSlot(self):
        i = utils.IndexIterator(pos=10, mainSlot=True)
        self.assertEqual(i.next(), 10)
        self.assertEqual(i.next(), None)

    def testIndexIteratorOutsideMainSlot(self):
        i = utils.IndexIterator(pos=10, mainSlot=False)
        self.assertEqual(i.next(), None)
        self.assertEqual(i.next(), None)


def test_suite():
    from unittest import TestSuite, makeSuite
    suite = TestSuite()
    suite.addTest(makeSuite(TestUtils))
    return suite

if __name__ == '__main__':
    framework()