Skip to content

Commit

Permalink
setup to allow running tests against physical hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrudd2 committed May 22, 2024
1 parent e6f2a90 commit 1b245a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
33 changes: 22 additions & 11 deletions clickplc/tests/test_driver.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
"""Test the driver correctly parses a tags file and responds with correct data."""
import asyncio
from unittest import mock

import pytest

from clickplc import command_line
from clickplc.mock import ClickPLC

ADDRESS = 'fakeip'
# from clickplc.driver import ClickPLC
# ADDRESS = '172.16.0.168'

@pytest.fixture
def plc_driver():
"""Confirm the driver correctly initializes without a tags file."""
return ClickPLC('fake ip')

@pytest.fixture(scope="session")
def event_loop():
"""Override the default event_loop fixture (which is function-scoped) to be session-scoped."""
loop = asyncio.new_event_loop()
yield loop
loop.close()


@pytest.fixture(scope='session')
async def plc_driver():
"""Confirm the driver correctly initializes without a tags file."""
async with ClickPLC(ADDRESS) as c:
yield c

@pytest.fixture
def expected_tags():
Expand Down Expand Up @@ -43,7 +54,7 @@ def expected_tags():
@mock.patch('clickplc.ClickPLC', ClickPLC)
def test_driver_cli(capsys):
"""Confirm the commandline interface works without a tags file."""
command_line(['fakeip'])
command_line([ADDRESS])
captured = capsys.readouterr()
assert 'x816' in captured.out
assert 'c100' in captured.out
Expand All @@ -53,26 +64,26 @@ def test_driver_cli(capsys):
@mock.patch('clickplc.ClickPLC', ClickPLC)
def test_driver_cli_tags(capsys):
"""Confirm the commandline interface works with a tags file."""
command_line(['fakeip', 'clickplc/tests/plc_tags.csv'])
command_line([ADDRESS, 'clickplc/tests/plc_tags.csv'])
captured = capsys.readouterr()
assert 'P_101' in captured.out
assert 'VAHH_101_OK' in captured.out
assert 'TI_101' in captured.out
with pytest.raises(SystemExit):
command_line(['fakeip', 'tags', 'bogus'])
command_line([ADDRESS, 'tags', 'bogus'])



def test_unsupported_tags():
@pytest.mark.asyncio
async def test_unsupported_tags():
"""Confirm the driver detects an improper tags file."""
with pytest.raises(TypeError, match='unsupported data type'):
ClickPLC('fake ip', 'clickplc/tests/bad_tags.csv')
ClickPLC(ADDRESS, 'clickplc/tests/bad_tags.csv')


@pytest.mark.asyncio
async def test_tagged_driver(expected_tags):
"""Test a roundtrip with the driver using a tags file."""
async with ClickPLC('fakeip', 'clickplc/tests/plc_tags.csv') as tagged_driver:
async with ClickPLC(ADDRESS, 'clickplc/tests/plc_tags.csv') as tagged_driver:
await tagged_driver.set('VAH_101_OK', True)
state = await tagged_driver.get()
assert state.get('VAH_101_OK')
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ ignore_missing_imports = True

[tool:pytest]
addopts = --cov=clickplc
asyncio_mode = auto

0 comments on commit 1b245a7

Please sign in to comment.