import json import tantri.cli.input_files.read_dipoles as read_dipoles import pytest def test_parse_one_dipole_failures(): dict = { "s": [1.5, 0, 1], # missing p "w": 1.5, } with pytest.raises(KeyError, match=r".*p.*"): read_dipoles.row_to_dipole(dict) dict = { # missing s "p": [150, 15.0, -21], "w": 1.5, } with pytest.raises(KeyError, match=r".*s.*"): read_dipoles.row_to_dipole(dict) dict = { "s": [1.5, 0, 1], "p": [150, 15.0, -21], # missing w } with pytest.raises(KeyError, match=r".*w.*"): read_dipoles.row_to_dipole(dict) def test_parse_one_dipole_happy_path(snapshot): dict = { "s": [1.5, 0, 1], "p": [150, 15.0, -21], "w": 1513, } transformed = read_dipoles.row_to_dipole(dict) assert transformed == snapshot def test_dot_r_wrong_length(): dict = { "s": [1.5, 0, 1, 5], "p": [150, 15.0, -21], "w": 1513, } with pytest.raises(ValueError, match=r".*does not have length 3.*"): read_dipoles.row_to_dipole(dict) dict = { "s": [1.5, 0, 1], "p": [150, 15.0, -21, 235, 23], "w": 1513, } with pytest.raises(ValueError, match=r".*does not have length 3.*"): read_dipoles.row_to_dipole(dict) def test_dipoles_from_json_string(snapshot): read_dipoles_json = """[ { "s": [-1.5, 0.0, 3.5], "p": [0, 0, 1000], "w": 0.11 }, { "s": [-66, 323, 431], "p": [1000, 5050, 1234], "w": 220 } ] """ parsed = json.loads(read_dipoles_json) transformed = read_dipoles.rows_to_dipoles(parsed) assert transformed == snapshot