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:
Anna Schumaker 2015-04-23 10:50:36 -04:00
parent 673a6bd9c6
commit 3879e5e814
2 changed files with 16 additions and 7 deletions

View File

@ -9,10 +9,19 @@ class Serial:
self.baudrate = baudrate
self.timeout = timeout
def read(self, count):
def gen_key(self, count):
lst = [random.choice(string.hexdigits) for n in range(count - 2)]
ret = "A" + "".join(lst) + "D"
return ret.encode()
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()
raise Exception("Test Serial Exception")
def flushInput(self):
pass

View File

@ -13,12 +13,12 @@ class Request:
pass
def read(self):
val = random.randint(0, 2)
if val == 0:
val = random.randint(0, 4)
if val == 0 or val == 1:
return "OK".encode()
elif val == 1:
elif val == 2 or val == 3:
return "ERROR".encode()
raise Exception('Test Exception')
raise Exception("Test Network Exception")
def urlopen(url):