Skip to content

Commit

Permalink
Wrap lsl to mock import for readthedocs
Browse files Browse the repository at this point in the history
  • Loading branch information
agricolab committed Dec 13, 2019
1 parent ffb3d54 commit e8868da
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion localite/flow/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import threading
import json
from localite.flow.payload import Payload, has_poison, Queue, put_in_queue
from pylsl import local_clock
from localite.flow.lsl import local_clock
from typing import Dict, Any
from subprocess import Popen
from typing import Union, Tuple
Expand Down
2 changes: 1 addition & 1 deletion localite/flow/loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import threading
from typing import List, Union, Dict, Any, Tuple
from pylsl import local_clock
from localite.flow.lsl import local_clock
from localite.flow.payload import Queue, get_from_queue, put_in_queue, Payload

constant_messages = [
Expand Down
11 changes: 11 additions & 0 deletions localite/flow/lsl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

if not os.environ.get("READTHEDOCS", False):
from pylsl import StreamInfo, StreamInlet, StreamOutlet, local_clock, resolve_stream
else: # pragma no cover
from time import time as local_clock

def resolve_stream(*args, **kwargs):
pass

StreamInfo = StreamInlet = StreamOutlet = resolve_stream
9 changes: 7 additions & 2 deletions localite/flow/mrk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from pylsl import StreamInfo, StreamInlet, StreamOutlet, local_clock, resolve_stream
from localite.flow.lsl import (
StreamInfo,
StreamInlet,
StreamOutlet,
local_clock,
resolve_stream,
)
import json
from localite.flow.payload import Queue, get_from_queue
import socket
Expand Down Expand Up @@ -60,7 +66,6 @@ def await_response(self, msg: str):
if key in item[0][0]:
return json.loads(item[0][0]), item[1]
time.sleep(0.01)
print(".", end="")

@property
def content(self) -> List[Any]:
Expand Down
11 changes: 9 additions & 2 deletions localite/flow/payload.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import NewType, Dict, Union, Tuple
from queue import Queue
import json
from pylsl import local_clock
from localite.flow.lsl import local_clock

TimeStamp = Union[
int, None
Expand All @@ -25,10 +25,17 @@ def __repr__(self):

def __eq__(self, other):
if isinstance(other, Payload):
return all((self.fmt == other.fmt, self.msg == other.msg, self.tstamp == other.tstamp))
return all(
(
self.fmt == other.fmt,
self.msg == other.msg,
self.tstamp == other.tstamp,
)
)
else:
return False


def has_poison(payload: Payload) -> bool:
"return whether there is a poison-pill in the Payload"
if (payload.fmt, payload.msg) == ("cmd", "poison-pill"):
Expand Down
2 changes: 1 addition & 1 deletion test/flow/test_mitm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def mock():
def test_setup_tear_down(mock, capsys):
start_threaded(loc_host="127.0.0.1")
kill()
time.sleep(1)
time.sleep(2)
pipe = capsys.readouterr()
assert "Shutting EXT down" in pipe.out
assert "Shutting CTRL down" in pipe.out
Expand Down

0 comments on commit e8868da

Please sign in to comment.