Ejemplo n.º 1
0
 def test_dict(self):
     # Dictionary.
     d = {"a": 0, "b": 1, "z": [25]}
     d_const = cpp_const.to_const(d)
     self.assertEquals(d_const["a"], 0)
     with self._ex():
         d_const["c"] = 2
     with self._ex():
         d_const.clear()
     # N.B. Access does not implicitly propagate.
     self.assertFalse(cpp_const.is_const_test(d_const["z"]))
Ejemplo n.º 2
0
 def test_dict(self):
     # Dictionary.
     d = {"a": 0, "b": 1, "z": [25]}
     d_const = cpp_const.to_const(d)
     self.assertEquals(d_const["a"], 0)
     with self._ex():
         d_const["c"] = 2
     with self._ex():
         d_const.clear()
     # N.B. Access does not implicitly propagate.
     self.assertFalse(cpp_const.is_const_test(d_const["z"]))
Ejemplo n.º 3
0
 def test_child(self):
     obj = AdvancedChild()
     obj.add("a", 0)
     obj_const = cpp_const.to_const(obj)
     self.assertEquals(obj_const.const_safe("a"), 0)
     with self._ex():
         obj_const.const_unsafe("a")
     with self._ex():
         obj_const.mutate_indirect_2()
     with self._ex():
         obj_const._values["c"] = 2
Ejemplo n.º 4
0
 def test_child(self):
     obj = AdvancedChild()
     obj.add("a", 0)
     obj_const = cpp_const.to_const(obj)
     self.assertEquals(obj_const.const_safe("a"), 0)
     with self._ex():
         obj_const.const_unsafe("a")
     with self._ex():
         obj_const.mutate_indirect_2()
     with self._ex():
         obj_const._values["c"] = 2
Ejemplo n.º 5
0
 def test_list(self):
     # List.
     x = [1, 2, 3, [10]]
     x_const = cpp_const.to_const(x)
     with self._ex():
         x_const[0] = 10
     with self._ex():
         x_const[:] = []
     with self._ex():
         del x_const[0]
     with self._ex():
         x_const.append(10)
     with self._ex():
         x_const.pop()
     # N.B. Access does not propagate.
     for i in x_const:
         self.assertFalse(cpp_const.is_const_test(i))
     self.assertFalse(cpp_const.is_const_test(x_const[3]))
Ejemplo n.º 6
0
 def test_list(self):
     # List.
     x = [1, 2, 3, [10]]
     x_const = cpp_const.to_const(x)
     with self._ex():
         x_const[0] = 10
     with self._ex():
         x_const[:] = []
     with self._ex():
         del x_const[0]
     with self._ex():
         x_const.append(10)
     with self._ex():
         x_const.pop()
     # N.B. Access does not propagate.
     for i in x_const:
         self.assertFalse(cpp_const.is_const_test(i))
     self.assertFalse(cpp_const.is_const_test(x_const[3]))
Ejemplo n.º 7
0
 def test_basic(self):
     # Basic class.
     obj = Basic("Tim")
     obj_const = cpp_const.to_const(obj)
     obj.new_attr = "Something"
     self.assertEquals(obj_const.get_name(), "Tim")
     self.assertEquals(obj_const.__dict__["_name"], "Tim")
     with self._ex():
         obj_const.set_name("Bob")
     with self._ex():
         obj_const.name = "Bob"
     with self._ex():
         obj_const._name = "Bob"
     with self._ex():
         obj_const.__dict__["_name"] = "Bob"
     with self._ex():
         obj_const.new_attr = "Something Else"
     # N.B. Access does not implicitly propagate.
     self.assertFalse(cpp_const.is_const_test(obj_const.value))
Ejemplo n.º 8
0
 def test_basic(self):
     # Basic class.
     obj = Basic("Tim")
     obj_const = cpp_const.to_const(obj)
     obj.new_attr = "Something"
     self.assertEquals(obj_const.get_name(), "Tim")
     self.assertEquals(obj_const.__dict__["_name"], "Tim")
     with self._ex():
         obj_const.set_name("Bob")
     with self._ex():
         obj_const.name = "Bob"
     with self._ex():
         obj_const._name = "Bob"
     with self._ex():
         obj_const.__dict__["_name"] = "Bob"
     with self._ex():
         obj_const.new_attr = "Something Else"
     # N.B. Access does not implicitly propagate.
     self.assertFalse(cpp_const.is_const_test(obj_const.value))
Ejemplo n.º 9
0
 def test_advanced(self):
     obj = Advanced()
     obj.add("a", 0)
     obj.add("b", 1)
     obj.add("z", [10])
     obj_const = cpp_const.to_const(obj)
     self.assertTrue(cpp_const.is_const_test(obj_const.get_values()))
     self.assertEquals(obj_const.get("a"), 0)
     with self._ex():
         obj_const.add("c", 2)
     with self._ex():
         obj_const.get_values()["c"] = 2
     with self._ex():
         obj_const.mutate()
     with self._ex():
         obj_const.mutate_indirect()
     # N.B. Access does not implicitly propagate.
     self.assertFalse(cpp_const.is_const_test(obj_const.get("z")))
     self.assertFalse(
         cpp_const.is_const_test(obj_const.__dict__["_values"]))
Ejemplo n.º 10
0
 def test_advanced(self):
     obj = Advanced()
     obj.add("a", 0)
     obj.add("b", 1)
     obj.add("z", [10])
     obj_const = cpp_const.to_const(obj)
     self.assertTrue(cpp_const.is_const_test(obj_const.get_values()))
     self.assertEquals(obj_const.get("a"), 0)
     with self._ex():
         obj_const.add("c", 2)
     with self._ex():
         obj_const.get_values()["c"] = 2
     with self._ex():
         obj_const.mutate()
     with self._ex():
         obj_const.mutate_indirect()
     # N.B. Access does not implicitly propagate.
     self.assertFalse(cpp_const.is_const_test(obj_const.get("z")))
     self.assertFalse(cpp_const.is_const_test(
         obj_const.__dict__["_values"]))