-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestCaseParser.py
executable file
·76 lines (57 loc) · 1.91 KB
/
TestCaseParser.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python
import glob
import json
from Action import Action
from Drone import Drone
from TestCase import TestCase
from WayPointList import WayPointList
class TestCaseParser:
def __init__(self, folderName):
self.files = glob.glob('{}/*.json'.format(folderName))
def parseAction(self, actionData):
startTime = actionData["startTime"]
act = actionData["action"]
try:
ttl = actionData["ttl"]
except:
ttl = None
try:
target = actionData["target"]
except:
target = None
return Action(act, startTime, target, ttl)
def parseDrone(self, droneData):
uid = droneData["uid"]
startTime = int(droneData["startTime"])
pointList = WayPointList(droneData["waypoints"])
actionsList = droneData["actions"]
actions = []
for actionData in actionsList:
actions.append(self.parseAction(actionData))
return Drone(uid, startTime, pointList, actions.sort())
def parseDrones(self, dronesJson):
drones = set()
for droneData in dronesJson:
drones.add(self.parseDrone(droneData))
return drones
def load(self, fileName):
fp = open(fileName, "r")
jsonData = json.load(fp)
name = jsonData["name"]
timeLimit = int(jsonData["timeLimit"])
droneList = jsonData["drones"]
noFlyZones = jsonData["noFlyZones"]
mannedAviation = jsonData["mannedAviation"]
drones = self.parseDrones(droneList)
testCase = TestCase(name, timeLimit, drones, noFlyZones, mannedAviation)
return testCase
def loadAll(self):
testCases = set()
for file in self.files:
testCases.add(self.load(file))
return testCases
def main():
parser = TestCaseParser("droneData")
testCases = parser.loadAll()
if __name__ == "__main__":
main()