File: test_formats.py

package info (click to toggle)
python-ase 3.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (31 lines) | stat: -rw-r--r-- 681 bytes parent folder | download
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)