42 lines
2.0 KiB
Python
42 lines
2.0 KiB
Python
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from dashboard_history import HistoryStore
|
|
from deploy.import_dashboard_history import import_history
|
|
|
|
|
|
class DashboardHistoryTests(unittest.TestCase):
|
|
def test_import_preserves_samples_tokens_and_events(self):
|
|
with tempfile.TemporaryDirectory() as folder:
|
|
old=Path(folder)/'old.sqlite3'
|
|
store=HistoryStore(old)
|
|
snapshot=dict(timestamp=1720000000,gpus=[dict(index=0,gpu_percent=25,
|
|
memory_used_mib=4096,temperature_c=55,power_w=170)],
|
|
router=dict(current_profile='Medium',upstream=dict(model='model.gguf'),
|
|
llama_telemetry=dict(slots=[dict(id=0,context_used=512,n_ctx=4096,processing=True)],
|
|
metrics=dict(prompt_tokens_total=12,
|
|
prompt_tokens_cached_total=3,
|
|
tokens_predicted_total=6))),
|
|
llama_runtime=dict(pid=123,model_file='model.gguf'))
|
|
store.record(snapshot)
|
|
store.record(dict(snapshot,timestamp=1720000015,
|
|
router=dict(snapshot['router'],current_profile='Fast')))
|
|
target=Path(folder)/'deck.sqlite3'
|
|
counts=import_history(old,target)
|
|
self.assertEqual(counts['samples_raw'],2)
|
|
self.assertEqual(counts['slot_samples_raw'],2)
|
|
self.assertEqual(counts['model_events'],1)
|
|
imported=HistoryStore(target)
|
|
result=imported.query('all')
|
|
self.assertEqual(result['token_totals']['prompt_tokens'],12)
|
|
self.assertEqual(result['token_totals']['cached_tokens'],3)
|
|
self.assertEqual(result['token_totals']['output_tokens'],6)
|
|
self.assertEqual(len(result['model_events']),1)
|
|
with self.assertRaises(ValueError):import_history(old,target)
|
|
imported.close()
|
|
store.close()
|
|
|
|
|
|
if __name__=='__main__':unittest.main()
|