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