diff options
-rw-r--r-- | blessings/__init__.py | 6 | ||||
-rw-r--r-- | blessings/tests.py | 10 |
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``. |