Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def array_from_text_rc(cls, msg, rows, columns):
arr = FSArray(0, columns)
i = 0
for c in msg:
if i >= rows * columns:
return arr
elif c in '\r\n':
i = ((i // columns) + 1) * columns - 1
else:
arr[i // arr.width, i % arr.width] = [fmtstr(c)]
i += 1
return arr
def test_oomerror(self):
a = FSArray(10, 40)
a[2:-2, 2:-2] = fsarray(['asdf', 'zxcv'])
def test_no_hanging_space(self):
a = FSArray(4, 2)
self.assertEqual(len(a.rows[0]), 0)
def test_assignment_working(self):
t = FSArray(10, 10)
t[2, 2] = 'a'
t[2, 2] == 'a'
def test_len_of_unicode_in_fsarray(self):
fsa = FSArray(3, 2)
fsa.rows[0] = fsa.rows[0].setslice_with_length(0, 2, '┌─', 2)
self.assertEqual(fsa.shape, (3, 2))
fsa.rows[0] = fsa.rows[0].setslice_with_length(0, 2, fmtstr('┌─', 'blue'), 2)
self.assertEqual(fsa.shape, (3, 2))
"""fsarray(list_of_FmtStrs_or_strings, width=None) -> FSArray
Returns a new FSArray of width of the maximum size of the provided
strings, or width provided, and height of the number of strings provided.
If a width is provided, raises a ValueError if any of the strings
are of length greater than this width"""
if 'width' in kwargs:
width = kwargs['width']
del kwargs['width']
if strings and max(len(s) for s in strings) > width:
raise ValueError("Those strings won't fit for width %d" % width)
else:
width = max(len(s) for s in strings) if strings else 0
fstrings = [s if isinstance(s, FmtStr) else fmtstr(s, *args, **kwargs) for s in strings]
arr = FSArray(len(fstrings), width, *args, **kwargs)
rows = [fs.setslice_with_length(0, len(s), s, width) for fs, s in zip(arr.rows, fstrings)]
arr.rows = rows
return arr
def assertFSArraysEqual(self, a, b):
self.assertEqual(type(a), FSArray)
self.assertEqual(type(b), FSArray)
self.assertEqual((a.width, b.height), (a.width, b.height), 'fsarray dimensions do not match: %r %r' % (a.shape, b.shape))
for i, (a_row, b_row) in enumerate(zip(a, b)):
self.assertEqual(a_row, b_row, 'FSArrays differ first on line %s:\n%s' % (i, FSArray.diff(a, b)))
def assertFSArraysEqual(self, a, b):
self.assertEqual(type(a), FSArray)
self.assertEqual(type(b), FSArray)
self.assertEqual((a.width, b.height), (a.width, b.height), 'fsarray dimensions do not match: %r %r' % (a.shape, b.shape))
for i, (a_row, b_row) in enumerate(zip(a, b)):
self.assertEqual(a_row, b_row, 'FSArrays differ first on line %s:\n%s' % (i, FSArray.diff(a, b)))