File: test_jsondb.py

package info (click to toggle)
python-ase 3.22.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,344 kB
  • sloc: python: 126,379; xml: 946; makefile: 111; javascript: 47
file content (22 lines) | stat: -rw-r--r-- 528 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def test_jsondb():
    """Read and write json from/to file descriptor."""
    from io import StringIO
    from ase.io import read, write

    s = u"""
    {"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'