/ proof-of-concept / cymsim
Sign in
proof-of-concept / cymsim
cymsim / tests / test_config.py
43 lines · 1.5 KBCodeBlameHistory
71e94accymsim: nonlinear FEM cymbal simulation packageJeremy Magland 1import pytest
3from cymsim.config import (Hit, MalletExciter, SimulationConfig, StickExciter, default_config)
6def test_yaml_round_trip(tmp_path):
7 cfg = default_config("stick")
8 cfg.hits.append(Hit(time=0.5, r=0.1, phi=1.0, velocity=3.0, exciter=MalletExciter(mass=0.2)))
9 path = tmp_path / "c.yaml"
10 cfg.to_yaml(path)
11 back = SimulationConfig.from_yaml(path)
12 assert back == cfg
13 assert isinstance(back.hits[0].exciter, StickExciter)
14 assert isinstance(back.hits[1].exciter, MalletExciter)
15 assert back.imperfections.rim_warp_modes == (2, 3, 4, 5)
18def test_partial_dict_uses_defaults():
19 cfg = SimulationConfig.from_dict({"hits": [{"time": 0.1, "exciter": {"kind": "stick"}}],
20 "numerics": {"duration": 0.5}})
21 assert cfg.hits[0].exciter == StickExciter()
22 assert cfg.numerics.duration == 0.5 and cfg.material.E == 1.1e11
25def test_errors():
26 with pytest.raises(ValueError):
27 SimulationConfig.from_dict({"material": {"youngs": 1.0}})
28 with pytest.raises(ValueError):
29 SimulationConfig.from_dict({"hits": [{"exciter": {"kind": "hammer"}}]})
30 cfg = default_config()
31 cfg.hits[0].r = 0.23
32 with pytest.raises(ValueError):
33 cfg.validate()
34 cfg = default_config()
35 cfg.hits = []
36 with pytest.raises(ValueError):
37 cfg.validate()
40def test_examples_load():
41 import glob
42 for path in glob.glob("examples/*.yaml"):
43 SimulationConfig.from_yaml(path).validate()
↑↓ move↵openescclose