|
3 | 3 | from copy import copy |
4 | 4 | from os import stat |
5 | 5 |
|
6 | | -from libarchive import (file_reader, file_writer, memory_reader, |
7 | | - memory_writer) |
| 6 | +from libarchive import (file_reader, file_writer, memory_reader, memory_writer) |
8 | 7 |
|
9 | 8 | import pytest |
10 | 9 |
|
@@ -66,53 +65,65 @@ def test_file_atime_ctime(archfmt, timefmt, tmpdir): |
66 | 65 |
|
67 | 66 | @pytest.mark.parametrize('archfmt,timefmt', [('zip', int), ('pax', float)]) |
68 | 67 | def test_memory_time_setters(archfmt, timefmt): |
69 | | - # Create an archive of our libarchive/ directory |
| 68 | + has_birthtime = archfmt != 'zip' |
70 | 69 |
|
71 | | - atimestamp = (1482144741, 495628118) |
72 | | - mtimestamp = (1482155417, 659017086) |
73 | | - ctimestamp = (1482145211, 536858081) |
| 70 | + # Create an archive of our libarchive/ directory |
74 | 71 | buf = bytes(bytearray(1000000)) |
75 | 72 | with memory_writer(buf, archfmt) as archive1: |
76 | 73 | archive1.add_files('libarchive/') |
77 | 74 |
|
| 75 | + atimestamp = (1482144741, 495628118) |
| 76 | + mtimestamp = (1482155417, 659017086) |
| 77 | + ctimestamp = (1482145211, 536858081) |
| 78 | + btimestamp = (1482144740, 495628118) |
78 | 79 | buf2 = bytes(bytearray(1000000)) |
79 | 80 | with memory_reader(buf) as archive1: |
80 | 81 | with memory_writer(buf2, archfmt) as archive2: |
81 | 82 | for entry in archive1: |
82 | 83 | entry.set_atime(*atimestamp) |
83 | 84 | entry.set_mtime(*mtimestamp) |
84 | 85 | entry.set_ctime(*ctimestamp) |
| 86 | + if has_birthtime: |
| 87 | + entry.set_birthtime(*btimestamp) |
85 | 88 | archive2.add_entries([entry]) |
86 | 89 |
|
87 | 90 | with memory_reader(buf2) as archive2: |
88 | 91 | for entry in archive2: |
89 | 92 | assert entry.atime == time_check(atimestamp, timefmt) |
90 | 93 | assert entry.mtime == time_check(mtimestamp, timefmt) |
91 | 94 | assert entry.ctime == time_check(ctimestamp, timefmt) |
| 95 | + if has_birthtime: |
| 96 | + assert entry.birthtime == time_check(btimestamp, timefmt) |
92 | 97 |
|
93 | 98 |
|
94 | 99 | @pytest.mark.parametrize('archfmt,timefmt', [('zip', int), ('pax', float)]) |
95 | 100 | def test_file_time_setters(archfmt, timefmt, tmpdir): |
| 101 | + has_birthtime = archfmt != 'zip' |
| 102 | + |
96 | 103 | # Create an archive of our libarchive/ directory |
97 | 104 | archive_path = tmpdir.join('/test.{0}'.format(archfmt)).strpath |
98 | 105 | archive2_path = tmpdir.join('/test2.{0}'.format(archfmt)).strpath |
| 106 | + with file_writer(archive_path, archfmt) as archive1: |
| 107 | + archive1.add_files('libarchive/') |
99 | 108 |
|
100 | 109 | atimestamp = (1482144741, 495628118) |
101 | 110 | mtimestamp = (1482155417, 659017086) |
102 | 111 | ctimestamp = (1482145211, 536858081) |
103 | | - with file_writer(archive_path, archfmt) as archive1: |
104 | | - archive1.add_files('libarchive/') |
105 | | - |
| 112 | + btimestamp = (1482144740, 495628118) |
106 | 113 | with file_reader(archive_path) as archive1: |
107 | 114 | with file_writer(archive2_path, archfmt) as archive2: |
108 | 115 | for entry in archive1: |
109 | 116 | entry.set_atime(*atimestamp) |
110 | 117 | entry.set_mtime(*mtimestamp) |
111 | 118 | entry.set_ctime(*ctimestamp) |
| 119 | + if has_birthtime: |
| 120 | + entry.set_birthtime(*btimestamp) |
112 | 121 | archive2.add_entries([entry]) |
113 | 122 |
|
114 | 123 | with file_reader(archive2_path) as archive2: |
115 | 124 | for entry in archive2: |
116 | 125 | assert entry.atime == time_check(atimestamp, timefmt) |
117 | 126 | assert entry.mtime == time_check(mtimestamp, timefmt) |
118 | 127 | assert entry.ctime == time_check(ctimestamp, timefmt) |
| 128 | + if has_birthtime: |
| 129 | + assert entry.birthtime == time_check(btimestamp, timefmt) |
0 commit comments