def test_showkey(self): """test getter/setter for the showkey attribute""" node1 = Parameter(wraptext("1"), wraptext("foo"), showkey=False) node2 = Parameter(wraptext("foo"), wraptext("bar")) self.assertFalse(node1.showkey) self.assertTrue(node2.showkey) node1.showkey = True node2.showkey = "" self.assertTrue(node1.showkey) self.assertFalse(node2.showkey)
def test_showkey(self): """test getter/setter for the showkey attribute""" node1 = Parameter(wraptext("1"), wraptext("foo"), showkey=False) node2 = Parameter(wraptext("foo"), wraptext("bar")) self.assertFalse(node1.showkey) self.assertTrue(node2.showkey) node1.showkey = True node2.showkey = "" self.assertTrue(node1.showkey) self.assertFalse(node2.showkey)
def test_showkey(self): """test getter/setter for the showkey attribute""" node1 = Parameter(wraptext("1"), wraptext("foo"), showkey=False) node2 = Parameter(wraptext("foo"), wraptext("bar")) self.assertFalse(node1.showkey) self.assertTrue(node2.showkey) node1.showkey = True self.assertTrue(node1.showkey) node1.showkey = "" self.assertFalse(node1.showkey) self.assertRaises(ValueError, setattr, node2, "showkey", False)
def test_showkey(self): """test getter/setter for the showkey attribute""" node1 = Parameter(wraptext("1"), wraptext("foo"), showkey=False) node2 = Parameter(wraptext("foo"), wraptext("bar")) self.assertFalse(node1.showkey) self.assertTrue(node2.showkey) node1.showkey = True self.assertTrue(node1.showkey) node1.showkey = "" self.assertFalse(node1.showkey) self.assertRaises(ValueError, setattr, node2, "showkey", False)
def set(self, key, value, showkey=True): # Check for uniqueness. # Wikicode is not hashable, so we instead use the stringified version # as the key and include the Wikicode <parameter name> within the object. skey = str(key) if not self.is_supported(skey): raise ValueError("Not supported: parameter %s" % (skey, )) if skey not in self._parameters_map: o = Parameter(key, value, showkey) self._parameters.append(o) # Needed for consistency - allow future lookups of this parameter. self._parameters_map[skey] = o else: # Overwrite existing parameter. o = self._parameters_map[skey] # Don't allow changing parameter names - creates a consistency problem. o.value = value o.showkey = showkey