Skip to content

Commit

Permalink
Increase coverage and fix makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
agricolab committed Feb 17, 2020
1 parent accf835 commit 0138607
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion localite/flow/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions localite/flow/loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[pytest]
testpaths = test
addopts = --cov=localite -r a -v
addopts = --cov=localite -r a -v --cov-report html
28 changes: 26 additions & 2 deletions test/flow/test_loc.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions test/install
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0138607

Please sign in to comment.