Exemplo n.º 1
0
    def generate_hash(self, hashmethod="md5"):
        """Return a unique hash ID for current instance.

        See :meth:`~xtgeo.common.sys.generic_hash()` for documentation.

        .. versionadded:: 2.14
        """
        required = (
            "ncol",
            "nrow",
            "nlay",
            "xori",
            "yori",
            "zori",
            "xinc",
            "yinc",
            "zinc",
            "yflip",
            "zflip",
            "rotation",
            "values",
            "ilines",
            "xlines",
            "traceidcodes",
        )

        gid = ""
        for req in required:
            gid += f"{getattr(self, '_' + req)}"

        return xtgeosys.generic_hash(gid, hashmethod=hashmethod)
Exemplo n.º 2
0
def test_generic_hash():
    """Testing generic hashlib function."""
    ahash = xsys.generic_hash("ABCDEF")
    assert ahash == "8827a41122a5028b9808c7bf84b9fcf6"

    ahash = xsys.generic_hash("ABCDEF", hashmethod="sha256")
    assert ahash == "e9c0f8b575cbfcb42ab3b78ecc87efa3b011d9a5d10b09fa4e96f240bf6a82f5"

    ahash = xsys.generic_hash("ABCDEF", hashmethod="blake2b")
    assert ahash[0:12] == "0bb3eb1511cb"

    with pytest.raises(KeyError):
        ahash = xsys.generic_hash("ABCDEF", hashmethod="invalid")

    # pass a hashlib function
    ahash = xsys.generic_hash("ABCDEF", hashmethod=hashlib.sha224)
    assert ahash == "fd6639af1cc457b72148d78e90df45df4d344ca3b66fa44598148ce4"