|
1 | 1 | # Copyright © 2012-2024 Forschungszentrum Jülich GmbH
|
2 | 2 | # SPDX-License-Identifier: LGPL-3.0-or-later
|
| 3 | + |
3 | 4 | import jupedsim as jps
|
4 | 5 | import pytest
|
5 | 6 |
|
6 | 7 |
|
7 | 8 | @pytest.fixture
|
8 |
| -def simulation_with_social_force_model(): |
9 |
| - return jps.Simulation( |
10 |
| - model=jps.SocialForceModel(), |
11 |
| - geometry=[(0, 0), (10, 0), (10, 10), (0, 10)], |
12 |
| - ) |
| 9 | +def create_simulation(): |
| 10 | + """Creates a generic simulation fixture for different models.""" |
| 11 | + |
| 12 | + def _create(model): |
| 13 | + return jps.Simulation( |
| 14 | + model=model, |
| 15 | + geometry=[(0, 0), (10, 0), (10, 10), (0, 10)], |
| 16 | + ) |
13 | 17 |
|
| 18 | + return _create |
14 | 19 |
|
15 |
| -def test_desired_speed_deprecated(simulation_with_social_force_model): |
16 |
| - sim = simulation_with_social_force_model |
| 20 | + |
| 21 | +@pytest.mark.parametrize( |
| 22 | + "model_class, agent_class, deprecated_attr", |
| 23 | + [ |
| 24 | + ( |
| 25 | + jps.SocialForceModel, |
| 26 | + jps.SocialForceModelAgentParameters, |
| 27 | + "desiredSpeed", |
| 28 | + ), |
| 29 | + ( |
| 30 | + jps.CollisionFreeSpeedModel, |
| 31 | + jps.CollisionFreeSpeedModelAgentParameters, |
| 32 | + "v0", |
| 33 | + ), |
| 34 | + ( |
| 35 | + jps.GeneralizedCentrifugalForceModel, |
| 36 | + jps.GeneralizedCentrifugalForceModelAgentParameters, |
| 37 | + "v0", |
| 38 | + ), |
| 39 | + ], |
| 40 | +) |
| 41 | +def test_desired_speed_deprecated( |
| 42 | + create_simulation, model_class, agent_class, deprecated_attr |
| 43 | +): |
| 44 | + """ |
| 45 | + Test that deprecated 'desiredSpeed' (or 'v0' in some models) raises warnings and is mapped to 'desired_speed'. |
| 46 | + """ |
| 47 | + sim = create_simulation(model_class()) |
17 | 48 | wp = sim.add_waypoint_stage((10, 1), 0.5)
|
18 | 49 | journey_id = sim.add_journey(jps.JourneyDescription([wp]))
|
19 | 50 |
|
20 |
| - agent = jps.SocialForceModelAgentParameters( |
| 51 | + agent = agent_class( |
21 | 52 | journey_id=journey_id,
|
22 | 53 | stage_id=wp,
|
23 | 54 | position=(1, 1),
|
24 | 55 | )
|
25 | 56 | agent_id = sim.add_agent(agent)
|
26 |
| - # Check if the deprecation warning is raised |
| 57 | + |
27 | 58 | with pytest.warns(
|
28 | 59 | DeprecationWarning, match="deprecated, use 'desired_speed' instead"
|
29 | 60 | ):
|
30 |
| - sim.agent(agent_id).model.desiredSpeed = 1.5 |
31 |
| - assert sim.agent(agent_id).model.desiredSpeed == 1.5 |
| 61 | + setattr(sim.agent(agent_id).model, deprecated_attr, 1.5) |
| 62 | + assert getattr(sim.agent(agent_id).model, deprecated_attr) == 1.5 |
32 | 63 |
|
33 |
| - # Verify the new snake_case property reflects the same value |
34 | 64 | assert sim.agent(agent_id).model.desired_speed == 1.5
|
0 commit comments