def test_deepcopy(self):
    # copy semantics can get hairy when overriding __setattr__/__getattr__, so we test them.
    o = OptionValueContainer()
    o.foo = RankedValue(RankedValue.FLAG, 1)
    o.bar = RankedValue(RankedValue.FLAG, {'a': 111})

    p = copy.deepcopy(o)

    # Verify that the result is in fact a copy.
    self.assertEqual(1, p.foo)  # Has original attribute.
    o.baz = RankedValue(RankedValue.FLAG, 42)
    self.assertFalse(hasattr(p, 'baz'))  # Does not have attribute added after the copy.

    # Verify that it's a deep copy by modifying a referent in o and reading it in p.
    o.bar['b'] = 222
    self.assertEqual({'a': 111}, p.bar)
예제 #2
0
    def test_deepcopy(self) -> None:
        # copy semantics can get hairy when overriding __setattr__/__getattr__, so we test them.
        o = OptionValueContainer()
        o.foo = RankedValue(RankedValue.FLAG, 1)
        o.bar = RankedValue(RankedValue.FLAG, {"a": 111})

        p = copy.deepcopy(o)

        # Verify that the result is in fact a copy.
        self.assertEqual(1, p.foo)  # Has original attribute.
        o.baz = RankedValue(RankedValue.FLAG, 42)
        self.assertFalse(hasattr(p, "baz"))  # Does not have attribute added after the copy.

        # Verify that it's a deep copy by modifying a referent in o and reading it in p.
        # TODO: add type hints to ranked_value.py and option_value_container.py so that this works.
        o.bar["b"] = 222  # type: ignore[index]
        self.assertEqual({"a": 111}, p.bar)
    def test_deepcopy(self):
        # copy semantics can get hairy when overriding __setattr__/__getattr__, so we test them.
        o = OptionValueContainer()
        o.foo = 1
        o.bar = {'a': 111}

        p = copy.deepcopy(o)

        # Verify that the result is in fact a copy.
        self.assertEqual(1, p.foo)  # Has original attribute.
        o.baz = 42
        self.assertFalse(hasattr(
            p, 'baz'))  # Does not have attribute added after the copy.

        # Verify that it's a deep copy by modifying a referent in o and reading it in p.
        o.bar['b'] = 222
        self.assertEqual({'a': 111}, p.bar)