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
|
import pytest
from ase.utils import xwopen
pytestmark = pytest.mark.usefixtures('testdir')
poem = 'Wer reitet so spät durch Nacht und Wind\n'.encode('utf-8')
filename = 'poem.txt'
def test_xwopen():
with xwopen(filename) as fd:
fd.write(poem)
assert fd.closed
with open(filename, 'rb') as fd:
assert fd.read() == poem
def test_xwopen_locked():
with xwopen(filename) as fd:
assert fd is not None
with xwopen(filename) as fd2:
assert fd2 is None
def test_xwopen_fail(tmp_path):
with pytest.raises(OSError):
with xwopen(tmp_path / 'does_not_exist/file'):
pass
|