tests:mock-bus more python3 comptaible
This commit is contained in:
@@ -2,12 +2,18 @@ from collections import namedtuple
|
|||||||
|
|
||||||
from .context import sgp30
|
from .context import sgp30
|
||||||
from time import time
|
from time import time
|
||||||
|
import sys
|
||||||
|
|
||||||
I2CAnswers= namedtuple("I2CAnswers",["answer","min_delay"])
|
I2CAnswers= namedtuple("I2CAnswers",["answer","min_delay"])
|
||||||
I2A = I2CAnswers
|
I2A = I2CAnswers
|
||||||
def add_crc(l):
|
def add_crc(l):
|
||||||
return l + [sgp30.Crc8().hash(l)]
|
return l + [sgp30.Crc8().hash(l)]
|
||||||
|
|
||||||
|
if sys.version_info[0] < 3:
|
||||||
|
byte_from_int = chr
|
||||||
|
else:
|
||||||
|
byte_from_int = lambda x: bytes([x])
|
||||||
|
|
||||||
answers = {
|
answers = {
|
||||||
(0x36, 0x82): I2A(add_crc([0,0]),.4), #GET_SERIAL
|
(0x36, 0x82): I2A(add_crc([0,0]),.4), #GET_SERIAL
|
||||||
(0x20, 0x15): I2A(add_crc([0,0]), 1), #GET_FEATURES
|
(0x20, 0x15): I2A(add_crc([0,0]), 1), #GET_FEATURES
|
||||||
@@ -47,9 +53,9 @@ class MockSMBus:
|
|||||||
if s.status == None:
|
if s.status == None:
|
||||||
raise AssertionError("Tried to read before write")
|
raise AssertionError("Tried to read before write")
|
||||||
for i in range(len(s.status)):
|
for i in range(len(s.status)):
|
||||||
msg.buf[i]=chr(s.status[i])
|
msg.buf[i]=byte_from_int(s.status[i])
|
||||||
if s._break_crc and i%3 == 2:
|
if s._break_crc and i%3 == 2:
|
||||||
msg.buf[i]=chr(s.status[i]^42)
|
msg.buf[i]=byte_from_int(s.status[i]^42)
|
||||||
s.status=None
|
s.status=None
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user