X Tutup
Skip to content

Commit 7bae7fa

Browse files
committed
Fixed compressing long strings with PY3
1 parent 3abd04a commit 7bae7fa

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/robot/reporting/stringcache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _encode(self, text):
4141
return raw
4242
compressed = compress_text(text)
4343
if len(compressed) * self._use_compressed_threshold < len(raw):
44-
return str(compressed)
44+
return compressed
4545
return raw
4646

4747
def _raw(self, text):

src/robot/utils/compress.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
import base64
1616
import sys
1717

18+
from .platform import PY2
19+
1820

1921
def compress_text(text):
20-
return base64.b64encode(_compress(text.encode('UTF-8')))
22+
result = base64.b64encode(_compress(text.encode('UTF-8')))
23+
return result if PY2 else result.decode('ASCII')
2124

2225

2326
if not sys.platform.startswith('java'):

utest/utils/test_compress.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import unittest
22
import zlib
33

4-
from robot.utils.compress import _compress
5-
from robot.utils.asserts import assert_equals
4+
from robot.utils.compress import compress_text, _compress
5+
from robot.utils.asserts import assert_equals, assert_true
66

77

88
class TestCompress(unittest.TestCase):
99

1010
def _test(self, text):
11+
assert_true(isinstance(compress_text(text), str))
1112
text = text.encode('UTF-8')
1213
assert_equals(_compress(text), zlib.compress(text, 9))
1314

@@ -21,3 +22,7 @@ def test_100_char_strings(self):
2122
def test_non_ascii(self):
2223
self._test(u'hyv\xe4')
2324
self._test(u'\u4e2d\u6587')
25+
26+
27+
if __name__ == '__main__':
28+
unittest.main()

0 commit comments

Comments
 (0)
X Tutup