def test_representation(self): """ The string representation of an instance of L{NamedConstant} includes the container the instances belongs to as well as the instance's name. """ name = NamedConstant() name._realize(self.container, "bar", None) self.assertEqual("<foo=bar>", repr(name))
def test_equality(self): """ A L{NamedConstant} instance compares equal to itself. """ name = NamedConstant() name._realize(self.container, "bar", None) self.assertTrue(name == name) self.assertFalse(name != name)
def test_name(self): """ The C{name} attribute of a L{NamedConstant} refers to the value passed for the C{name} parameter to C{_realize}. """ name = NamedConstant() name._realize(self.container, "bar", None) self.assertEqual("bar", name.name)
class METHOD(Names): """ A container for some named constants to use in unit tests for L{Names}. """ GET = NamedConstant() PUT = NamedConstant() POST = NamedConstant() DELETE = NamedConstant()
def test_hash(self): """ Because two different L{NamedConstant} instances do not compare as equal to each other, they also have different hashes to avoid collisions when added to a C{dict} or C{set}. """ first = NamedConstant() first._realize(self.container, "bar", None) second = NamedConstant() second._realize(self.container, "bar", None) self.assertNotEqual(hash(first), hash(second))
def test_nonequality(self): """ Two different L{NamedConstant} instances do not compare equal to each other. """ first = NamedConstant() first._realize(self.container, "bar", None) second = NamedConstant() second._realize(self.container, "bar", None) self.assertFalse(first == second) self.assertTrue(first != second)