|
1 | 1 | import sys |
2 | | -from multiprocessing import Process |
3 | | -# look in ../ BEFORE trying to import Algorithmia. If you append to the |
4 | | -# you will load the version installed on the computer. |
5 | | -sys.path = ['../'] + sys.path |
6 | 2 |
|
7 | | -import unittest |
8 | | -import Algorithmia |
9 | | -import uvicorn |
10 | | -import time |
11 | | -from requests import Response |
12 | | -from Test.api import app |
| 3 | +if sys.version_info[0] >= 3: |
| 4 | + import unittest |
| 5 | + import Algorithmia |
| 6 | + import uvicorn |
| 7 | + import time |
| 8 | + from multiprocessing import Process |
| 9 | + # look in ../ BEFORE trying to import Algorithmia. If you append to the |
| 10 | + # you will load the version installed on the computer. |
| 11 | + sys.path = ['../'] + sys.path |
| 12 | + from requests import Response |
| 13 | + from Test.api import app |
13 | 14 |
|
14 | | -def start_webserver(): |
15 | | - uvicorn.run(app, host="127.0.0.1", port=8080, log_level="debug") |
| 15 | + def start_webserver(): |
| 16 | + uvicorn.run(app, host="127.0.0.1", port=8080, log_level="debug") |
16 | 17 |
|
17 | | -class AlgoTest(unittest.TestCase): |
18 | | - error_500 = Response() |
19 | | - error_500.status_code = 500 |
| 18 | + class AlgoTest(unittest.TestCase): |
| 19 | + error_500 = Response() |
| 20 | + error_500.status_code = 500 |
20 | 21 |
|
21 | | - def setUp(self): |
22 | | - self.client = Algorithmia.client(api_address="http://localhost:8080") |
23 | | - self.uvi_p = Process(target=start_webserver) |
24 | | - self.uvi_p.start() |
25 | | - time.sleep(1) |
26 | | - def tearDown(self): |
27 | | - self.uvi_p.terminate() |
28 | | - def test_throw_500_error_HTTP_response_on_algo_request(self): |
29 | | - try: |
30 | | - result = self.client.algo('util/Echo').pipe(bytearray('foo','utf-8')) |
31 | | - except Exception as e: |
32 | | - result = e |
33 | | - pass |
34 | | - self.assertEqual(str(self.error_500), str(result)) |
| 22 | + def setUp(self): |
| 23 | + self.client = Algorithmia.client(api_address="http://localhost:8080") |
| 24 | + self.uvi_p = Process(target=start_webserver) |
| 25 | + self.uvi_p.start() |
| 26 | + time.sleep(1) |
| 27 | + def tearDown(self): |
| 28 | + self.uvi_p.terminate() |
| 29 | + def test_throw_500_error_HTTP_response_on_algo_request(self): |
| 30 | + try: |
| 31 | + result = self.client.algo('util/Echo').pipe(bytearray('foo','utf-8')) |
| 32 | + except Exception as e: |
| 33 | + result = e |
| 34 | + pass |
| 35 | + self.assertEqual(str(self.error_500), str(result)) |
0 commit comments