zdtm.py: ignore unicode encode errors

Submitted by Pavel Tikhomirov on June 20, 2018, 3:13 p.m.

Details

Message ID 20180620151321.12007-1-ptikhomirov@virtuozzo.com
State Accepted
Series "zdtm.py: ignore unicode encode errors"
Commit 70e18b846bdc6657a2726780a1717677ca39a304
Headers show

Commit Message

Pavel Tikhomirov June 20, 2018, 3:13 p.m.
We have a problem after commit 212e4c771a1b ("test: make zdtm.py
python2/python3 compatible") when running tests on python2:

https://ci.openvz.org/job/CRIU/job/CRIU-virtuozzo/job/criu-dev/3804/console

Traceback (most recent call last):
  File "./test/zdtm.py", line 2249, in <module>
    opts['action'](opts)
  File "./test/zdtm.py", line 2001, in run_tests
    launcher.run_test(t, tdesc, run_flavs)
  File "./test/zdtm.py", line 1680, in run_test
    self.wait()
  File "./test/zdtm.py", line 1737, in wait
    self.__wait_one(0)
  File "./test/zdtm.py", line 1725, in __wait_one
    print(open(sub['log']).read())
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in
position 258: ordinal not in range(128)

print does not like "‘" symbol in zdtm_static_cgroup04.log:
...
rmdir: failed to remove ‘cgclean.sKFHLm/zdtmtst/special_prop_check’: No
such file or directory

Small reproducer:

[snorch@snorch ~]$ cat test_ascii.py
from __future__ import absolute_import, division, print_function, unicode_literals
from builtins import (str, open, range, zip, int, input)

f = open('./zdtm_static_cgroup04.log')
s = f.read()
print(s)

[snorch@snorch ~]$ python test_ascii.py | grep ""
Traceback (most recent call last):
  File "test_ascii.py", line 6, in <module>
    print(s)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in
position 258: ordinal not in range(128)

So just ignore these quote symbol when printing logs.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
 test/zdtm.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/test/zdtm.py b/test/zdtm.py
index 2e093e597..c795490ae 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -1723,7 +1723,7 @@  do_sbs = False
 					print(testline, file=self.__file_report)
 
 			if sub['log']:
-				print(open(sub['log']).read())
+				print(open(sub['log']).read().encode('ascii', 'ignore'))
 				os.unlink(sub['log'])
 
 			return True

Comments

Andrey Vagin June 20, 2018, 6:20 p.m.
Applied, thanks

On Wed, Jun 20, 2018 at 06:13:21PM +0300, Pavel Tikhomirov wrote:
> We have a problem after commit 212e4c771a1b ("test: make zdtm.py
> python2/python3 compatible") when running tests on python2:
> 
> https://ci.openvz.org/job/CRIU/job/CRIU-virtuozzo/job/criu-dev/3804/console
> 
> Traceback (most recent call last):
>   File "./test/zdtm.py", line 2249, in <module>
>     opts['action'](opts)
>   File "./test/zdtm.py", line 2001, in run_tests
>     launcher.run_test(t, tdesc, run_flavs)
>   File "./test/zdtm.py", line 1680, in run_test
>     self.wait()
>   File "./test/zdtm.py", line 1737, in wait
>     self.__wait_one(0)
>   File "./test/zdtm.py", line 1725, in __wait_one
>     print(open(sub['log']).read())
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in
> position 258: ordinal not in range(128)
> 
> print does not like "‘" symbol in zdtm_static_cgroup04.log:
> ...
> rmdir: failed to remove ‘cgclean.sKFHLm/zdtmtst/special_prop_check’: No
> such file or directory
> 
> Small reproducer:
> 
> [snorch@snorch ~]$ cat test_ascii.py
> from __future__ import absolute_import, division, print_function, unicode_literals
> from builtins import (str, open, range, zip, int, input)
> 
> f = open('./zdtm_static_cgroup04.log')
> s = f.read()
> print(s)
> 
> [snorch@snorch ~]$ python test_ascii.py | grep ""
> Traceback (most recent call last):
>   File "test_ascii.py", line 6, in <module>
>     print(s)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in
> position 258: ordinal not in range(128)
> 
> So just ignore these quote symbol when printing logs.
> 
> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
> ---
>  test/zdtm.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/test/zdtm.py b/test/zdtm.py
> index 2e093e597..c795490ae 100755
> --- a/test/zdtm.py
> +++ b/test/zdtm.py
> @@ -1723,7 +1723,7 @@ do_sbs = False
>  					print(testline, file=self.__file_report)
>  
>  			if sub['log']:
> -				print(open(sub['log']).read())
> +				print(open(sub['log']).read().encode('ascii', 'ignore'))
>  				os.unlink(sub['log'])
>  
>  			return True
> -- 
> 2.17.0
>