MCPcopy Create free account
hub / github.com/cloudpipe/cloudpickle / test_property

Method test_property

tests/cloudpickle_test.py:1600–1641  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1598 self.assertEqual(cloned.__qualname__, func.__qualname__)
1599
1600 def test_property(self):
1601 # Note that the @property decorator only has an effect on new-style
1602 # classes.
1603 class MyObject:
1604 _read_only_value = 1
1605 _read_write_value = 1
1606
1607 @property
1608 def read_only_value(self):
1609 "A read-only attribute"
1610 return self._read_only_value
1611
1612 @property
1613 def read_write_value(self):
1614 return self._read_write_value
1615
1616 @read_write_value.setter
1617 def read_write_value(self, value):
1618 self._read_write_value = value
1619
1620 my_object = MyObject()
1621
1622 assert my_object.read_only_value == 1
1623 assert MyObject.read_only_value.__doc__ == "A read-only attribute"
1624
1625 with pytest.raises(AttributeError):
1626 my_object.read_only_value = 2
1627 my_object.read_write_value = 2
1628
1629 depickled_obj = pickle_depickle(my_object)
1630
1631 assert depickled_obj.read_only_value == 1
1632 assert depickled_obj.read_write_value == 2
1633
1634 # make sure the depickled read_only_value attribute is still read-only
1635 with pytest.raises(AttributeError):
1636 my_object.read_only_value = 2
1637
1638 # make sure the depickled read_write_value attribute is writeable
1639 depickled_obj.read_write_value = 3
1640 assert depickled_obj.read_write_value == 3
1641 type(depickled_obj).read_only_value.__doc__ == "A read-only attribute"
1642
1643 def test_namedtuple(self):
1644 MyTuple = collections.namedtuple("MyTuple", ["a", "b", "c"])

Callers

nothing calls this directly

Calls 2

MyObjectClass · 0.85
pickle_depickleFunction · 0.85

Tested by

no test coverage detected