| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | import hashlib |
| 4 | import pickle |
| 5 | |
| 6 | import pytest |
| 7 | |
| 8 | from vllm.utils.hashing import sha256 |
| 9 | |
| 10 | |
| 11 | @pytest.mark.parametrize("input", [(), ("abc",), (None,), (None, bool, [1, 2, 3])]) |
| 12 | def test_sha256(input: tuple): |
| 13 | digest = sha256(input) |
| 14 | assert digest is not None |
| 15 | assert isinstance(digest, bytes) |
| 16 | assert digest != b"" |
| 17 | |
| 18 | input_bytes = pickle.dumps(input, protocol=pickle.HIGHEST_PROTOCOL) |
| 19 | assert digest == hashlib.sha256(input_bytes).digest() |
| 20 | |
| 21 | # hashing again, returns the same value |
| 22 | assert digest == sha256(input) |
| 23 | |
| 24 | # hashing different input, returns different value |
| 25 | assert digest != sha256(input + (1,)) |