Skip to content

Commit

Permalink
Fix make_canvas for lines with multiple attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
pquentin committed Mar 31, 2016
1 parent 20e181d commit e24a33b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pudb/ui_tools.py
Expand Up @@ -30,7 +30,7 @@ def make_canvas(txt, attr, maxcol, fill_attr=None):
def get_byte_line_attr(line, line_attr):
i = 0
for label, column_count in line_attr:
byte_count = len(line[i:column_count].encode(_target_encoding))
byte_count = len(line[i:i+column_count].encode(_target_encoding))
i += column_count
yield label, byte_count

Expand Down
45 changes: 45 additions & 0 deletions unittests/test_make_canvas.py
@@ -0,0 +1,45 @@
from pudb.ui_tools import make_canvas

class TestMakeCanvas():
def test_simple(self):
text = u'aaaaaa'
canvas = make_canvas(
txt=[text],
attr=[[('var value', len(text))]],
maxcol=len(text) + 5
)
content = list(canvas.content())
assert content == [
[('var value', None, b'aaaaaa'), (None, None, b' ' * 5)]
]

def test_multiple(self):
canvas = make_canvas(
txt=[u'Return: None'],
attr=[[('return label', 8), ('return value', 4)]],
maxcol=100
)
content = list(canvas.content())
assert content == [
[('return label', None, b'Return: '),
('return value', None, b'None'),
(None, None, b' ' * 88)]
]

def test_boundary(self):
text = u'aaaaaa'
canvas = make_canvas(
txt=[text],
attr=[[('var value', len(text))]],
maxcol=len(text)
)
assert list(canvas.content()) == [[('var value', None, b'aaaaaa')]]

def test_byte_boundary(self):
text = u'aaaaaaé'
canvas = make_canvas(
txt=[text],
attr=[[('var value', len(text))]],
maxcol=len(text)
)
assert list(canvas.content()) == [[('var value', None, b'aaaaaa\xc3\xa9')]]

0 comments on commit e24a33b

Please sign in to comment.