-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUnitTestTools.py
43 lines (39 loc) · 1.36 KB
/
UnitTestTools.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
31
32
33
34
35
36
37
38
39
40
41
42
43
'''
* File: UnitTestTools.py
* Copyright (c) 2023 Loupe
* https://loupe.team
*
* This file is part of ASPython, licensed under the MIT License.
'''
'''
UnitTest Tools
This package contains tools for running unit tests.
'''
import os
import requests
import subprocess
import logging
class UnitTestServer():
def __init__(self, host = 'http://127.0.0.1', destination = './TestResults'):
self._host = host
self._destination = destination
self.connected = False
# Retrieve list of tests.
try:
r = requests.get(url = self._host + '/WsTest/?', params = {})
if r.status_code == 200:
data = r.json()
self.testSuites = data['itemList']
self.connected = True
else:
logging.error(f'Received HTTP response {r.status_code} from the test server')
except Exception as e:
logging.error(f'Exception occurred while connecting to the test server ({e})')
def runTest(self, name):
for testSuite in self.testSuites:
if testSuite['device'] == name:
r = requests.get(url = self._host + '/WsTest/' + name, params = {})
if r.status_code == 200:
f = open(f'{os.path.join(self._destination, name)}.xml', 'w')
f.write(r.text)
f.close()