Skip to content

Commit 02e297d

Browse files
committed
Support option serial tests
1 parent e9cdd60 commit 02e297d

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ jobs:
3232
run: |
3333
python3 -m pip install --upgrade pip
3434
python3 -m pip install wheel
35-
if [ -f requirements.txt ]; then python3 -m pip install -r requirements.txt; fi
35+
python3 -m pip install -r requirements.txt
36+
python3 -m pip install -r requirements-serial.txt
3637
python3 -m pip install flake8 pytest
3738
- name: Lint with flake8
3839
run: |

GNUmakefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ dist/SLIP39.app: SLIP39.py FORCE
7575
# o advance __version__ number in slip32/version.py
7676
# o log in to your pypi account (ie. for package maintainer only)
7777

78-
upload: wheel
78+
upload-check:
79+
@$(PY3) -m twine --version \
80+
|| ( echo "\n*** Missing Python modules; run:\n\n $(PY3) -m pip install --upgrade twine\n" \
81+
&& false )
82+
upload: upload-check wheel
7983
python3 -m twine upload --repository pypi dist/slip39-$(VERSION)*
8084

8185
clean:

slip39/generator_test.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import pty
44
import threading
55

6-
from serial import Serial
6+
import pytest
7+
8+
try:
9+
from serial import Serial
10+
except ImportError:
11+
Serial = None
712

813
from .api import RANDOM_BYTES, accountgroups
914
from .generator import chacha20poly1305, accountgroups_output, accountgroups_input
@@ -25,6 +30,8 @@ def listener(port):
2530
os.write(port, b"I don't understand\r\n")
2631

2732

33+
@pytest.mark.skipif( not Serial,
34+
reason="Serial testing needs pyserial" )
2835
def test_serial():
2936
"""Start the testing"""
3037
master,slave = pty.openpty() # open the pseudoterminal
@@ -77,20 +84,8 @@ def generator( password, cryptopaths, fd ):
7784
)
7885

7986

80-
class SerialEOF( Serial ):
81-
"""Convert any SerialException to an EOFError, for compatibility with PTY. In real serial ports,
82-
we'll handle detection of counterparty readiness with DTR/DSR, and flow control with RTS/CTS."""
83-
def read( self, size=1 ):
84-
while True:
85-
try:
86-
return super( SerialEOF, self ).read( size=size )
87-
except Exception as exc: # SerialError as exc:
88-
# if "readiness" in str(exc):
89-
# time.sleep( .1 )
90-
# continue
91-
raise EOFError( str( exc ))
92-
93-
87+
@pytest.mark.skipif( not Serial,
88+
reason="Serial testing needs pyserial" )
9489
def test_groups_pty():
9590
password = "password"
9691
master,slave = pty.openpty()
@@ -107,6 +102,22 @@ def test_groups_pty():
107102
gen.daemon = True
108103
gen.start()
109104

105+
class SerialEOF( Serial ):
106+
"""Convert any SerialException to an EOFError, for compatibility with PTY. In real serial
107+
ports, we'll handle detection of counterparty readiness with DTR/DSR, and flow control with
108+
RTS/CTS.
109+
110+
"""
111+
def read( self, size=1 ):
112+
while True:
113+
try:
114+
return super( SerialEOF, self ).read( size=size )
115+
except Exception as exc: # SerialError as exc:
116+
# if "readiness" in str(exc):
117+
# time.sleep( .1 )
118+
# continue
119+
raise EOFError( str( exc ))
120+
110121
ser = SerialEOF( slave_name, timeout=1)
111122
for group in accountgroups_input(
112123
cipher = chacha20poly1305( password=password ),

0 commit comments

Comments
 (0)