Skip to content

Commit

Permalink
- pyramid.testing.DummyResource didn't define __bool__, so co…
Browse files Browse the repository at this point in the history
…de under

   Python 3 would use ``__len__`` to find truthiness; this usually caused an
   instance of DummyResource to be "falsy" instead of "truthy".  See
   #1032

Closes #1032
  • Loading branch information
mcdonc committed Jun 11, 2013
1 parent 035b860 commit 050b71c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ Bug Fixes
files have now been removed. See
https://github.com/Pylons/pyramid/issues/981

- ``pyramid.testing.DummyResource`` didn't define ``__bool__``, so code under
Python 3 would use ``__len__`` to find truthiness; this usually caused an
instance of DummyResource to be "falsy" instead of "truthy". See
https://github.com/Pylons/pyramid/pull/1032

1.4 (2012-12-18)
================

Expand Down
2 changes: 2 additions & 0 deletions pyramid/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ def keys(self):
def __nonzero__(self):
return True

__bool__ = __nonzero__

def __len__(self):
return len(self.subs)

Expand Down
4 changes: 4 additions & 0 deletions pyramid/tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def test_nonzero(self):
resource = self._makeOne()
self.assertEqual(resource.__nonzero__(), True)

def test_bool(self):
resource = self._makeOne()
self.assertEqual(resource.__bool__(), True)

def test_ctor_with__provides__(self):
resource = self._makeOne(__provides__=IDummy)
self.assertTrue(IDummy.providedBy(resource))
Expand Down

0 comments on commit 050b71c

Please sign in to comment.