1+ #
2+ # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
3+ #
4+ # Licensed under the Apache License, Version 2.0 (the "License");
5+ # you may not use this file except in compliance with the License.
6+ # You may obtain a copy of the License at
7+ #
8+ # http://www.apache.org/licenses/LICENSE-2.0
9+ #
10+ # Unless required by applicable law or agreed to in writing, software
11+ # distributed under the License is distributed on an "AS IS" BASIS,
12+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ # See the License for the specific language governing permissions and
14+ # limitations under the License.
15+ #
16+ import uuid
17+ from common .misc_utils import get_uuid
18+
19+ class TestGetUuid :
20+ """Test cases for get_uuid function"""
21+
22+ def test_returns_string (self ):
23+ """Test that function returns a string"""
24+ result = get_uuid ()
25+ assert isinstance (result , str )
26+
27+ def test_hex_format (self ):
28+ """Test that returned string is in hex format"""
29+ result = get_uuid ()
30+ # UUID v1 hex should be 32 characters (without dashes)
31+ assert len (result ) == 32
32+ # Should only contain hexadecimal characters
33+ assert all (c in '0123456789abcdef' for c in result )
34+
35+ def test_no_dashes_in_result (self ):
36+ """Test that result contains no dashes"""
37+ result = get_uuid ()
38+ assert '-' not in result
39+
40+ def test_unique_results (self ):
41+ """Test that multiple calls return different UUIDs"""
42+ results = [get_uuid () for _ in range (10 )]
43+
44+ # All results should be unique
45+ assert len (results ) == len (set (results ))
46+
47+ # All should be valid hex strings of correct length
48+ for result in results :
49+ assert len (result ) == 32
50+ assert all (c in '0123456789abcdef' for c in result )
51+
52+ def test_valid_uuid_structure (self ):
53+ """Test that the hex string can be converted back to UUID"""
54+ result = get_uuid ()
55+
56+ # Should be able to create UUID from the hex string
57+ reconstructed_uuid = uuid .UUID (hex = result )
58+ assert isinstance (reconstructed_uuid , uuid .UUID )
59+
60+ # The hex representation should match the original
61+ assert reconstructed_uuid .hex == result
62+
63+ def test_uuid1_specific_characteristics (self ):
64+ """Test that UUID v1 characteristics are present"""
65+ result = get_uuid ()
66+ uuid_obj = uuid .UUID (hex = result )
67+
68+ # UUID v1 should have version 1
69+ assert uuid_obj .version == 1
70+
71+ # Variant should be RFC 4122
72+ assert uuid_obj .variant == 'specified in RFC 4122'
73+
74+ def test_result_length_consistency (self ):
75+ """Test that all generated UUIDs have consistent length"""
76+ for _ in range (100 ):
77+ result = get_uuid ()
78+ assert len (result ) == 32
79+
80+ def test_hex_characters_only (self ):
81+ """Test that only valid hex characters are used"""
82+ for _ in range (100 ):
83+ result = get_uuid ()
84+ # Should only contain lowercase hex characters (UUID hex is lowercase)
85+ assert result .islower ()
86+ assert all (c in '0123456789abcdef' for c in result )
0 commit comments