def test_error_in_interval():
    with pytest.raises(ValueError):
        update_nattune(
            files=[str(_get_input_file())],
            interval=[0., 0.],  # nothing here
            rename_suffix=RENAME_SUFFIX,
        )
def test_single_plane_update():
    update_nattune(
        files=[str(_get_input_file())],
        interval=[0.26, 0.33],
        rename_suffix=RENAME_SUFFIX,
        planes=["X"],
    )
    assert len(list(_get_input_dir().glob(f'*{RENAME_SUFFIX}*'))) == 1
    assert (_get_input_dir() / f'spec_test.sdds{RENAME_SUFFIX}.linx').exists()
def test_remove_not_found():
    update_nattune(
        files=[str(_get_input_file())],
        interval=[0., 0.],  # nothing here
        rename_suffix=RENAME_SUFFIX,
        not_found_action='remove')
    for plane in PLANES:
        new = tfs.read(
            str(_get_input_dir() /
                f'spec_test.sdds{RENAME_SUFFIX}.lin{plane.lower()}'))
        assert len(new.index) == 0
def test_remove_some_not_found():
    update_nattune(
        files=[str(_get_input_file())],
        interval=[0.2631, 0.265],  # some here
        rename_suffix=RENAME_SUFFIX,
        not_found_action='remove')

    newx = tfs.read(
        str(_get_input_dir() / f'spec_test.sdds{RENAME_SUFFIX}.linx'))
    assert len(newx.index) == 2  # specific to this test-set

    newy = tfs.read(
        str(_get_input_dir() / f'spec_test.sdds{RENAME_SUFFIX}.liny'))
    assert len(newy.index) == 3  # specific to this test-set
def test_all_planes_update():
    update_nattune(
        files=[str(_get_input_file())],
        interval=[0.26, 0.33],  # actual tunes are in that interval
        rename_suffix=RENAME_SUFFIX)
    assert len(list(_get_input_dir().glob(f'*{RENAME_SUFFIX}*'))) == 2
    for plane in PLANES:
        new = tfs.read(
            str(_get_input_dir() /
                f'spec_test.sdds{RENAME_SUFFIX}.lin{plane.lower()}'))
        assert np.allclose(new[f'{COL_NATTUNE}{plane}'],
                           new[f'{COL_TUNE}{plane}'],
                           atol=1e-7)
        assert np.allclose(new[f'{COL_NATAMP}{plane}'],
                           new[f'{COL_AMP}{plane}'],
                           atol=1e-5)
def test_keep_not_found():
    update_nattune(
        files=[str(_get_input_file())],
        interval=[0., 0.],  # nothing here
        rename_suffix=RENAME_SUFFIX,
        not_found_action='ignore')
    for plane in PLANES:
        old = tfs.read(
            str(_get_input_dir() / f'spec_test.sdds.lin{plane.lower()}'))
        new = tfs.read(
            str(_get_input_dir() /
                f'spec_test.sdds{RENAME_SUFFIX}.lin{plane.lower()}'))
        assert np.allclose(old[f'{COL_NATTUNE}{plane}'],
                           new[f'{COL_NATTUNE}{plane}'],
                           atol=1e-17)
        assert np.allclose(old[f'{COL_NATAMP}{plane}'],
                           new[f'{COL_NATAMP}{plane}'],
                           atol=1e-17)