Skip to content

Commit

Permalink
Improve tests (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbruno25 authored Jul 19, 2024
1 parent bd01064 commit cb77162
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/can_explorer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def _add_row(self) -> None:
self._row_values.append(row)

def _sync_rows(self) -> None:
"""
Pair the current row_keys with the row_values.
Automatically hide's any rows not being used.
"""
while len(self._row_keys) > len(self._row_values):
self._add_row()

Expand Down
7 changes: 7 additions & 0 deletions tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ def test_controller_cannot_start_without_stopping(app, tag, controller):
assert controller.is_active()
with pytest.raises(RuntimeError):
controller.start()


def test_controller_must_be_inactive_to_apply_settings(app, tag, controller):
controller.start()
assert controller.is_active()
with pytest.raises(RuntimeError):
controller.settings_apply_button_callback()
30 changes: 17 additions & 13 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
from time import sleep

import dearpygui.dearpygui as dpg
import pyautogui
import pytest
from can_explorer.app import CanExplorer
Expand Down Expand Up @@ -80,23 +81,26 @@ def virtual_gui(request, process):
save_screenshot(request)


def test_gui_launch_basic(virtual_gui):
pytest.skip("Todo")
def test_gui_launch(app, controller, tag):
assert dpg.is_dearpygui_running()

# Check if the main window was created
assert dpg.does_item_exist(tag.header)
assert dpg.does_item_exist(tag.body)
assert dpg.does_item_exist(tag.footer)

def test_gui_must_be_inactive_to_apply_settings(app, tag, controller):
pytest.skip("Todo")
# app.run()
# Check if key UI elements exist
assert dpg.does_item_exist(tag.main_button)
assert dpg.does_item_exist(tag.clear_button)
assert dpg.does_item_exist(tag.plot_buffer_slider)
assert dpg.does_item_exist(tag.plot_height_slider)

# dpg.set_value(tag.settings_interface, "virtual")
# controller.settings_apply_button_callback()
# Check if the settings tab exists
assert dpg.does_item_exist(tag.settings_tab)

# controller.start_stop_button_callback()
# assert controller.is_active()

# dpg.set_value(tag.settings_interface, None)
# with pytest.raises(RuntimeError):
# controller.settings_apply_button_callback()
# Verify initial state
assert not controller.is_active()
assert dpg.get_item_label(tag.main_button) == "Start"


def test_gui_visualizes_traffic(virtual_gui):
Expand Down

0 comments on commit cb77162

Please sign in to comment.