MCPcopy Create free account
hub / github.com/wal-e/wal-e / test_creation_upper_dir

Function test_creation_upper_dir

tests/test_tar_hacks.py:106–151  ·  view source on GitHub ↗

Check for upper-directory creation in untarring This affected the special "cat" based extraction works when no upper level directory is present. Using that path depends on PIPE_BUF_BYTES, so test that integration via monkey-patching it to a small value.

(tmpdir, monkeypatch)

Source from the content-addressed store, hash-verified

104
105
106def test_creation_upper_dir(tmpdir, monkeypatch):
107 """Check for upper-directory creation in untarring
108
109 This affected the special "cat" based extraction works when no
110 upper level directory is present. Using that path depends on
111 PIPE_BUF_BYTES, so test that integration via monkey-patching it to
112 a small value.
113
114 """
115 from wal_e import pipebuf
116
117 # Set up a directory with a file inside.
118 adir = tmpdir.join('adir').ensure(dir=True)
119 some_file = adir.join('afile')
120 some_file.write('1234567890')
121
122 tar_path = str(tmpdir.join('foo.tar'))
123
124 # Add the file to a test tar, *but not the directory*.
125 tar = tarfile.open(name=tar_path, mode='w')
126 tar.add(str(some_file))
127 tar.close()
128
129 # Replace cat_extract with a version that does the same, but
130 # ensures that it is called by the test.
131 original_cat_extract = tar_partition.cat_extract
132
133 class CheckCatExtract(object):
134 def __init__(self):
135 self.called = False
136
137 def __call__(self, *args, **kwargs):
138 self.called = True
139 return original_cat_extract(*args, **kwargs)
140
141 check = CheckCatExtract()
142 monkeypatch.setattr(tar_partition, 'cat_extract', check)
143 monkeypatch.setattr(pipebuf, 'PIPE_BUF_BYTES', 1)
144
145 dest_dir = tmpdir.join('dest')
146 dest_dir.ensure(dir=True)
147 with open(tar_path, 'rb') as f:
148 tar_partition.TarPartition.tarfile_extract(f, str(dest_dir))
149
150 # Make sure the test exercised cat_extraction.
151 assert check.called

Callers

nothing calls this directly

Calls 7

CheckCatExtractClass · 0.85
writeMethod · 0.80
openMethod · 0.80
addMethod · 0.80
tarfile_extractMethod · 0.80
joinMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected