simulator: Add an RFID reader exception
So we can test what happens if the Serial library has an error. I also make exceptions less likely to happen. Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
parent
673a6bd9c6
commit
3879e5e814
|
@ -9,10 +9,19 @@ class Serial:
|
||||||
self.baudrate = baudrate
|
self.baudrate = baudrate
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
|
||||||
def read(self, count):
|
def gen_key(self, count):
|
||||||
lst = [random.choice(string.hexdigits) for n in range(count - 2)]
|
lst = [random.choice(string.hexdigits) for n in range(count - 2)]
|
||||||
ret = "A" + "".join(lst) + "D"
|
return "A" + "".join(lst) + "D"
|
||||||
|
|
||||||
|
def read(self, count):
|
||||||
|
val = random.randint(0, 4)
|
||||||
|
if val == 0 or val == 1:
|
||||||
|
return "".encode()
|
||||||
|
elif val == 2 or val == 3:
|
||||||
|
ret = self.gen_key(count)
|
||||||
|
print("> Serial generating key: %s" % ret)
|
||||||
return ret.encode()
|
return ret.encode()
|
||||||
|
raise Exception("Test Serial Exception")
|
||||||
|
|
||||||
def flushInput(self):
|
def flushInput(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -13,12 +13,12 @@ class Request:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
val = random.randint(0, 2)
|
val = random.randint(0, 4)
|
||||||
if val == 0:
|
if val == 0 or val == 1:
|
||||||
return "OK".encode()
|
return "OK".encode()
|
||||||
elif val == 1:
|
elif val == 2 or val == 3:
|
||||||
return "ERROR".encode()
|
return "ERROR".encode()
|
||||||
raise Exception('Test Exception')
|
raise Exception("Test Network Exception")
|
||||||
|
|
||||||
|
|
||||||
def urlopen(url):
|
def urlopen(url):
|
||||||
|
|
Loading…
Reference in New Issue