diff --git a/localite/flow/ext.py b/localite/flow/ext.py index 5db5939..d200653 100644 --- a/localite/flow/ext.py +++ b/localite/flow/ext.py @@ -54,7 +54,7 @@ def __init__(self, queue: Queue, host: str = "127.0.0.1", port: int = 6667): self.is_running = threading.Event() def await_running(self): - while not self.is_running.is_set(): + while not self.is_running.is_set(): # pragma no cover pass def run(self): diff --git a/localite/flow/loc.py b/localite/flow/loc.py index 1d00501..f633491 100644 --- a/localite/flow/loc.py +++ b/localite/flow/loc.py @@ -182,7 +182,7 @@ def reset(self): def update(self, payload: Payload): "update the expectation" - if payload.fmt != "loc": # pragma no cover + if payload.fmt != "loc": raise ValueError("Must be a valid loc-command") self.fmt = payload.fmt self.msg = payload.msg @@ -264,11 +264,11 @@ def run(self): response = listen_and_queue( client, ignore=self.ignore, queue=self.outbox ) - # sometimes, the get: "target_index" is ignored. + # sometimes, the get: "target_index" is ignored. # in these cases, resend if "target_index" in lastmessage.msg: - flevel = lastmessage.expects(response) - if flevel >= 2: + flevel = lastmessage.expects(response) + if flevel >= 2: print("LOC:RESEND", lastmessage.msg) client.send(lastmessage.msg) lastmessage.counter = 0 diff --git a/makefile b/makefile index 5ff3320..21c0697 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -SHELL := /bin/bash #to be able to execute `source` +#SHELL := /bin/bash #to be able to execute `source` .PHONY: build build: clean @@ -9,15 +9,16 @@ clean: rm -rf dist */*.egg-info *.egg-info build rm -rf .test +.ONESHELL: .PHONY: test test: build - twine check dist/* - # twine upload --repository-url https://test.pypi.org/legacy/ dist/* --verbose - virtualenv .test - source .test/bin/activate - pip install git+https://github.com/labstreaminglayer/liblsl-Python.git - pip install dist/*.whl - pytest + bash test/install + # twine check dist/* + # virtualenv .test + # source .test/bin/activate + # pip install git+https://github.com/labstreaminglayer/liblsl-Python.git + # pip install dist/*.whl + # pytest .PHONY: upload upload: build diff --git a/pytest.ini b/pytest.ini index 0f1a040..bb974ea 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,3 @@ [pytest] testpaths = test -addopts = --cov=localite -r a -v \ No newline at end of file +addopts = --cov=localite -r a -v --cov-report html \ No newline at end of file diff --git a/test/flow/test_loc.py b/test/flow/test_loc.py index 789efa4..b156f40 100644 --- a/test/flow/test_loc.py +++ b/test/flow/test_loc.py @@ -1,7 +1,7 @@ # from .mock_localite import Mock -from pytest import fixture +from pytest import fixture, raises from localite.flow.mock import Mock -from localite.flow.loc import LOC, is_valid +from localite.flow.loc import LOC, is_valid, LastMessage from localite.flow.payload import Queue, Payload, put_in_queue, get_from_queue import time import json @@ -164,3 +164,27 @@ def pl(msg: str) -> Payload: assert is_valid(pl('{"coil_0_target_index": -1}')) == False assert is_valid(pl('{"current_instrument": "POINTER"}')) assert is_valid(pl('{"garbage": "garbage"}')) == False + + +def test_last_message_expects(): + lm = LastMessage() + assert lm.expects(None) == 0 + assert lm.expects(None) == 0 + + +def test_last_message_raises(): + pl = Payload(fmt="mrk", msg='{"single_pulse":"COIL_0"}') + lm = LastMessage() + with raises(ValueError): + lm.update(pl) + + +def test_last_message_works(): + pl = Payload(fmt="loc", msg='{"single_pulse":"COIL_0"}') + lm = LastMessage() + lm.update(pl) + assert lm.expects(None) == 1 + assert lm.expects(None) == 2 + response = {lm.expect: 1} + assert lm.expects(response) == 0 + assert lm.expect == None diff --git a/test/install b/test/install new file mode 100644 index 0000000..0f4200d --- /dev/null +++ b/test/install @@ -0,0 +1,7 @@ +#!/bin/bash +twine check dist/* +virtualenv .test +source .test/bin/activate +pip install git+https://github.com/labstreaminglayer/liblsl-Python.git +pip install dist/*.whl +pytest \ No newline at end of file