-
Notifications
You must be signed in to change notification settings - Fork 0
/
flight.py
139 lines (128 loc) · 5.86 KB
/
flight.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from activity_factory import *
# required inputs:
# file_to_test.column_list - provides the column name lookup for position
# config.get_options - provides the list of requested tests
# findings - in the odd case there are issuess we'd like know that
def build_flight_list(column_list,config_options,findings):
flight_list = []
column_number = 0
working_flight = object
for working_option in config_options:
if "test" in working_option:
#
# Process test option
#
column_number = 0
#
# name is required
#
if "name" not in working_option['test']:
findings.add_finding("name tag required")
continue
#
# use name to lookup column number,
# all column references are by column_number
#
if working_option['test']['name'] in column_list:
column_number = column_list.index(working_option['test']['name'])
else:
#
# can't fly with out the number, reject test entry
#
findings.add_finding(f"column not found {working_option['test']['name']}")
continue
# column name and position in file are determined
# create the flight object
working_flight = flight(working_option['test']['name'], column_number)
#
# set required flag
#
if 'required' in working_option['test'] :
working_flight.flight_data_required = working_option['test']['required']
#
# add regex flight test to the working flight
#
if 'width' in working_option['test']:
working_flight.append_flight_activity(flight_activity(
"width test",
f"column fialed width test",
generate_width_check(0,working_option['test']['width'][0],working_option['test']['width'][1])
))
if 'regex' in working_option['test']:
working_flight.append_flight_activity(flight_activity(
"regex test",
f"column failed regex test {working_option['test']['regex']}",
generate_regex_check("",working_option['test']['regex'])))
#
# add range flight activity to working flight
#
if 'range' in working_option['test']:
working_flight.append_flight_activity(flight_activity(
"range test",
f"column failed range test {working_option['test']['range'][0]},{working_option['test']['range'][1]}",
generate_range_check(0,working_option['test']['range'][0],working_option['test']['range'][1])))
#
if 'date_range' in working_option['test']:
working_flight.append_flight_activity(flight_activity(
"date range test",
f"column failed range test {working_option['test']['date_range'][0]},{working_option['test']['date_range'][1]}",
generate_date_range_check(0,working_option['test']['date_range'][0],working_option['test']['date_range'][1])))
#
# add type flight activity to working flight
# all flights start as string
#
if 'type' in working_option['test']:
if working_option['test']['type'] == 'date':
working_flight.update_type("date")
working_flight.append_flight_activity(flight_activity(
"date type check",
"column failed date check",
generate_date_type_check("")))
elif working_option['test']['type'] == 'number':
working_flight.update_type("number")
working_flight.append_flight_activity(flight_activity(
"number type check",
"column failed number check",
generate_number_type_check(0)
))
# all the flight tests are in, file the flight in the book
flight_list.append(working_flight)
return flight_list
#
# class flight container for flight activities
# flight_name - name for set of activities. atm this equals column name
# flight_number - the column positional order
# flight_type - a data type designation that enables other activivities
# flight_activities - an array of flight activity objects
#
class flight:
'''Models a flight. Flights have a column name, the number of the colum and a set of activities to preform on the column'''
def __init__(self,flight_name,flight_number):
self.flight_name = flight_name
self.flight_number = flight_number
self.flight_data_required = False
self.flight_type = "string"
self.flight_activities = []
def update_type(self,flight_type):
'''Used to validate and update flight type'''
if flight_type in ["date","number","money"]:
self.flight_type = flight_type
return True
return False
def append_flight_activity(self,flight_activity):
self.flight_activities.append(flight_activity)
#
# flight activity contains 3 parts
# name - name of activity requested (type, regex, and others)
# message - message returned on activity failure
# activity - a function that executes activity and returns result
# see check_factory.py
# true -> activity passed
# false -> activity failed
#
#
class flight_activity:
def __init__(self,name,message,activity):
self.flight_activity_name = name
self.flight_activity_message = message
self.flight_activity = activity