[svn r63148] add a __repr__ for xspecs

--HG--
branch : trunk
This commit is contained in:
hpk 2009-03-20 17:58:32 +01:00
parent a4c14e83f0
commit 78d1836d80
2 changed files with 8 additions and 1 deletions

View File

@ -34,6 +34,10 @@ class TestXSpec:
for x in ("popen", "popen//python=this"):
assert XSpec(x)._spec == x
def test_repr(self):
for x in ("popen", "popen//python=this"):
assert repr(XSpec(x)).find("popen") != -1
def test_hash_equality(self):
assert XSpec("popen") == XSpec("popen")
assert hash(XSpec("popen")) == hash(XSpec("popen"))

View File

@ -22,9 +22,12 @@ class XSpec:
key, value = keyvalue[:i], keyvalue[i+1:]
# XXX be restrictive for now
if key not in XSpec.__dict__:
raise AttributeError("%r not a valid attribute" % key)
raise AttributeError("%r not a valid XSpec key" % key)
setattr(self, key, value)
def __repr__(self):
return "<XSpec %r>" %(self._spec,)
def __hash__(self):
return hash(self._spec)
def __eq__(self, other):