Skip to content

Commit

Permalink
Allow Refs to be hashable using their data (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
happyraul authored and markpeek committed May 26, 2018
1 parent 8e2b9b4 commit 4eceaa0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,22 @@ def test_ref_eq(self):
self.assertNotEqual(r, Ref)
self.assertNotEqual(wch.Ref(), "NonexistantResource")

def test_ref_hash(self):
s = hash("AWS::NoValue")
r = hash(Ref(s))

wch = cloudformation.WaitConditionHandle("TestResource")

self.assertEqual(s, r)
self.assertEqual(s, hash(NoValue))
self.assertEqual(r, hash(NoValue))
self.assertEqual(hash(wch.Ref()), hash("TestResource"))

self.assertNotEqual(r, hash("AWS::Region"))
self.assertNotEqual(r, hash(Region))
self.assertNotEqual(r, hash(Ref))
self.assertNotEqual(hash(wch.Ref()), hash("NonexistantResource"))


class TestName(unittest.TestCase):

Expand Down
3 changes: 3 additions & 0 deletions troposphere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@ def __eq__(self, other):
return self.data == other.data
return self.data.values()[0] == other

def __hash__(self):
return hash(self.data.values()[0])


# Pseudo Parameter Ref's
AccountId = Ref(AWS_ACCOUNT_ID)
Expand Down

0 comments on commit 4eceaa0

Please sign in to comment.