-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathbase.py
30 lines (25 loc) · 929 Bytes
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Base testcase class with functions and state available to all tests.
# Author: Tony DiCola (tdicola@adafruit.com)
import os
import time
import unittest
import Adafruit_IO
class IOTestCase(unittest.TestCase):
def get_test_key(self):
"""Return the AIO key specified in the ADAFRUIT_IO_KEY environment
variable, or raise an exception if it doesn't exist.
"""
key = os.environ.get('ADAFRUIT_IO_KEY', None)
if key is None:
raise RuntimeError("ADAFRUIT_IO_KEY environment variable must be " \
"set with valid Adafruit IO key to run this test!")
return key
def ensure_feed_deleted(self, client, feed):
"""Delete the provided feed if it exists. Does nothing if the feed
doesn't exist.
"""
try:
client.delete_feed(feed)
except Adafruit_IO.RequestError:
# Swallow the error if the feed doesn't exist.
pass