test_namedutils.py 623 B

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. try:
  3. from cPickle import loads, dumps
  4. except:
  5. from pickle import loads, dumps
  6. from boltons.namedutils import namedlist, namedtuple
  7. Point = namedtuple('Point', 'x, y', rename=True)
  8. MutablePoint = namedlist('MutablePoint', 'x, y', rename=True)
  9. def test_namedlist():
  10. p = MutablePoint(x=10, y=20)
  11. assert p == [10, 20]
  12. p[0] = 11
  13. assert p == [11, 20]
  14. p.x = 12
  15. assert p == [12, 20]
  16. def test_namedlist_pickle():
  17. p = MutablePoint(x=10, y=20)
  18. assert p == loads(dumps(p))
  19. def test_namedtuple_pickle():
  20. p = Point(x=10, y=20)
  21. assert p == loads(dumps(p))