11import time
2+ from datetime import datetime
23from unittest .mock import MagicMock , patch
34
45import pytest
56
67from trackio import Run , init
7- from trackio .utils import _cached_whoami
8+ from trackio .sqlite_storage import SQLiteStorage
89
910
1011class DummyClient :
@@ -39,6 +40,7 @@ def test_init_resume_modes(temp_dir):
3940 assert run .name == "new-run"
4041
4142 run .log ({"x" : 1 })
43+ SQLiteStorage .bulk_log ("test-project" , "new-run" , [{"x" : 1 }])
4244 run .finish ()
4345
4446 run = init (
@@ -84,10 +86,10 @@ def test_init_resume_modes(temp_dir):
8486 assert run .name == "nonexistent-run"
8587
8688
87- @patch ("huggingface_hub.whoami " )
89+ @patch ("trackio.utils._cached_whoami " )
8890@patch ("time.time" )
89- def test_run_name_generation_with_space_id (mock_time , mock_whoami , temp_dir ):
90- mock_whoami .return_value = {"name" : "testuser" }
91+ def test_run_name_generation_with_space_id (mock_time , mock_cached_whoami , temp_dir ):
92+ mock_cached_whoami .return_value = {"name" : "testuser" }
9193 mock_time .return_value = 1234567890
9294
9395 client = DummyClient ()
@@ -100,8 +102,6 @@ def test_run_name_generation_with_space_id(mock_time, mock_whoami, temp_dir):
100102 )
101103 assert run .name == "testuser-1234567890"
102104
103- _cached_whoami .cache_clear ()
104-
105105
106106def test_reserved_config_keys_rejected (temp_dir ):
107107 with pytest .raises (ValueError , match = "Config key '_test' is reserved" ):
@@ -113,9 +113,9 @@ def test_reserved_config_keys_rejected(temp_dir):
113113 )
114114
115115
116- @patch ("huggingface_hub.whoami " )
117- def test_automatic_username_and_timestamp_added (mock_whoami , temp_dir ):
118- mock_whoami .return_value = {"name" : "testuser" }
116+ @patch ("trackio.utils._cached_whoami " )
117+ def test_automatic_username_and_timestamp_added (mock_cached_whoami , temp_dir ):
118+ mock_cached_whoami .return_value = {"name" : "testuser" }
119119
120120 run = Run (
121121 url = "http://test" ,
@@ -128,13 +128,9 @@ def test_automatic_username_and_timestamp_added(mock_whoami, temp_dir):
128128 assert "_Created" in run .config
129129 assert run .config ["learning_rate" ] == 0.01
130130
131- from datetime import datetime
132-
133131 created_time = datetime .fromisoformat (run .config ["_Created" ])
134132 assert created_time .tzinfo is not None
135133
136- _cached_whoami .cache_clear ()
137-
138134
139135def test_run_group_added (temp_dir ):
140136 run = Run (
0 commit comments