summaryrefslogtreecommitdiff
path: root/blessings
diff options
context:
space:
mode:
authorErik Rose <grinch@grinchcentral.com>2012-06-01 17:56:18 -0700
committerErik Rose <grinch@grinchcentral.com>2012-06-01 18:01:43 -0700
commit0f19539b5f87366bb2833f5a91311df72a1d4894 (patch)
tree9138fca759ca2e8c50562b2970081fda7c9b3d22 /blessings
parent103f089a2081a83a1d0fc471c2aa484ce30da407 (diff)
downloadblessings-0f19539b5f87366bb2833f5a91311df72a1d4894.tar.gz
Fix a bug where location() wouldn't do anything when passed 0s.
Diffstat (limited to 'blessings')
-rw-r--r--blessings/__init__.py6
-rw-r--r--blessings/tests.py10
2 files changed, 13 insertions, 3 deletions
diff --git a/blessings/__init__.py b/blessings/__init__.py
index dbd4b69..6f8c107 100644
--- a/blessings/__init__.py
+++ b/blessings/__init__.py
@@ -448,11 +448,11 @@ class Location(object):
def __enter__(self):
"""Save position and move to the requested column, row, or both."""
self.term.stream.write(self.term.save) # save position
- if self.x and self.y:
+ if self.x is not None and self.y is not None:
self.term.stream.write(self.term.move(self.y, self.x))
- elif self.x:
+ elif self.x is not None:
self.term.stream.write(self.term.move_x(self.x))
- elif self.y:
+ elif self.y is not None:
self.term.stream.write(self.term.move_y(self.y))
def __exit__(self, type, value, tb):
diff --git a/blessings/tests.py b/blessings/tests.py
index 72236ae..817e766 100644
--- a/blessings/tests.py
+++ b/blessings/tests.py
@@ -111,6 +111,16 @@ def test_null_location():
unicode_cap('rc'))
+def test_zero_location():
+ """Make sure ``location()`` pays attention to 0-valued args."""
+ t = TestTerminal(stream=StringIO(), force_styling=True)
+ with t.location(0, 0):
+ pass
+ eq_(t.stream.getvalue(), unicode_cap('sc') +
+ unicode_parm('cup', 0, 0) +
+ unicode_cap('rc'))
+
+
def test_null_fileno():
"""Make sure ``Terminal`` works when ``fileno`` is ``None``.