Skip to content

Commit 7a2a910

Browse files
committed
Ignore time for 7z entry listings on windows
Somehow the file time is off by 2 hours and not GMT on Windows-only. And only when we list entries. Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 0474798 commit 7a2a910

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

tests/extractcode/test_sevenzip.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
class TestSevenZip(FileBasedTesting):
4343
test_data_dir = os.path.join(os.path.dirname(__file__), 'data')
4444

45-
def check_results_with_expected_json(self, results, expected_loc, regen=False):
45+
def check_results_with_expected_json(self, results, expected_loc, clean_dates=False, regen=False):
4646
if regen:
4747
if py2:
4848
wmode = 'wb'
@@ -53,8 +53,20 @@ def check_results_with_expected_json(self, results, expected_loc, regen=False):
5353

5454
with open(expected_loc, 'rb') as ex:
5555
expected = json.load(ex, encoding='utf-8')
56+
if clean_dates:
57+
if isinstance(results, list):
58+
self.clean_dates(results)
59+
self.clean_dates(expected)
60+
5661
assert expected == results
5762

63+
def clean_dates(self, results):
64+
if isinstance(results, list):
65+
for res in results:
66+
# remove time from date/time stamp
67+
if 'date' in res:
68+
res['date'] = res['date'].partition(' ')[0]
69+
5870
def test_get_7z_errors_password_protected(self):
5971
test = '''
6072
7-Zip 9.04 beta Copyright (c) 1999-2009 Igor Pavlov 2009-05-30
@@ -152,7 +164,7 @@ def test_list_entries_of_special_tar_win(self):
152164
entries = [e.to_dict(full=True) for e in entries]
153165
errors = errors or []
154166
results = entries + errors
155-
self.check_results_with_expected_json(results, expected_loc, regen=False)
167+
self.check_results_with_expected_json(results, expected_loc, clean_dates=True, regen=False)
156168

157169
@skipIf(on_windows, 'Windows file-by-file extracton is not working well')
158170
def test_list_entries_with_weird_names_7z(self):
@@ -172,7 +184,7 @@ def test_list_entries_with_weird_names_7z_win(self):
172184
entries = [e.to_dict(full=True) for e in entries]
173185
errors = errors or []
174186
results = entries + errors
175-
self.check_results_with_expected_json(results, expected_loc, regen=False)
187+
self.check_results_with_expected_json(results, expected_loc, clean_dates=True, regen=False)
176188

177189

178190
class TestSevenParseListing(TestSevenZip):

0 commit comments

Comments
 (0)