From 194fa11664ce1aff4c14097fe1e733c19873d8b2 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 15 Apr 2012 19:25:31 +0100 Subject: Fix Pathname to render from end instead of beginning --- ttystatus/pathname.py | 4 ++-- ttystatus/pathname_tests.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ttystatus/pathname.py b/ttystatus/pathname.py index bf5fe5a..0fbdbd7 100644 --- a/ttystatus/pathname.py +++ b/ttystatus/pathname.py @@ -31,8 +31,8 @@ class Pathname(ttystatus.Widget): self._key = key self.pathname = '' - def render(self, render): - return self.pathname + def render(self, width): + return self.pathname[-width:] def update(self, master): self.pathname = master.get(self._key, '') diff --git a/ttystatus/pathname_tests.py b/ttystatus/pathname_tests.py index 1191f43..70d6c1e 100644 --- a/ttystatus/pathname_tests.py +++ b/ttystatus/pathname_tests.py @@ -28,12 +28,17 @@ class PathnameTests(unittest.TestCase): self.assertFalse(self.w.static_width) def test_is_empty_initially(self): - self.assertEqual(self.w.render(0), '') + self.assertEqual(self.w.render(10), '') def test_updates(self): self.w.update({'foo': 'bar'}) - self.assertEqual(self.w.render(0), 'bar') + self.assertEqual(self.w.render(10), 'bar') def test_handles_update_to_other_value(self): self.w.update({'other': 1}) - self.assertEqual(self.w.render(0), '') + self.assertEqual(self.w.render(10), '') + + def test_truncates_from_beginning(self): + self.w.update({'foo': '/this/is/a/path'}) + self.assertEqual(self.w.render(6), 'a/path') + -- cgit v1.2.1