def test_error_if_parameter_missing_from_cif(self, missing_data_item):
        data_items_with_missing_item = dict(zip("abcdef", range(6)))
        data_items_with_missing_item.pop(missing_data_item)

        with pytest.raises(ValueError) as exception_info:
            get_cif_data(data_items_with_missing_item, missing_data_item)
        assert str(exception_info.value) == \
            "Parameter: '{}' missing from input CIF".format(missing_data_item)
    def test_get_textual_cif_data_by_name(self):
        test_data_items = {"symmetry_space_group_name_H-M": "R -3 c H",
                           "chemical_name_mineral ": "Calcite",
                           "chemical_formula_sum": "C1 Ca1 O3"}

        data_names, data_values = zip(*test_data_items.items())
        data = get_cif_data(test_data_items, *data_names)
        assert data == list(data_values)
    def test_getting_single_data_value(self):
        test_data_items = {"symmetry_space_group_name_H-M": "R -3 c H",
                           "chemical_name_mineral ": "Calcite",
                           "chemical_formula_sum": "C1 Ca1 O3"}

        data_name = "chemical_formula_sum"
        [data] = get_cif_data(test_data_items, data_name)
        assert data == "C1 Ca1 O3"
    def test_get_textual_loop_cif_data_by_name(self):
        test_data_items = {"cell_length_a": "4.9900(2)",
                           "atom_site_label": ["Ca1", "C1", "O1"],
                           "atom_type_symbol": ["Ca2+", "C4+", "O2-"]}

        labels, symbols = get_cif_data(test_data_items,
                                       "atom_site_label",
                                       "atom_type_symbol")
        assert labels == ["Ca1", "C1", "O1"]
        assert symbols == ["Ca2+", "C4+", "O2-"]
    def test_get_numerical_loop_cif_data_by_name(self, mocker):
        test_data_items = {"cell_length_a": "4.9900(2)",
                           "atom_site_fract_x": ["0", "0", "0.25706(33)"],
                           "atom_site_fract_y": ["0", "0.25", "0.25"]}
        cif_num_mock = mocker.patch("diffraction.cif.helpers.cif_numerical",
                                    side_effect=lambda data_name, data_value: data_value)

        expected_calls = [(("atom_site_fract_x", test_data_items["atom_site_fract_x"]),),
                          (("atom_site_fract_y", test_data_items["atom_site_fract_y"]),)]
        x, y = get_cif_data(test_data_items, "atom_site_fract_x", "atom_site_fract_y")
        assert cif_num_mock.call_args_list == expected_calls
        assert x == test_data_items["atom_site_fract_x"]
        assert y == test_data_items["atom_site_fract_y"]
    def test_get_numerical_cif_data_by_name(self, mocker):
        test_data_items = {"cell_length_a": "4.9900(2)",
                           "cell_length_b": "4.9900(2)",
                           "cell_angle_gamma": "120.",
                           "atom_site_fract_x": "-2.34"}
        cif_num_mock = mocker.patch("diffraction.cif.helpers.cif_numerical",
                                    side_effect=lambda data_name, data_value: data_value)

        data_names, data_values = zip(*test_data_items.items())

        data = get_cif_data(test_data_items, *data_names)
        expected_calls = [((data_name, data_value),)
                          for data_name, data_value in zip(data_names, data_values)]
        assert cif_num_mock.call_args_list == expected_calls
        assert data == list(data_values)