Hello community, here is the log from the commit of package python-rarfile for openSUSE:Factory checked in at 2019-09-23 12:39:11 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-rarfile (Old) and /work/SRC/openSUSE:Factory/.python-rarfile.new.7948 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-rarfile" Mon Sep 23 12:39:11 2019 rev:2 rq:732398 version:3.1 Changes: -------- --- /work/SRC/openSUSE:Factory/python-rarfile/python-rarfile.changes 2017-04-14 13:34:55.559092621 +0200 +++ /work/SRC/openSUSE:Factory/.python-rarfile.new.7948/python-rarfile.changes 2019-09-23 12:39:43.445587192 +0200 @@ -1,0 +2,6 @@ +Sat Sep 21 13:58:36 UTC 2019 - Luigi Baldoni <[email protected]> + +- Update to version 3.1 (no changelog available) +- Spec cleanup + +------------------------------------------------------------------- Old: ---- rarfile-3.0.tar.gz New: ---- rarfile-3.1.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-rarfile.spec ++++++ --- /var/tmp/diff_new_pack.QIBzJ4/_old 2019-09-23 12:39:44.021587097 +0200 +++ /var/tmp/diff_new_pack.QIBzJ4/_new 2019-09-23 12:39:44.021587097 +0200 @@ -1,7 +1,7 @@ # # spec file for package python-rarfile # -# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -12,26 +12,25 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# Please submit bugfixes or comments via https://bugs.opensuse.org/ # %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-rarfile -Version: 3.0 +Version: 3.1 Release: 0 Summary: RAR Archive Reader for Python License: ISC Group: Development/Languages/Python -Url: https://rarfile.readthedocs.org/ -Source0: https://pypi.io/packages/source/r/rarfile/rarfile-%{version}.tar.gz +URL: https://rarfile.readthedocs.org/ +Source0: https://files.pythonhosted.org/packages/source/r/rarfile/rarfile-%{version}.tar.gz BuildRequires: %{python_module setuptools} BuildRequires: fdupes BuildRequires: python-rpm-macros BuildRequires: python3-Sphinx >= 1.3 Requires: bsdtar Recommends: unrar -BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildArch: noarch %python_subpackages @@ -59,21 +58,19 @@ %python_build make %{?_smp_mflags} -C doc html rm doc/_build/html/.buildinfo -sed -i 's/\r$//' doc/_build/html/objects.inv %install %python_install %python_expand %fdupes -s %{buildroot}%{$python_sitelib} %files %{python_files} -%defattr(-,root,root,-) -%doc LICENSE +%license LICENSE %pycache_only %{python_sitelib}/__pycache__/rarfile.*.py* %{python_sitelib}/rarfile.py* %{python_sitelib}/rarfile-%{version}-py%{python_version}.egg-info %files %{python_files doc} -%defattr(-,root,root,-) -%doc LICENSE doc/_build/html/ +%license LICENSE +%doc doc/_build/html/ %changelog ++++++ rarfile-3.0.tar.gz -> rarfile-3.1.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/LICENSE new/rarfile-3.1/LICENSE --- old/rarfile-3.0/LICENSE 2016-06-08 22:14:13.000000000 +0200 +++ new/rarfile-3.1/LICENSE 2019-09-15 15:51:09.000000000 +0200 @@ -1,5 +1,5 @@ -Copyright (c) 2005-2016 Marko Kreen <[email protected]> +Copyright (c) 2005-2019 Marko Kreen <[email protected]> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/MANIFEST.in new/rarfile-3.1/MANIFEST.in --- old/rarfile-3.0/MANIFEST.in 2016-06-08 22:14:13.000000000 +0200 +++ new/rarfile-3.1/MANIFEST.in 2019-03-29 12:45:00.000000000 +0100 @@ -1,3 +1,3 @@ include README.rst Makefile MANIFEST.in LICENSE dumprar.py include doc/*.rst doc/Makefile doc/conf.py doc/make.bat -include test/Makefile test/*.sh test/files/*.rar test/files/*.exp +include test/Makefile test/*.sh test/files/*.rar test/files/*.r[0-9][0-9] test/files/*.exp diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/Makefile new/rarfile-3.1/Makefile --- old/rarfile-3.0/Makefile 2016-06-08 23:49:55.000000000 +0200 +++ new/rarfile-3.1/Makefile 2019-09-15 14:42:30.000000000 +0200 @@ -1,15 +1,19 @@ +VER := $(shell python3 setup.py --version) +TGZ = dist/rarfile-$(VER).tar.gz + prefix = /usr/local all: pyflakes3 rarfile.py - tox + tox -e lint + tox -e py36-cryptography + tox -e py37 install: python setup.py install --prefix=$(prefix) -tgz: clean - python setup.py sdist +tgz: clean $(TGZ) clean: rm -rf __pycache__ build dist @@ -25,8 +29,11 @@ rbuild: curl -X POST https://readthedocs.org/build/6715 -upload: - python setup.py sdist upload +$(TGZ): + python3 setup.py sdist + +upload: $(TGZ) + twine upload $(TGZ) ack: for fn in test/files/*.py27; do \ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/PKG-INFO new/rarfile-3.1/PKG-INFO --- old/rarfile-3.0/PKG-INFO 2016-12-27 18:24:14.000000000 +0100 +++ new/rarfile-3.1/PKG-INFO 2019-09-15 15:54:32.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: rarfile -Version: 3.0 +Version: 3.1 Summary: RAR archive reader for Python Home-page: https://github.com/markokr/rarfile Author: Marko Kreen diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/doc/conf.py new/rarfile-3.1/doc/conf.py --- old/rarfile-3.0/doc/conf.py 2016-06-08 23:49:57.000000000 +0200 +++ new/rarfile-3.1/doc/conf.py 2019-09-15 15:51:09.000000000 +0200 @@ -30,7 +30,7 @@ autodoc_member_order = 'bysource' autoclass_content = 'both' -autodoc_default_flags = ['show-inheritance'] +autodoc_default_options = {'show-inheritance': True} intersphinx_mapping = {'python': ('https://docs.python.org/3', None)} @@ -48,7 +48,7 @@ # General information about the project. project = u'RarFile' -copyright = u'2005-2016, Marko Kreen' +copyright = u'2005-2019, Marko Kreen' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/doc/news.rst new/rarfile-3.1/doc/news.rst --- old/rarfile-3.0/doc/news.rst 2016-12-27 18:11:47.000000000 +0100 +++ new/rarfile-3.1/doc/news.rst 2019-09-15 15:45:35.000000000 +0200 @@ -4,6 +4,37 @@ .. py:currentmodule:: rarfile +Version 3.1 (2019-09-15) +------------------------ + +**This will be last version with support for Python 2.x** + +New feature: + +* Accept pathlib objects as filenames. + (Aleksey Popov) + +* Accept `bytes` filenames in Python 3 + (Nate Bogdanowicz) + +Fixes: + +* Use bug-compatible SHA1 for longer passwords (> 28 chars) + in RAR3 encrypted headers. + (Marko Kreen) + +* Return true/false from _check_unrar_tool + (miigotu) + +* Include all test files in archive + (Benedikt Morbach) + +* Include volume number in NeedFirstVolume exception if available (rar5). + +Cleanups: + +* Convert tests to pytest. + Version 3.0 (2016-12-27) ------------------------ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/dumprar.py new/rarfile-3.1/dumprar.py --- old/rarfile-3.0/dumprar.py 2016-06-08 23:41:03.000000000 +0200 +++ new/rarfile-3.1/dumprar.py 2019-09-15 15:05:12.000000000 +0200 @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 """Dump archive contents, test extraction.""" @@ -308,7 +308,7 @@ xprint(" arctime=%s", fmt_time(h.arctime)) if h.flags & rf.RAR_FILE_PASSWORD: enc_algo, enc_flags, kdf_count, salt, iv, checkval = h.file_encryption - algo_name = enc_algo == rf.RAR5_XENC_CIPHER_AES256 and 'AES256' or 'UnknownAlgo' + algo_name = 'AES256' if enc_algo == rf.RAR5_XENC_CIPHER_AES256 else 'UnknownAlgo' xprint(' algo=%d:%s enc_flags=%04x:%s kdf_lg=%d kdf_count=%d salt=%s iv=%s checkval=%s', enc_algo, algo_name, enc_flags, render_flags(enc_flags, r5_file_enc_flags), kdf_count, 1 << kdf_count, rf.tohex(salt), rf.tohex(iv), @@ -331,7 +331,7 @@ elif h.block_type == rf.RAR5_BLOCK_ENDARC: xprint(" flags=0x%04x:%s", h.flags, render_flags(h.endarc_flags, r5_endarc_flags)) elif h.block_type == rf.RAR5_BLOCK_ENCRYPTION: - algo_name = h.encryption_algo == rf.RAR5_XENC_CIPHER_AES256 and 'AES256' or 'UnknownAlgo' + algo_name = 'AES256' if h.encryption_algo == rf.RAR5_XENC_CIPHER_AES256 else 'UnknownAlgo' xprint(" algo=%d:%s flags=0x%04x:%s", h.encryption_algo, algo_name, h.flags, render_flags(h.encryption_flags, r5_enc_flags)) xprint(" kdf_lg=%d kdf_count=%d", h.encryption_kdf_count, 1 << h.encryption_kdf_count) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/rarfile.egg-info/PKG-INFO new/rarfile-3.1/rarfile.egg-info/PKG-INFO --- old/rarfile-3.0/rarfile.egg-info/PKG-INFO 2016-12-27 18:24:13.000000000 +0100 +++ new/rarfile-3.1/rarfile.egg-info/PKG-INFO 2019-09-15 15:54:32.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: rarfile -Version: 3.0 +Version: 3.1 Summary: RAR archive reader for Python Home-page: https://github.com/markokr/rarfile Author: Marko Kreen diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/rarfile.egg-info/SOURCES.txt new/rarfile-3.1/rarfile.egg-info/SOURCES.txt --- old/rarfile-3.0/rarfile.egg-info/SOURCES.txt 2016-12-27 18:24:14.000000000 +0100 +++ new/rarfile-3.1/rarfile.egg-info/SOURCES.txt 2019-09-15 15:54:32.000000000 +0200 @@ -49,6 +49,8 @@ test/files/rar3-comment-plain.rar.exp test/files/rar3-comment-psw.rar test/files/rar3-comment-psw.rar.exp +test/files/rar3-old.r00 +test/files/rar3-old.r01 test/files/rar3-old.rar test/files/rar3-old.rar.exp test/files/rar3-vols.part1.rar diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/rarfile.py new/rarfile-3.1/rarfile.py --- old/rarfile-3.0/rarfile.py 2016-12-23 16:16:30.000000000 +0100 +++ new/rarfile-3.1/rarfile.py 2019-09-15 15:46:44.000000000 +0200 @@ -1,6 +1,6 @@ # rarfile.py # -# Copyright (c) 2005-2016 Marko Kreen <[email protected]> +# Copyright (c) 2005-2019 Marko Kreen <[email protected]> # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -170,8 +170,17 @@ unicode = str _byte_code = int # noqa +# don't break 2.6 completely +if sys.hexversion < 0x2070000: + memoryview = lambda x: x # noqa -__version__ = '3.0' +try: + from pathlib import Path + _have_pathlib = True +except ImportError: + _have_pathlib = False + +__version__ = '3.1' # export only interesting items __all__ = ['is_rarfile', 'RarInfo', 'RarFile', 'RarExtFile'] @@ -215,6 +224,12 @@ ALT_TEST_ARGS = ('-t', '-f') ALT_CHECK_ARGS = ('--help',) +#ALT_TOOL = 'unar' +#ALT_OPEN_ARGS = ('-o', '-') +#ALT_EXTRACT_ARGS = () +#ALT_TEST_ARGS = ('-test',) # does not work +#ALT_CHECK_ARGS = ('-v',) + #: whether to speed up decompression by using tmp archive USE_EXTRACT_HACK = 1 @@ -646,7 +661,11 @@ Either "stop" to quietly stop parsing on errors, or "strict" to raise errors. Default is "stop". """ - self._rarfile = rarfile + if _have_pathlib and isinstance(rarfile, Path): + self._rarfile = str(rarfile) + else: + self._rarfile = rarfile + self._charset = charset or DEFAULT_CHARSET self._info_callback = info_callback self._crc_check = crc_check @@ -794,6 +813,8 @@ """ if isinstance(member, RarInfo): fname = member.filename + elif _have_pathlib and isinstance(member, Path): + fname = str(member) else: fname = member self._extract([fname], path, pwd) @@ -879,6 +900,8 @@ # destination path if path is not None: + if _have_pathlib and isinstance(path, Path): + path = str(path) cmd.append(path + os.sep) # call @@ -948,6 +971,8 @@ """ if isinstance(member, RarInfo): fname = member.filename + elif _have_pathlib and isinstance(member, Path): + fname = str(member) else: fname = member @@ -1024,6 +1049,12 @@ # RAR 2.x does not set FIRSTVOLUME, # so check it only if NEWNUMBERING is used if (h.flags & RAR_MAIN_FIRSTVOLUME) == 0: + if getattr(h, 'main_volume_number', None) is not None: + # rar5 may have more info + raise NeedFirstVolume( + "Need to start from first volume (current: %r)" + % (h.main_volume_number,) + ) raise NeedFirstVolume("Need to start from first volume") if h.flags & RAR_MAIN_PASSWORD: self._needs_password = True @@ -1072,7 +1103,7 @@ # handle encrypted headers if (self._main and self._main.flags & RAR_MAIN_PASSWORD) or self._hdrenc_main: if not self._password: - return + return None fd = self._decrypt_header(fd) # now read actual header @@ -1673,7 +1704,7 @@ def _parse_main_block(self, h, hdata, pos): h.main_flags, pos = load_vint(hdata, pos) if h.main_flags & RAR5_MAIN_FLAG_HAS_VOLNR: - h.main_volume_number = load_vint(hdata, pos) + h.main_volume_number, pos = load_vint(hdata, pos) h.flags |= RAR_MAIN_NEWNUMBERING if h.main_flags & RAR5_MAIN_FLAG_SOLID: @@ -1874,6 +1905,7 @@ # rar bug? - appends zero to comment cmt = cmt.split(ZERO, 1)[0] self.comment = cmt.decode('utf8') + return None def _open_hack(self, inf, psw): # len, type, blk_flags, flags @@ -2033,6 +2065,7 @@ def _read(self, cnt): """Actual read that gets sanitized cnt.""" + raise NotImplementedError("_read") def close(self): """Close open resources.""" @@ -2525,6 +2558,53 @@ """Hexadecimal digest.""" return tohex(self.digest()) + +class Rar3Sha1(object): + """Bug-compat for SHA1 + """ + digest_size = 20 + block_size = 64 + + _BLK_BE = struct.Struct(b'>16L') + _BLK_LE = struct.Struct(b'<16L') + + __slots__ = ('_nbytes', '_md', '_rarbug') + + def __init__(self, data=b'', rarbug=False): + self._md = sha1() + self._nbytes = 0 + self._rarbug = rarbug + self.update(data) + + def update(self, data): + """Process more data.""" + self._md.update(data) + bufpos = self._nbytes & 63 + self._nbytes += len(data) + + if self._rarbug and len(data) > 64: + dpos = self.block_size - bufpos + while dpos + self.block_size <= len(data): + self._corrupt(data, dpos) + dpos += self.block_size + + def digest(self): + """Return final state.""" + return self._md.digest() + + def hexdigest(self): + """Return final state as hex string.""" + return self._md.hexdigest() + + def _corrupt(self, data, dpos): + """Corruption from SHA1 core.""" + ws = list(self._BLK_BE.unpack_from(data, dpos)) + for t in range(16, 80): + tmp = ws[(t - 3) & 15] ^ ws[(t - 8) & 15] ^ ws[(t - 14) & 15] ^ ws[(t - 16) & 15] + ws[t & 15] = ((tmp << 1) | (tmp >> (32 - 1))) & 0xFFFFFFFF + self._BLK_LE.pack_into(data, dpos, *ws) + + ## ## Utility functions ## @@ -2672,7 +2752,12 @@ def is_filelike(obj): """Filename or file object? """ - if isinstance(obj, str) or isinstance(obj, unicode): + if _have_pathlib: + filename_types = (bytes, unicode, Path) + else: + filename_types = (bytes, unicode) + + if isinstance(obj, filename_types): return False res = True for a in ('read', 'tell', 'seek'): @@ -2686,13 +2771,14 @@ """ if not isinstance(psw, unicode): psw = psw.decode('utf8') - seed = psw.encode('utf-16le') + salt + seed = bytearray(psw.encode('utf-16le') + salt) + h = Rar3Sha1(rarbug=True) iv = EMPTY - h = sha1() for i in range(16): for j in range(0x4000): cnt = S_LONG.pack(i * 0x4000 + j) - h.update(seed + cnt[:3]) + h.update(seed) + h.update(cnt[:3]) if j == 0: iv += h.digest()[19:20] key_be = h.digest()[:16] @@ -2814,6 +2900,8 @@ except OSError as ex: if ex.errno == errno.ENOENT: raise RarCannotExec("Unrar not installed? (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL) + if ex.errno == errno.EACCES or ex.errno == errno.EPERM: + raise RarCannotExec("Cannot execute unrar (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL) raise return p @@ -2945,7 +3033,8 @@ TEST_ARGS = ALT_TEST_ARGS except RarCannotExec: # no usable tool, only uncompressed archives work - pass + return False + return True _check_unrar_tool() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/setup.cfg new/rarfile-3.1/setup.cfg --- old/rarfile-3.0/setup.cfg 2016-12-27 18:24:14.000000000 +0100 +++ new/rarfile-3.1/setup.cfg 2019-09-15 15:54:32.000000000 +0200 @@ -1,5 +1,4 @@ [egg_info] tag_build = tag_date = 0 -tag_svn_revision = 0 Binary files old/rarfile-3.0/test/files/rar3-old.r00 and new/rarfile-3.1/test/files/rar3-old.r00 differ Binary files old/rarfile-3.0/test/files/rar3-old.r01 and new/rarfile-3.1/test/files/rar3-old.r01 differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/test/run_dump.sh new/rarfile-3.1/test/run_dump.sh --- old/rarfile-3.0/test/run_dump.sh 2016-06-08 23:41:03.000000000 +0200 +++ new/rarfile-3.1/test/run_dump.sh 2019-09-15 14:01:17.000000000 +0200 @@ -35,7 +35,10 @@ fi echo "#### $py ####" >> "$diffs" diff -uw "$f.exp" "$f.$tag" >> "$diffs" - result=1 + case "$f" in + *-hpsw.rar) ;; + *) result=1;; + esac fi done diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/test/test_api.py new/rarfile-3.1/test/test_api.py --- old/rarfile-3.0/test/test_api.py 2016-06-08 23:41:03.000000000 +0200 +++ new/rarfile-3.1/test/test_api.py 2019-09-15 15:29:48.000000000 +0200 @@ -1,54 +1,62 @@ """API tests. """ -import sys import io import os -from nose.tools import * +import pytest import rarfile +if rarfile._have_pathlib: + from pathlib import Path + # # test start # -@raises(NotImplementedError) def test_bad_arc_mode_w(): - rarfile.RarFile('test/files/rar3-comment-plain.rar', 'w') + with pytest.raises(NotImplementedError): + rarfile.RarFile('test/files/rar3-comment-plain.rar', 'w') -@raises(NotImplementedError) def test_bad_arc_mode_rb(): - rarfile.RarFile('test/files/rar3-comment-plain.rar', 'rb') + with pytest.raises(NotImplementedError): + rarfile.RarFile('test/files/rar3-comment-plain.rar', 'rb') -@raises(ValueError) def test_bad_errs(): - rarfile.RarFile('test/files/rar3-comment-plain.rar', 'r', errors='foo') + with pytest.raises(ValueError): + rarfile.RarFile('test/files/rar3-comment-plain.rar', 'r', errors='foo') -@raises(NotImplementedError) def test_bad_open_mode_w(): rf = rarfile.RarFile('test/files/rar3-comment-plain.rar') - rf.open('qwe', 'w') + with pytest.raises(NotImplementedError): + rf.open('qwe', 'w') -@raises(rarfile.PasswordRequired) def test_bad_open_psw(): rf = rarfile.RarFile('test/files/rar3-comment-psw.rar') - rf.open('file1.txt') + with pytest.raises(rarfile.PasswordRequired): + rf.open('file1.txt') -@raises(ValueError) def test_bad_filelike(): - rarfile.is_rarfile(bytearray(10)) + with pytest.raises(ValueError): + rarfile.is_rarfile(bytearray(10)) def test_open_psw_late_rar3(): rf = rarfile.RarFile('test/files/rar3-comment-psw.rar') - rf.open('file1.txt', 'r', 'password').read() - rf.open('file1.txt', 'r', u'password').read() + d1 = rf.open('file1.txt', 'r', 'password').read() + d2 = rf.open('file1.txt', 'r', u'password').read() + assert d1 == d2 def test_open_psw_late_rar5(): rf = rarfile.RarFile('test/files/rar5-psw.rar') rf.open('stest1.txt', 'r', 'password').read() rf.open('stest1.txt', 'r', u'password').read() +if rarfile._have_pathlib: + def test_open_pathlib_path(): + rf = rarfile.RarFile('test/files/rar5-psw.rar') + rf.open(Path('stest1.txt'), 'r', 'password').read() + def test_read_psw_late_rar3(): rf = rarfile.RarFile('test/files/rar3-comment-psw.rar') rf.read('file1.txt', 'password') @@ -59,32 +67,46 @@ rf.read('stest1.txt', 'password') rf.read('stest1.txt', u'password') -@raises(rarfile.BadRarFile) # needs better error def test_open_psw_late(): rf = rarfile.RarFile('test/files/rar5-psw.rar') - rf.read('stest1.txt', 'password222') + with pytest.raises(rarfile.BadRarFile): + rf.read('stest1.txt', 'password222') + +if rarfile._have_pathlib: + def test_create_from_pathlib_path(): + # Make sure we can open both relative and absolute Paths + rarfile.RarFile(Path('test/files/rar5-psw.rar')) + rarfile.RarFile(Path('test/files/rar5-psw.rar').resolve()) def test_detection(): - eq_(rarfile.is_rarfile('test/files/ctime4.rar.exp'), False) - eq_(rarfile.is_rarfile('test/files/ctime4.rar'), True) - eq_(rarfile.is_rarfile('test/files/rar5-crc.rar'), True) + assert rarfile.is_rarfile('test/files/ctime4.rar.exp') is False + assert rarfile.is_rarfile('test/files/ctime4.rar') is True + assert rarfile.is_rarfile('test/files/rar5-crc.rar') is True + + if rarfile._have_pathlib: + assert rarfile.is_rarfile(Path('test/files/rar5-crc.rar')) is True + -@raises(rarfile.BadRarFile) def test_signature_error(): - rarfile.RarFile('test/files/ctime4.rar.exp') + with pytest.raises(rarfile.BadRarFile): + rarfile.RarFile('test/files/ctime4.rar.exp') -@raises(rarfile.BadRarFile) def test_signature_error_mem(): data = io.BytesIO(b'x'*40) - rarfile.RarFile(data) + with pytest.raises(rarfile.BadRarFile): + rarfile.RarFile(data) def test_with(): with rarfile.RarFile('test/files/rar5-crc.rar') as rf: + data = rf.read('stest1.txt') with rf.open('stest1.txt') as f: + dst = io.BytesIO() while 1: buf = f.read(7) if not buf: break + dst.write(buf) + assert dst.getvalue() == data def test_readline(): def load_readline(rf, fn): @@ -101,26 +123,14 @@ rf = rarfile.RarFile('test/files/seektest.rar') v1 = load_readline(rf, 'stest1.txt') v2 = load_readline(rf, 'stest2.txt') - eq_(len(v1), 512) - eq_(v1, v2) - -_old_stdout = None -_buf_stdout = None - -def install_buf(): - global _old_stdout, _buf_stdout - _buf_stdout = io.StringIO() - _old_stdout = sys.stdout - sys.stdout = _buf_stdout - -def uninstall_buf(): - sys.stdout = _old_stdout + assert len(v1) == 512 + assert v1 == v2 -@with_setup(install_buf, uninstall_buf) -def test_printdir(): +def test_printdir(capsys): rf = rarfile.RarFile('test/files/seektest.rar') rf.printdir() - eq_(_buf_stdout.getvalue(), u'stest1.txt\nstest2.txt\n') + res = capsys.readouterr() + assert res.out == u'stest1.txt\nstest2.txt\n' def test_testrar(): rf = rarfile.RarFile('test/files/seektest.rar') @@ -131,64 +141,63 @@ rf = rarfile.RarFile(io.BytesIO(arc)) rf.testrar() -def clean_extract_dirs(): - for dn in ['tmp/extract1', 'tmp/extract2', 'tmp/extract3']: - for fn in ['stest1.txt', 'stest2.txt']: - try: - os.unlink(os.path.join(dn, fn)) - except OSError: - pass - try: - os.rmdir(dn) - except OSError: - pass - -@with_setup(clean_extract_dirs, clean_extract_dirs) -def test_extract(): - os.makedirs('tmp/extract1') - os.makedirs('tmp/extract2') - os.makedirs('tmp/extract3') +def test_extract(tmp_path): + ex1 = tmp_path / "extract1" + ex2 = tmp_path / "extract2" + ex3 = tmp_path / "extract3" + os.makedirs(str(ex1)) + os.makedirs(str(ex2)) + os.makedirs(str(ex3)) rf = rarfile.RarFile('test/files/seektest.rar') - rf.extractall('tmp/extract1') - assert_true(os.path.isfile('tmp/extract1/stest1.txt')) - assert_true(os.path.isfile('tmp/extract1/stest2.txt')) - - rf.extract('stest1.txt', 'tmp/extract2') - assert_true(os.path.isfile('tmp/extract2/stest1.txt')) - assert_false(os.path.isfile('tmp/extract2/stest2.txt')) + rf.extractall(str(ex1)) + assert os.path.isfile(str(ex1 / 'stest1.txt')) is True + assert os.path.isfile(str(ex1 / 'stest2.txt')) is True + + rf.extract('stest1.txt', str(ex2)) + assert os.path.isfile(str(ex2 / 'stest1.txt')) is True + assert os.path.isfile(str(ex2 / 'stest2.txt')) is False inf = rf.getinfo('stest2.txt') - rf.extract(inf, 'tmp/extract3') - assert_false(os.path.isfile('tmp/extract3/stest1.txt')) - assert_true(os.path.isfile('tmp/extract3/stest2.txt')) - - rf.extractall('tmp/extract2', ['stest1.txt']) - assert_true(os.path.isfile('tmp/extract2/stest1.txt')) - - rf.extractall('tmp/extract3', [rf.getinfo('stest2.txt')]) - assert_true(os.path.isfile('tmp/extract3/stest2.txt')) - -@with_setup(clean_extract_dirs, clean_extract_dirs) -def test_extract_mem(): - os.makedirs('tmp/extract1') - os.makedirs('tmp/extract2') - os.makedirs('tmp/extract3') + rf.extract(inf, str(ex3)) + assert os.path.isfile(str(ex3 / 'stest1.txt')) is False + assert os.path.isfile(str(ex3 / 'stest2.txt')) is True + + rf.extractall(str(ex2), ['stest1.txt']) + assert os.path.isfile(str(ex2 / 'stest1.txt')) is True + + rf.extractall(str(ex3), [rf.getinfo('stest2.txt')]) + assert os.path.isfile(str(ex3 / 'stest2.txt')) is True + + if rarfile._have_pathlib: + ex4 = tmp_path / "extract4" + os.makedirs(str(ex4)) + rf.extractall(ex4) + assert os.path.isfile(str(ex4 / 'stest1.txt')) is True + assert os.path.isfile(str(ex4 / 'stest2.txt')) is True + +def test_extract_mem(tmp_path): + ex1 = tmp_path / "extract11" + ex2 = tmp_path / "extract22" + ex3 = tmp_path / "extract33" + os.makedirs(str(ex1)) + os.makedirs(str(ex2)) + os.makedirs(str(ex3)) arc = open('test/files/seektest.rar', 'rb').read() rf = rarfile.RarFile(io.BytesIO(arc)) - rf.extractall('tmp/extract1') - assert_true(os.path.isfile('tmp/extract1/stest1.txt')) - assert_true(os.path.isfile('tmp/extract1/stest2.txt')) - - rf.extract('stest1.txt', 'tmp/extract2') - assert_true(os.path.isfile('tmp/extract2/stest1.txt')) - assert_false(os.path.isfile('tmp/extract2/stest2.txt')) + rf.extractall(str(ex1)) + assert os.path.isfile(str(ex1 / 'stest1.txt')) is True + assert os.path.isfile(str(ex1 / 'stest2.txt')) is True + + rf.extract('stest1.txt', str(ex2)) + assert os.path.isfile(str(ex2 / 'stest1.txt')) is True + assert os.path.isfile(str(ex2 / 'stest2.txt')) is False inf = rf.getinfo('stest2.txt') - rf.extract(inf, 'tmp/extract3') - assert_false(os.path.isfile('tmp/extract3/stest1.txt')) - assert_true(os.path.isfile('tmp/extract3/stest2.txt')) + rf.extract(inf, str(ex3)) + assert os.path.isfile(str(ex3 / 'stest1.txt')) is False + assert os.path.isfile(str(ex3 / 'stest2.txt')) is True def test_infocb(): infos = [] @@ -196,22 +205,22 @@ infos.append( (info.type, info.needs_password(), info.isdir(), info._must_disable_hack()) ) rf = rarfile.RarFile('test/files/seektest.rar', info_callback=info_cb) - eq_(infos, [ + assert infos == [ (rarfile.RAR_BLOCK_MAIN, False, False, False), (rarfile.RAR_BLOCK_FILE, False, False, False), (rarfile.RAR_BLOCK_FILE, False, False, False), - (rarfile.RAR_BLOCK_ENDARC, False, False, False)]) + (rarfile.RAR_BLOCK_ENDARC, False, False, False)] infos = [] rf = rarfile.RarFile('test/files/rar5-solid-qo.rar', info_callback=info_cb) - eq_(infos, [ + assert infos == [ (rarfile.RAR_BLOCK_MAIN, False, False, True), (rarfile.RAR_BLOCK_FILE, False, False, False), (rarfile.RAR_BLOCK_FILE, False, False, True), (rarfile.RAR_BLOCK_FILE, False, False, True), (rarfile.RAR_BLOCK_FILE, False, False, True), (rarfile.RAR_BLOCK_SUB, False, False, False), - (rarfile.RAR_BLOCK_ENDARC, False, False, False)]) + (rarfile.RAR_BLOCK_ENDARC, False, False, False)] def install_alt_tool(): rarfile.ORIG_UNRAR_TOOL = 'x_unrar_missing' @@ -226,7 +235,7 @@ for fn in rf.namelist(): rf.read(fn) -@with_setup(install_alt_tool, uninstall_alt_tool) +#@with_setup(install_alt_tool, uninstall_alt_tool) def test_alt_tool(): #test_read_rar3() pass diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/test/test_crypto.py new/rarfile-3.1/test/test_crypto.py --- old/rarfile-3.0/test/test_crypto.py 2016-06-08 23:41:03.000000000 +0200 +++ new/rarfile-3.1/test/test_crypto.py 2019-09-15 13:40:37.000000000 +0200 @@ -5,7 +5,7 @@ from binascii import unhexlify -from nose.tools import * +import pytest import rarfile @@ -19,26 +19,27 @@ except ImportError: pass -if rarfile._have_crypto: - def test_aes128_cbc(): - data = b'0123456789abcdef' * 2 - key = b'\x02' * 16 - iv = b'\x80' * 16 - - #encdata = aes_encrypt(key, iv, data) - encdata = unhexlify('4b0d438b4a1b972bd4ab81cd64674dcce4b0158090fbe616f455354284d53502') - - ctx = rarfile.AES_CBC_Decrypt(key, iv) - eq_(ctx.decrypt(encdata), data) - - def test_aes256_cbc(): - data = b'0123456789abcdef' * 2 - key = b'\x52' * 32 - iv = b'\x70' * 16 [email protected](not rarfile._have_crypto, reason="No crypto") +def test_aes128_cbc(): + data = b'0123456789abcdef' * 2 + key = b'\x02' * 16 + iv = b'\x80' * 16 + + #encdata = aes_encrypt(key, iv, data) + encdata = unhexlify('4b0d438b4a1b972bd4ab81cd64674dcce4b0158090fbe616f455354284d53502') + + ctx = rarfile.AES_CBC_Decrypt(key, iv) + assert ctx.decrypt(encdata) == data + [email protected](not rarfile._have_crypto, reason="No crypto") +def test_aes256_cbc(): + data = b'0123456789abcdef' * 2 + key = b'\x52' * 32 + iv = b'\x70' * 16 - #encdata = aes_encrypt(key, iv, data) - encdata = unhexlify('24988f387592e4d95b6eaab013137a221f81b25aa7ecde0ef4f4d7a95f92c250') + #encdata = aes_encrypt(key, iv, data) + encdata = unhexlify('24988f387592e4d95b6eaab013137a221f81b25aa7ecde0ef4f4d7a95f92c250') - ctx = rarfile.AES_CBC_Decrypt(key, iv) - eq_(ctx.decrypt(encdata), data) + ctx = rarfile.AES_CBC_Decrypt(key, iv) + assert ctx.decrypt(encdata) == data diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/test/test_format.py new/rarfile-3.1/test/test_format.py --- old/rarfile-3.0/test/test_format.py 2016-06-08 23:41:03.000000000 +0200 +++ new/rarfile-3.1/test/test_format.py 2019-09-15 15:39:05.000000000 +0200 @@ -1,13 +1,8 @@ """Format details. """ -import sys -import io -import os - from datetime import datetime -from nose.tools import * - +import pytest import rarfile def render_date(dt): @@ -63,41 +58,37 @@ return '; '.join(problems) def cmp_struct(a, b): - eq_(a, b, diffs(a, b)) + assert a == b, diffs(a, b) # # test start # [email protected](not rarfile._have_crypto, reason="No crypto") def test_rar3_header_encryption(): r = rarfile.RarFile('test/files/rar3-comment-hpsw.rar', 'r') - eq_(r.needs_password(), True) - eq_(r.comment, None) - eq_(r.namelist(), []) - - try: - r.setpassword('password') - assert_true(r.needs_password()) - eq_(r.namelist(), [u'file1.txt', u'file2.txt']) - assert_not_equal(r.comment, None) - eq_(r.comment, 'RARcomment\n') - except rarfile.NoCrypto: - pass + assert r.needs_password() is True + assert r.comment is None + assert r.namelist() == [] + + r.setpassword('password') + assert r.needs_password() is True + assert r.namelist() == [u'file1.txt', u'file2.txt'] + assert r.comment is not None + assert r.comment == 'RARcomment\n' [email protected](not rarfile._have_crypto, reason="No crypto") def test_rar5_header_encryption(): r = rarfile.RarFile('test/files/rar5-hpsw.rar') - eq_(r.needs_password(), True) - eq_(r.comment, None) - eq_(r.namelist(), []) - - try: - r.setpassword('password') - assert_true(r.needs_password()) - eq_(r.namelist(), [u'stest1.txt', u'stest2.txt']) - assert_not_equal(r.comment, None) - eq_(r.comment, 'RAR5 archive - hdr-password\n') - except rarfile.NoCrypto: - pass + assert r.needs_password() is True + assert r.comment is None + assert r.namelist() == [] + + r.setpassword('password') + assert r.needs_password() is True + assert r.namelist() == [u'stest1.txt', u'stest2.txt'] + assert r.comment is not None + assert r.comment == 'RAR5 archive - hdr-password\n' r.close() def get_vol_info(extver=20, tz='', hr='11'): @@ -125,36 +116,42 @@ def test_rar3_vols(): r = rarfile.RarFile('test/files/rar3-vols.part1.rar') - eq_(r.needs_password(), False) - eq_(r.comment, None) - eq_(r.strerror(), None) + assert r.needs_password() is False + assert r.comment is None + assert r.strerror() is None cmp_struct(dumparc(r), get_vol_info()) - eq_(r.volumelist(), [ + assert r.volumelist() == [ 'test/files/rar3-vols.part1.rar', 'test/files/rar3-vols.part2.rar', - 'test/files/rar3-vols.part3.rar']) + 'test/files/rar3-vols.part3.rar'] + with pytest.raises(rarfile.NeedFirstVolume): + rarfile.RarFile('test/files/rar3-vols.part2.rar') def test_rar3_oldvols(): r = rarfile.RarFile('test/files/rar3-old.rar') - eq_(r.needs_password(), False) - eq_(r.comment, None) - eq_(r.strerror(), None) + assert r.needs_password() is False + assert r.comment is None + assert r.strerror() is None cmp_struct(dumparc(r), get_vol_info()) - eq_(r.volumelist(), [ + assert r.volumelist() == [ 'test/files/rar3-old.rar', 'test/files/rar3-old.r00', - 'test/files/rar3-old.r01']) + 'test/files/rar3-old.r01'] + with pytest.raises(rarfile.NeedFirstVolume): + rarfile.RarFile('test/files/rar3-old.r00') def test_rar5_vols(): r = rarfile.RarFile('test/files/rar5-vols.part1.rar') - eq_(r.needs_password(), False) - eq_(r.comment, None) - eq_(r.strerror(), None) + assert r.needs_password() is False + assert r.comment is None + assert r.strerror() is None cmp_struct(dumparc(r), get_vol_info(50, '+00:00', '08')) - eq_(r.volumelist(), [ + assert r.volumelist() == [ 'test/files/rar5-vols.part1.rar', 'test/files/rar5-vols.part2.rar', - 'test/files/rar5-vols.part3.rar']) + 'test/files/rar5-vols.part3.rar'] + with pytest.raises(rarfile.NeedFirstVolume): + rarfile.RarFile('test/files/rar5-vols.part2.rar') def expect_ctime(mtime, ctime): return [mkitem( @@ -207,17 +204,17 @@ )]) def test_oldvols(): - eq_(rarfile._next_oldvol('qq00.part0.rar'), 'qq00.part0.r00') - eq_(rarfile._next_oldvol('qq00.part0.r00'), 'qq00.part0.r01') - eq_(rarfile._next_oldvol('qq00.part0.r29'), 'qq00.part0.r30') - eq_(rarfile._next_oldvol('qq00.part0.r99'), 'qq00.part0.s00') + assert rarfile._next_oldvol('qq00.part0.rar') == 'qq00.part0.r00' + assert rarfile._next_oldvol('qq00.part0.r00') == 'qq00.part0.r01' + assert rarfile._next_oldvol('qq00.part0.r29') == 'qq00.part0.r30' + assert rarfile._next_oldvol('qq00.part0.r99') == 'qq00.part0.s00' def test_newvols(): - eq_(rarfile._next_newvol('qq00.part0.rar'), 'qq00.part1.rar') - eq_(rarfile._next_newvol('qq00.part09.rar'), 'qq00.part10.rar') - eq_(rarfile._next_newvol('qq00.part99.rar'), 'qq00.paru00.rar') + assert rarfile._next_newvol('qq00.part0.rar') == 'qq00.part1.rar' + assert rarfile._next_newvol('qq00.part09.rar') == 'qq00.part10.rar' + assert rarfile._next_newvol('qq00.part99.rar') == 'qq00.paru00.rar' -@raises(rarfile.BadRarName) def test_newvols_err(): - rarfile._next_newvol('xx.rar') + with pytest.raises(rarfile.BadRarName): + rarfile._next_newvol('xx.rar') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/test/test_hashing.py new/rarfile-3.1/test/test_hashing.py --- old/rarfile-3.0/test/test_hashing.py 2016-06-08 23:41:03.000000000 +0200 +++ new/rarfile-3.1/test/test_hashing.py 2019-09-15 13:53:08.000000000 +0200 @@ -3,31 +3,29 @@ from __future__ import division, print_function +import hashlib from binascii import unhexlify -from nose.tools import * - import rarfile - -from rarfile import Blake2SP, CRC32Context, NoHashContext, tohex +from rarfile import Blake2SP, CRC32Context, NoHashContext, tohex, Rar3Sha1 def test_nohash(): - eq_(NoHashContext('').hexdigest(), None) - eq_(NoHashContext('asd').hexdigest(), None) + assert NoHashContext('').hexdigest() is None + assert NoHashContext('asd').hexdigest() is None md = NoHashContext() md.update('asd') - eq_(md.digest(), None) + assert md.digest() is None def test_crc32(): - eq_(CRC32Context(b'').hexdigest(), '00000000') - eq_(CRC32Context(b'Hello').hexdigest(), 'f7d18982') - eq_(CRC32Context(b'Bye').hexdigest(), '4f7ad7d4') + assert CRC32Context(b'').hexdigest() == '00000000' + assert CRC32Context(b'Hello').hexdigest() == 'f7d18982' + assert CRC32Context(b'Bye').hexdigest() == '4f7ad7d4' md = CRC32Context() md.update(b'He') md.update(b'll') md.update(b'o') - eq_(md.hexdigest(), 'f7d18982') + assert md.hexdigest() == 'f7d18982' def xblake2sp(xdata): data = unhexlify(xdata) @@ -48,31 +46,59 @@ if rarfile._have_blake2: def test_blake2sp(): - eq_(Blake2SP(b'').hexdigest(), 'dd0e891776933f43c7d032b08a917e25741f8aa9a12c12e1cac8801500f2ca4f') - eq_(Blake2SP(b'Hello').hexdigest(), '0d6bae0db99f99183d060f7994bb94b45c6490b2a0a628b8b1346ebea8ec1d66') + assert Blake2SP(b'').hexdigest() == 'dd0e891776933f43c7d032b08a917e25741f8aa9a12c12e1cac8801500f2ca4f' + assert Blake2SP(b'Hello').hexdigest() == '0d6bae0db99f99183d060f7994bb94b45c6490b2a0a628b8b1346ebea8ec1d66' - eq_(xblake2sp(''), 'dd0e891776933f43c7d032b08a917e25741f8aa9a12c12e1cac8801500f2ca4f') - eq_(xblake2sp('00'), 'a6b9eecc25227ad788c99d3f236debc8da408849e9a5178978727a81457f7239') + assert xblake2sp('') == 'dd0e891776933f43c7d032b08a917e25741f8aa9a12c12e1cac8801500f2ca4f' + assert xblake2sp('00') == 'a6b9eecc25227ad788c99d3f236debc8da408849e9a5178978727a81457f7239' long1 = '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031' - eq_(xblake2sp(long1), '270affa6426f1a515c9b76dfc27d181fc2fd57d082a3ba2c1eef071533a6dfb7') + assert xblake2sp(long1) == '270affa6426f1a515c9b76dfc27d181fc2fd57d082a3ba2c1eef071533a6dfb7' long2 = long1 * 20 - eq_(xblake2sp(long2), '24a78d92592d0761a3681f32935225ca55ffb8eb16b55ab9481c89c59a985ff3') - eq_(xblake2sp_slow(long2), '24a78d92592d0761a3681f32935225ca55ffb8eb16b55ab9481c89c59a985ff3') + assert xblake2sp(long2) == '24a78d92592d0761a3681f32935225ca55ffb8eb16b55ab9481c89c59a985ff3' + assert xblake2sp_slow(long2) == '24a78d92592d0761a3681f32935225ca55ffb8eb16b55ab9481c89c59a985ff3' def test_hmac_sha256(): - eq_(tohex(rarfile.hmac_sha256(b'key', b'data')), '5031fe3d989c6d1537a013fa6e739da23463fdaec3b70137d828e36ace221bd0') + assert tohex(rarfile.hmac_sha256(b'key', b'data')) == '5031fe3d989c6d1537a013fa6e739da23463fdaec3b70137d828e36ace221bd0' + +def test_rar3_sha1(): + for n in range(0, 200): + data = bytearray([i for i in range(n)]) + h1 = hashlib.sha1(data).hexdigest() + h2 = Rar3Sha1(data).hexdigest() + assert h1 == h2 + + data = bytearray([(i & 255) for i in range(2000)]) + x1 = hashlib.sha1() + x2 = Rar3Sha1() + for step in (3, 17, 67, 128, 157): + pos = 0 + while pos < len(data): + pos2 = pos + step + if pos2 > len(data): + pos2 = len(data) + x1.update(data[pos:pos2]) + x2.update(data[pos:pos2]) + assert x1.hexdigest() == x2.hexdigest() + pos = pos2 def test_rar3_s2k(): exp = ('a160cb31cb262e9231c0b6fc984fbb0d', 'aa54a659fb0c359b30f353a6343fb11d') key, iv = rarfile.rar3_s2k(b'password', unhexlify('00FF00')) - eq_((tohex(key), tohex(iv)), exp) + assert (tohex(key), tohex(iv)) == exp key, iv = rarfile.rar3_s2k(u'password', unhexlify('00FF00')) - eq_((tohex(key), tohex(iv)), exp) + assert (tohex(key), tohex(iv)) == exp + + exp = ('ffff33ffaf31987c899ccc2f965a8927', 'bdff6873721b247afa4f978448a5aeef') + key, iv = rarfile.rar3_s2k(u'p'*28, unhexlify('1122334455667788')) + assert (tohex(key), tohex(iv)) == exp + exp = ('306cafde28f1ea78c9427c3ec642c0db', '173ecdf574c0bfe9e7c23bdfd96fa435') + key, iv = rarfile.rar3_s2k(u'p'*29, unhexlify('1122334455667788')) + assert (tohex(key), tohex(iv)) == exp if rarfile._have_crypto: def test_pbkdf2_hmac_sha256(): - eq_(tohex(rarfile.pbkdf2_sha256(b'password', b'salt', 100)), - '07e6997180cf7f12904f04100d405d34888fdf62af6d506a0ecc23b196fe99d8') + assert tohex(rarfile.pbkdf2_sha256(b'password', b'salt', 100)) == \ + '07e6997180cf7f12904f04100d405d34888fdf62af6d506a0ecc23b196fe99d8' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/test/test_korrupt.py new/rarfile-3.1/test/test_korrupt.py --- old/rarfile-3.0/test/test_korrupt.py 2016-06-08 23:41:03.000000000 +0200 +++ new/rarfile-3.1/test/test_korrupt.py 2019-09-15 13:54:10.000000000 +0200 @@ -1,9 +1,9 @@ """test corrupt file parsing. """ -import rarfile import glob import io +import rarfile def try_read(tmpfn): try: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/test/test_reading.py new/rarfile-3.1/test/test_reading.py --- old/rarfile-3.0/test/test_reading.py 2016-06-08 23:41:03.000000000 +0200 +++ new/rarfile-3.1/test/test_reading.py 2019-09-15 13:58:51.000000000 +0200 @@ -2,13 +2,10 @@ """ import io - from glob import glob - +import pytest import rarfile -from nose.tools import * - _done_reading = set() def run_reading_normal(fn, comment): @@ -18,8 +15,8 @@ return if rf.needs_password(): rf.setpassword('password') - eq_(rf.strerror(), None) - eq_(rf.comment, comment) + assert rf.strerror() is None + assert rf.comment == comment for ifn in rf.namelist(): # full read @@ -35,7 +32,7 @@ break total += len(buf) f.close() - eq_(total, item.file_size) + assert total == item.file_size # read from stream with readinto bbuf = bytearray(1024) @@ -84,12 +81,13 @@ def test_reading_rar3_psw(): run_reading('test/files/rar3-comment-psw.rar', u'RARcomment\n') -if rarfile._have_crypto: - def test_reading_rar3_hpsw(): - run_reading('test/files/rar3-comment-hpsw.rar', u'RARcomment\n') -else: - @raises(rarfile.NoCrypto) - def test_reading_rar3_hpsw_nocrypto(): [email protected](not rarfile._have_crypto, reason="No crypto") +def test_reading_rar3_hpsw(): + run_reading('test/files/rar3-comment-hpsw.rar', u'RARcomment\n') + [email protected](rarfile._have_crypto, reason="Has crypto") +def test_reading_rar3_hpsw_nocrypto(): + with pytest.raises(rarfile.NoCrypto): run_reading('test/files/rar3-comment-hpsw.rar', u'RARcomment\n') def test_reading_rar3_vols(): @@ -126,12 +124,13 @@ run_reading('test/files/rar5-vols.part2.rar') run_reading('test/files/rar5-vols.part3.rar') -if rarfile._have_crypto: - def test_reading_rar5_hpsw(): - run_reading('test/files/rar5-hpsw.rar', u'RAR5 archive - hdr-password\n') -else: - @raises(rarfile.NoCrypto) - def test_reading_rar5_hpsw(): [email protected](not rarfile._have_crypto, reason="No crypto") +def test_reading_rar5_hpsw(): + run_reading('test/files/rar5-hpsw.rar', u'RAR5 archive - hdr-password\n') + [email protected](rarfile._have_crypto, reason="Has crypto") +def test_reading_rar5_hpsw_nocrypto(): + with pytest.raises(rarfile.NoCrypto): run_reading('test/files/rar5-hpsw.rar', u'RAR5 archive - hdr-password\n') def test_reading_rar5_psw_blake(): @@ -144,7 +143,8 @@ problems = [] missed = [] for fn in glob('test/files/*.rar'): + fn = fn.replace('\\', '/') if fn not in _done_reading: missed.append(fn) - eq_(missed, problems) + assert missed == problems diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rarfile-3.0/test/test_seek.py new/rarfile-3.1/test/test_seek.py --- old/rarfile-3.0/test/test_seek.py 2016-06-08 23:41:03.000000000 +0200 +++ new/rarfile-3.1/test/test_seek.py 2019-09-15 13:54:01.000000000 +0200 @@ -4,8 +4,6 @@ import io import rarfile -from nose.tools import * - ARC = 'test/files/seektest.rar' def do_seek(f, pos, lim): @@ -23,7 +21,7 @@ got = f.tell() - eq_(got, exp) + assert got == exp ln = f.read(4) if got == fsize and ln: raise Exception('unexpected read') @@ -31,7 +29,7 @@ raise Exception('unexpected read failure') if ln: spos = int(ln) - eq_(spos*4, got) + assert spos*4 == got def run_seek(rf, fn): inf = rf.getinfo(fn)
