-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
147 additions
and
61 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: ['main', 'dev'] | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v3 | ||
- uses: pre-commit/[email protected] | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ['3.8', '3.9', '3.10', '3.11'] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install poetry | ||
poetry install | ||
- name: Setup container display | ||
# https://arbitrary-but-fixed.net/2022/01/21/headless-gui-github-actions.html | ||
run: Xvfb :1 -screen 0 1600x1200x24 & | ||
- name: Test with pytest | ||
run: poetry run pytest -v | ||
env: | ||
DISPLAY: :1 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,52 @@ | ||
from unittest.mock import Mock, patch | ||
|
||
import pytest | ||
from can_explorer import app, can_bus, plotting | ||
|
||
|
||
@pytest.fixture | ||
def mock_buffer(): | ||
with patch("can_explorer.can_bus.PayloadBuffer", autospec=True) as mock: | ||
yield mock | ||
|
||
|
||
@pytest.fixture | ||
def mock_listener(): | ||
with patch("can_explorer.can_bus._Listener", autospec=True) as mock: | ||
yield mock | ||
|
||
|
||
@pytest.fixture | ||
def mock_recorder(): | ||
... | ||
def mock_notifier(): | ||
with patch("can_explorer.can_bus.Notifier", autospec=True) as mock: | ||
yield mock | ||
|
||
|
||
@pytest.fixture | ||
def mock_plot_manager(): | ||
... | ||
def fake_recorder(mock_listener, mock_notifier): | ||
recorder = can_bus.Recorder() | ||
|
||
with patch("can_explorer.can_bus.Recorder") as mock: | ||
mock.return_value = recorder | ||
|
||
yield recorder | ||
|
||
|
||
@pytest.fixture | ||
def fake_manager(): | ||
with patch("can_explorer.plotting.Row"): | ||
manager = plotting.PlotManager() | ||
|
||
with patch("can_explorer.plotting.PlotManager") as mock: | ||
mock.return_value = manager | ||
|
||
yield manager | ||
|
||
|
||
@pytest.fixture | ||
def mock_app(): | ||
... | ||
def fake_app(fake_manager, fake_recorder): | ||
main_app = app.MainApp() | ||
main_app.plot_manager = fake_manager | ||
main_app.can_recorder = fake_recorder | ||
main_app.set_bus(Mock()) | ||
yield main_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,42 @@ | ||
# for 3.8, 3.9, etc. | ||
def test_app_launches_without_errors(): | ||
... | ||
from random import sample | ||
from threading import Thread | ||
from time import sleep | ||
|
||
import dearpygui.dearpygui as dpg | ||
from can_explorer import app | ||
|
||
def test_app_populates_data_in_ascending_order(): | ||
... | ||
DELAY = 0.1 | ||
|
||
|
||
def test_app_launch_basic(): | ||
Thread(target=app.main).start() | ||
sleep(DELAY) | ||
assert dpg.is_dearpygui_running() | ||
dpg.stop_dearpygui() | ||
|
||
|
||
def test_set_app_state_starts_worker(fake_app): | ||
fake_app.set_state(True) | ||
assert fake_app._worker.is_alive() | ||
|
||
|
||
def test_set_app_state_stops_worker(fake_app): | ||
fake_app.set_state(True) | ||
assert fake_app._worker.is_alive() | ||
fake_app.set_state(False) | ||
assert not fake_app._worker.is_alive() | ||
|
||
|
||
def test_app_populates_data_in_ascending_order(fake_app, fake_manager, fake_recorder): | ||
data = sample(range(250), 25) | ||
|
||
fake_app.start() | ||
|
||
for i in data: | ||
fake_recorder[i] = [0] | ||
|
||
sleep(DELAY) | ||
sorted_data = list(sorted(data)) | ||
sorted_keys = list(fake_manager.row.keys()) | ||
|
||
assert sorted_data == sorted_keys |