PageRenderTime 26ms CodeModel.GetById 20ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/lib/python/indra/util/iterators_test.py

https://bitbucket.org/lindenlab/viewer-beta/
Python | 72 lines | 63 code | 0 blank | 9 comment | 0 complexity | 1b811d3cf1626f6d6531a1d16ea2bb9b MD5 | raw file
 1"""\
 2@file iterators_test.py
 3@brief Test cases for iterators module.
 4
 5$LicenseInfo:firstyear=2008&license=mit$
 6
 7Copyright (c) 2008-2009, Linden Research, Inc.
 8
 9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26$/LicenseInfo$
27"""
28
29import unittest
30
31from indra.util.iterators import iter_chunks
32
33class TestIterChunks(unittest.TestCase):
34    """Unittests for iter_chunks"""
35    def test_bad_agg_size(self):
36        rows = [1,2,3,4]
37        self.assertRaises(ValueError, iter_chunks, rows, 0)
38        self.assertRaises(ValueError, iter_chunks, rows, -1)
39
40        try:
41            for i in iter_chunks(rows, 0):
42                pass
43        except ValueError:
44            pass
45        else:
46            self.fail()
47        
48        try:
49            result = list(iter_chunks(rows, 0))
50        except ValueError:
51            pass
52        else:
53            self.fail()
54    def test_empty(self):
55        rows = []
56        result = list(iter_chunks(rows))
57        self.assertEqual(result, [])
58    def test_small(self):
59        rows = [[1]]
60        result = list(iter_chunks(rows, 2))
61        self.assertEqual(result, [[[1]]])
62    def test_size(self):
63        rows = [[1],[2]]
64        result = list(iter_chunks(rows, 2))
65        self.assertEqual(result, [[[1],[2]]])
66    def test_multi_agg(self):
67        rows = [[1],[2],[3],[4],[5]]
68        result = list(iter_chunks(rows, 2))
69        self.assertEqual(result, [[[1],[2]],[[3],[4]],[[5]]])
70
71if __name__ == "__main__":
72    unittest.main()