2024-02-03 16:43:36 +00:00
|
|
|
from pickle import loads, dumps
|
2015-05-19 07:13:17 +00:00
|
|
|
|
|
|
|
from boltons.namedutils import namedlist, namedtuple
|
|
|
|
|
|
|
|
Point = namedtuple('Point', 'x, y', rename=True)
|
|
|
|
MutablePoint = namedlist('MutablePoint', 'x, y', rename=True)
|
|
|
|
|
|
|
|
|
|
|
|
def test_namedlist():
|
|
|
|
p = MutablePoint(x=10, y=20)
|
|
|
|
|
|
|
|
assert p == [10, 20]
|
|
|
|
p[0] = 11
|
|
|
|
assert p == [11, 20]
|
|
|
|
p.x = 12
|
|
|
|
assert p == [12, 20]
|
|
|
|
|
|
|
|
|
|
|
|
def test_namedlist_pickle():
|
|
|
|
p = MutablePoint(x=10, y=20)
|
|
|
|
assert p == loads(dumps(p))
|
|
|
|
|
|
|
|
|
|
|
|
def test_namedtuple_pickle():
|
|
|
|
p = Point(x=10, y=20)
|
|
|
|
assert p == loads(dumps(p))
|