58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
from datetime import UTC, datetime
|
|
|
|
from lmpm.data.store import add_experiment, add_material, init_db, list_experiments
|
|
from lmpm.domain.experiment import ExperimentRecord, ProcessingParams, QualityMetrics
|
|
from lmpm.domain.material import MaterialProperty
|
|
|
|
|
|
def material_property():
|
|
return MaterialProperty(
|
|
material_id="acrylic-001",
|
|
name="Clear Acrylic",
|
|
category="polymer",
|
|
reflectivity=0.08,
|
|
absorptivity=0.92,
|
|
melting_point_c=160.0,
|
|
thermal_conductivity_w_m_k=0.19,
|
|
density_g_cm3=1.18,
|
|
roughness_um=1.2,
|
|
)
|
|
|
|
|
|
def prepare_database(tmp_path):
|
|
database_path = tmp_path / "lemdb.db"
|
|
material = material_property()
|
|
init_db(database_path)
|
|
add_material(database_path, material)
|
|
return database_path, material
|
|
|
|
|
|
def test_init_db_creates_readable_tables(tmp_path):
|
|
database_path, _ = prepare_database(tmp_path)
|
|
|
|
assert database_path.exists()
|
|
|
|
|
|
def test_experiment_round_trip_through_sqlite(tmp_path):
|
|
database_path, _ = prepare_database(tmp_path)
|
|
experiment = ExperimentRecord(
|
|
experiment_id=None,
|
|
material_id="acrylic-001",
|
|
params=ProcessingParams(
|
|
power_percent=45,
|
|
scan_speed_mm_s=80,
|
|
pulse_frequency_hz=20,
|
|
),
|
|
metrics=QualityMetrics(kerf_width_mm=0.18),
|
|
recorded_at=datetime.now(UTC),
|
|
)
|
|
|
|
experiment_id = add_experiment(database_path, experiment)
|
|
stored = list_experiments(database_path)
|
|
|
|
assert experiment_id == 1
|
|
assert len(stored) == 1
|
|
assert stored[0].material_id == "acrylic-001"
|
|
assert stored[0].params == experiment.params
|
|
assert stored[0].metrics == experiment.metrics
|