import json import tantri.cli.input_files.read_dots as dots import pytest def test_parse_one_dot_failures(): dict = { "r": [1.5, 0, 1] # missing label } with pytest.raises(KeyError, match=r".*label.*"): dots.row_to_dot(dict) dict = { # missing r "label": "label" } with pytest.raises(KeyError, match=r".*r.*"): dots.row_to_dot(dict) def test_parse_one_dot(snapshot): dict = { "r": [1.5, 0, 1], "label": "dot1", } transformed = dots.row_to_dot(dict) assert transformed == snapshot def test_dot_r_wrong_length(): dict = { "r": [1.5, 0], "label": "dot1", } with pytest.raises(ValueError, match=r".*does not have length 3.*"): dots.row_to_dot(dict) def test_from_json_string(snapshot): dots_json = """[ { "r": [0, 1.5, 2], "label": "dot1" }, { "r": [-5, 3, -1.0], "label": "dot2" } ] """ parsed = json.loads(dots_json) transformed = dots.rows_to_dots(parsed) assert transformed == snapshot