Exemplo n.º 1
0
    def test_copy_copied_parameter_node(self):
        node = ParameterNode(use_as_attributes=True)
        node.p = Parameter(set_cmd=None)
        node.p = 123
        self.assertEqual(node['p'].parent, node)

        node2 = copy(node)
        node3 = copy(node2)
        self.assertEqual(node2['p'].parent, node2)
        self.assertEqual(node3['p'].parent, node3)
        self.assertListEqual(self.parameter_copies, [node['p'], node2['p']])
        self.assertListEqual(self.parameter_deepcopies, [])
        self.assertListEqual(self.parameter_node_copies, [node, node2])
        self.assertListEqual(self.parameter_node_deepcopies, [])

        self.assertIsNot(node['p'], node2['p'])
        self.assertIsNot(node2['p'], node3['p'])
        self.assertEqual(node.p, 123)
        self.assertEqual(node2.p, 123)
        self.assertEqual(node3.p, 123)

        node.p = 124
        self.assertEqual(node.p, 124)
        self.assertEqual(node2.p, 123)
        self.assertEqual(node3.p, 123)

        node2.p = 125
        self.assertEqual(node.p, 124)
        self.assertEqual(node2.p, 125)
        self.assertEqual(node3.p, 123)

        node3.p = 126
        self.assertEqual(node.p, 124)
        self.assertEqual(node2.p, 125)
        self.assertEqual(node3.p, 126)
Exemplo n.º 2
0
    def test_copy_parameter_in_parameter_node(self):
        node = ParameterNode(use_as_attributes=True)
        node.p = Parameter(set_cmd=None)
        node.p = 123
        self.assertEqual(node['p'].parent, node)

        copy(node['p'])
        self.assertListEqual(self.parameter_copies, [node['p']])
        self.assertListEqual(self.parameter_node_copies, [])
        self.assertListEqual(self.parameter_node_deepcopies, [])
Exemplo n.º 3
0
    def test_parameter_no_parent(self):
        p = Parameter(set_cmd=None)
        p.parent = False

        node = ParameterNode()
        node.p = p
        self.assertIs(p.parent, False)
Exemplo n.º 4
0
    def test_pickled_node_with_parameter(self):
        node = ParameterNode(name='node')
        node.p = Parameter(initial_value=123)
        pickle_dump = pickle.dumps(node)

        node_pickled = pickle.loads(pickle_dump)
        self.assertEqual(node_pickled.name, 'node')
        self.assertEqual(node_pickled['p'].name, 'p')
        self.assertEqual(node_pickled['p'].get_latest(), 123)
        self.assertEqual(node_pickled['p'].get(), 123)
Exemplo n.º 5
0
    def test_copy_parameter_in_node(self):
        node = ParameterNode(use_as_attributes=True)
        node.p = Parameter(set_cmd=None)

        node.p = 123

        p_copy = copy(node['p'])
        self.assertEqual(node.p, 123)
        self.assertEqual(p_copy(), 123)

        node.p = 124
        self.assertEqual(node.p, 124)
        self.assertEqual(p_copy(), 123)

        p_copy(125)
        self.assertEqual(node.p, 124)
        self.assertEqual(p_copy(), 125)

        self.assertListEqual(self.parameter_copies, [node['p']])
        self.assertListEqual(self.parameter_node_copies, [])
        self.assertListEqual(self.parameter_node_deepcopies, [])
Exemplo n.º 6
0
    def test_deepcopy_parameter_node_add_parameter(self):
        node = ParameterNode(use_as_attributes=True)
        node.add_parameter('p', set_cmd=None)
        node.p = 123
        self.assertEqual(node['p'](), 123)
        self.assertEqual(node['p']._instrument, node)

        node_copy = deepcopy(node)
        self.assertEqual(node.p, 123)
        self.assertEqual(node['p']._instrument, node)
        self.assertEqual(node_copy['p']._instrument, None)

        self.assertListEqual(self.parameter_copies, [])
        self.assertListEqual(self.parameter_deepcopies, [node['p']])
        self.assertListEqual(self.parameter_node_copies, [])
        self.assertListEqual(self.parameter_node_deepcopies, [node])
Exemplo n.º 7
0
 def test_parameter_in_node_simplified_snapshot(self):
     node = ParameterNode(simplify_snapshot=True)
     node.p = Parameter(initial_value=42)
     self.assertEqual(node.snapshot()['p'], 42)
Exemplo n.º 8
0
 def test_parameter_in_node_snapshot(self):
     node = ParameterNode()
     node.p = Parameter()
     self.assertEqual(node.snapshot()['parameters']['p'], node.p.snapshot())