0001-misc-fix-ellipsize-for-mini-strings-16280.patch
tests/test_fields.py | ||
---|---|---|
90 | 90 | |
91 | 91 | |
92 | 92 |
def test_text(): |
93 |
assert fields.TextField().get_view_short_value('foo'*10) == ('foo'*10)[:25] + ' (...)'
|
|
93 |
assert fields.TextField().get_view_short_value('foo'*15) == ('foo'*10)[:27] + '(…)'
|
|
94 | 94 |
assert fields.TextField().get_view_value('foo') == '<p>foo</p>' |
95 | 95 |
assert fields.TextField().get_view_value('foo\n\nfoo') == '<p>foo\n</p><p>\nfoo</p>' |
96 | 96 |
assert fields.TextField(pre=True).get_view_value('foo') == '<pre>foo</pre>' |
tests/test_misc.py | ||
---|---|---|
18 | 18 |
import wcs.api # workaround against circular dependencies :/ |
19 | 19 |
from wcs.qommon.form import FileSizeWidget, PicklableUpload |
20 | 20 |
from wcs.qommon.humantime import humanduration2seconds, seconds2humanduration |
21 |
from wcs.qommon.misc import (simplify, json_loads, parse_isotime, format_time, |
|
22 |
date_format, get_as_datetime, normalize_geolocation) |
|
21 |
from wcs.qommon.misc import ( |
|
22 |
simplify, json_loads, parse_isotime, format_time, |
|
23 |
date_format, get_as_datetime, normalize_geolocation, ellipsize) |
|
23 | 24 |
from wcs.admin.settings import FileTypesDirectory |
24 | 25 |
from wcs.scripts import Script |
25 | 26 |
from wcs.qommon import force_str, evalutils |
... | ... | |
555 | 556 |
field.id = '1' |
556 | 557 |
field.label = 'test' |
557 | 558 |
assert repr(field) == "<StringField 1 'test'>" |
559 | ||
560 | ||
561 |
@pytest.mark.parametrize('value, length, expected', [ |
|
562 |
('', 30, ''), |
|
563 |
(None, 30, 'None'), |
|
564 |
('foo bar', 30, 'foo bar'), |
|
565 |
('01234567890123456789012345678', 30, '01234567890123456789012345678'), |
|
566 |
('012345678901234567890123456789', 30, '012345678901234567890123456789'), |
|
567 |
('0123456789012345678901234567890', 30, '012345678901234567890123456(…)'), |
|
568 |
('foo bar', 4, 'f(…)'), |
|
569 |
('foo bar', 3, 'foo'), |
|
570 |
('foo bar', 2, 'fo'), |
|
571 |
]) |
|
572 |
def test_ellipsize(value, length, expected): |
|
573 |
create_temporary_pub() |
|
574 |
assert ellipsize(value, length=length) == expected |
wcs/qommon/misc.py | ||
---|---|---|
261 | 261 | |
262 | 262 |
def ellipsize(s, length=30): |
263 | 263 |
s = force_text(s, get_publisher().site_charset, errors='replace') |
264 |
if s and len(s) >= length: |
|
265 |
s = s[:length-5] + ' (...)' |
|
264 |
if s and len(s) > length: |
|
265 |
if length > 3: |
|
266 |
s = s[:length-3] + '(…)' |
|
267 |
else: |
|
268 |
s = s[:length] |
|
266 | 269 |
return force_str(s) |
267 | 270 | |
268 | 271 | |
269 |
- |