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
|
# fmt: off
from pathlib import Path
import pytest
from ase.io import read
from ase.io.formats import UnknownFileTypeError
def mkfile(path, text):
path = Path(path)
path.write_text(text)
return path
def test_no_such_file():
fname = 'nosuchfile.traj'
with pytest.raises(FileNotFoundError, match=fname):
read(fname)
def test_empty_file():
path = mkfile('empty.xyz', '')
with pytest.raises(UnknownFileTypeError, match='Empty file'):
read(path)
def test_bad_format():
path = mkfile('strangefile._no_such_format', 'strange file contents')
with pytest.raises(UnknownFileTypeError, match='_no_such_format'):
read(path)
|