import pytest
from hypothesis import given, strategies as st
from robobench.core.initialization import ModelInitializationBenchmark, InitializationMetrics
from unittest.mock import patch, MagicMock

def test_model_name_parsing():
    benchmark = ModelInitializationBenchmark("model:quant")
    assert benchmark.model_id == "model"
    assert benchmark.quantization == "quant"

def test_invalid_model_name():
    with pytest.raises(ValueError):
        ModelInitializationBenchmark("invalid_model_name")

@pytest.mark.parametrize("model_name,expected_id,expected_quant", [
    ("llama3.2:3b-gguf-q2-k", "llama3.2", "3b-gguf-q2-k"),
    ("phi2:3b-gguf-q4", "phi2", "3b-gguf-q4"),
])
def test_model_name_variants(model_name, expected_id, expected_quant):
    benchmark = ModelInitializationBenchmark(model_name)
    assert benchmark.model_id == expected_id
    assert benchmark.quantization == expected_quant

@patch('subprocess.run')
def test_cold_start(mock_run, mock_memory_snapshot):
    mock_run.return_value = MagicMock(
        stdout='{"status": "success"}',
        returncode=0
    )

    benchmark = ModelInitializationBenchmark("model:quant")
    result, duration = benchmark._cold_start()

    assert result["status"] == "success"
    assert duration > 0
