forked from wal-e/wal-e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_files.py
51 lines (34 loc) · 1.09 KB
/
test_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import errno
import os
import pytest
from wal_e import files
def test_no_error(tmpdir):
p = unicode(tmpdir.join('somefile'))
with files.DeleteOnError(p) as doe:
doe.f.write('hello')
with open(p) as f:
assert f.read() == 'hello'
def test_clear_on_error(tmpdir):
p = unicode(tmpdir.join('somefile'))
boom = StandardError('Boom')
with pytest.raises(StandardError) as e:
with files.DeleteOnError(p) as doe:
doe.f.write('hello')
raise boom
assert e.value == boom
with pytest.raises(IOError) as e:
open(p)
assert e.value.errno == errno.ENOENT
def test_no_error_if_already_deleted(tmpdir):
p = unicode(tmpdir.join('somefile'))
with files.DeleteOnError(p) as doe:
doe.f.write('hello')
os.unlink(p)
def test_explicit_deletion_without_exception(tmpdir):
p = unicode(tmpdir.join('somefile'))
with files.DeleteOnError(p) as doe:
doe.f.write('hello')
doe.remove_regardless = True
with pytest.raises(IOError) as e:
open(p)
assert e.value.errno == errno.ENOENT