Skip to content

Commit

Permalink
Adapt to interface changes in statemachine package (#17)
Browse files Browse the repository at this point in the history
* Adapt to interface changes in statemachine package

* Try testing traffic light visu in gh actions

* Next try

* Next try

* Increase required coverage after visu test
  • Loading branch information
m-naumann authored Feb 2, 2024
1 parent b70a1b1 commit 5733399
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ jobs:
run: mypy src/behavior_generation_lecture_python/mdp

- name: test
run: pytest

- name: check coverage # (less coverage required here since vizard is not tested)
run: pytest --cov=src --cov-fail-under=70
run: |
export DISPLAY=:99
Xvfb :99 &
pytest
- name: check coverage
run: |
export DISPLAY=:99
Xvfb :99 &
pytest --cov=src --cov-fail-under=85
- name: copy notebooks to docs folder
run: cp -r notebooks/* docs/notebooks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class TrafficLightStateMachine(StateMachine):
veh_go = veh_red_yellow.to(veh_green)

def __init__(self, start_mainloop=True):
StateMachine.__init__(self)
self.visu = VisualizeTrafficLights()
super().__init__(self)
self.visu.register_button_event(self.button_press)
self.visu.vehicle_go()
if start_mainloop:
Expand All @@ -38,34 +38,34 @@ def on_enter_veh_yellow(self):
time.sleep(3)
self.visu.vehicle_prepare_to_stop()
time.sleep(3)
self.run("veh_stop")
self.send("veh_stop")

def on_enter_veh_red_ped_red_1(self):
self.visu.vehicle_stop()
time.sleep(2)
self.run("ped_go")
self.send("ped_go")

def on_enter_veh_red_ped_green(self):
self.visu.pedestrian_go()
time.sleep(5)
self.run("ped_stop")
self.send("ped_stop")

def on_enter_veh_red_ped_red_2(self):
self.visu.pedestrian_stop()
time.sleep(5)
self.run("veh_prepare_to_go")
self.send("veh_prepare_to_go")

def on_enter_veh_red_yellow(self):
self.visu.vehicle_prepare_to_go()
time.sleep(2)
self.run("veh_go")
self.send("veh_go")

def on_enter_veh_green(self):
self.visu.vehicle_go()

def button_press(self, event):
if self.is_veh_green:
self.run("veh_prepare_to_stop")
if self.state == "veh_green":
self.send("veh_prepare_to_stop")
else:
warnings.warn(
"The button only has effect if currently vehicles have green."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
)


@pytest.mark.skipif(not os.environ.get("DISPLAY"), reason="Display required")
def test_traffic_light_state_machine_with_visu():
tl = traffic_light_state_machine_with_visu.TrafficLightStateMachine(
start_mainloop=False
Expand Down

0 comments on commit 5733399

Please sign in to comment.