Exemplo n.º 1
0
    def test_unsupported_suffix(self, tmpdir):
        """File with unsupported extension."""

        # create a file with unsupported extensions
        ext = "FAKE"
        full_path = pathlib.Path(str(tmpdir)) / "test_file.{}".format(ext)
        full_path.touch()

        with pytest.raises(ValueError):
            DisplacementField.from_file(full_path)
Exemplo n.º 2
0
    def test_npy(self, tmpdir, array, as_str):
        """Possible to read npy arrays."""
        full_path = pathlib.Path(str(tmpdir)) / "file_temp.npy"

        if as_str:
            full_path = str(full_path)

        np.save(full_path, array)

        if array.ndim == 3 and array.shape[2] == 2:
            df = DisplacementField.from_file(full_path)
            assert isinstance(df, DisplacementField)
            assert np.allclose(array[:, :, 0], df.delta_x)
            assert np.allclose(array[:, :, 1], df.delta_y)

        else:
            with pytest.raises(ValueError):
                DisplacementField.from_file(full_path)
Exemplo n.º 3
0
    def test_saveload(self, tmpdir, as_str):
        """Test that saving and loading loads the same dvf."""

        delta_x = np.random.random((2, 3))
        delta_y = np.random.random((2, 3))

        df_orig = DisplacementField(delta_x, delta_y)

        file_path = pathlib.Path(str(tmpdir)) / "test.npy"

        if as_str:
            file_path = str(file_path)

        df_orig.save(file_path)

        df_new = DisplacementField.from_file(file_path)

        assert df_orig == df_new
Exemplo n.º 4
0
    def test_wrong_input(self):
        """Input is wrong."""

        with pytest.raises(TypeError):
            DisplacementField.from_file(123213)