File: test_jsondb.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 (26 lines) | stat: -rw-r--r-- 533 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
# fmt: off
from io import StringIO

from ase.io import read, write


def test_jsondb():
    """Read and write json from/to file descriptor."""

    s = """
    {"1":
         {"numbers": [1, 1],
          "positions": [[0.0, 0.0, 0.35],
                        [0.0, 0.0, -0.35]]}}
    """

    fd = StringIO(s)
    a = read(fd, format='json')
    assert a.get_chemical_formula() == 'H2'

    fd = StringIO()
    write(fd, a, format='json')

    fd.seek(0)
    a = read(fd, format='json')
    assert a.get_chemical_formula() == 'H2'