test_tarfile fails on an android emulator running an x86 system image at API level 21.
====================================================================== [0/9481]
FAIL: test_extract_with_numeric_owner (test.test_tarfile.NumericOwnerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/sdcard/org.bitbucket.pyona/lib/python3.6/unittest/mock.py", line 1175, in patched
return func(*args, **keywargs)
File "/sdcard/org.bitbucket.pyona/lib/python3.6/test/test_tarfile.py", line 2483, in test_extract_
with_numeric_owner
any_order=True)
File "/sdcard/org.bitbucket.pyona/lib/python3.6/unittest/mock.py", line 856, in assert_has_calls
) from cause
AssertionError: (call('/data/local/tmp/test_python_2938/@test_2938_tmp-tardir/numeric-owner-testfile
', 99, 98), call('/data/local/tmp/test_python_2938/@test_2938_tmp-tardir/dir/numeric-owner-testfile'
, 88, 87)) not all found in call list
======================================================================
FAIL: test_extractall_with_numeric_owner (test.test_tarfile.NumericOwnerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/sdcard/org.bitbucket.pyona/lib/python3.6/unittest/mock.py", line 1175, in patched
return func(*args, **keywargs)
File "/sdcard/org.bitbucket.pyona/lib/python3.6/test/test_tarfile.py", line 2503, in test_extracta
ll_with_numeric_owner
any_order=True)
File "/sdcard/org.bitbucket.pyona/lib/python3.6/unittest/mock.py", line 856, in assert_has_calls
) from cause
AssertionError: (call('/data/local/tmp/test_python_2938/@test_2938_tmp-tardir/numeric-owner-testfile
', 99, 98), call('/data/local/tmp/test_python_2938/@test_2938_tmp-tardir/dir', 77, 76), call('/data/
local/tmp/test_python_2938/@test_2938_tmp-tardir/dir/numeric-owner-testfile', 88, 87)) not all found
in call list
----------------------------------------------------------------------
Ran 426 tests in 5.549s
FAILED (failures=2, skipped=80)
test test_tarfile failed
1 test failed:
test_tarfile
Total duration: 0:00:06
On the android-21-x86 emulator:
>>> import grp
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen failed: cannot locate symbol "setgrent" referenced by "grp.cpython-36m-i386-linux-gnu.so"...
The attached patch fixes the tarfile module to handle the case where the pwd module can be imported and the grp module cannot. With this fix test_tarfile runs without any failure.
The chown() method of the tarfile.TarFile class does not attempt to do a chown when pwd is None, even when numeric_owner is True, and although an attempt is made to fall back to tarinfo.gid when getgrnam() fails, or to tarinfo.uid when getgrnam() fails, nothing is done if only one of the grp or pwd modules fails on import.
This new patch is similar to the previous one and is more explicit.