1
|
|
|
"""
|
2
|
|
|
Testing key methods from Parameter Handling class
|
3
|
|
|
"""
|
4
|
|
|
from datetime import datetime
|
5
|
|
|
import os
|
6
|
|
|
from db_extractor.FileOperations import FileOperations
|
7
|
|
|
from db_extractor.ParameterHandling import ParameterHandling
|
8
|
|
|
from db_extractor.ExtractNeeds import ExtractNeeds
|
9
|
|
|
import unittest
|
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class TestParameterHandling(unittest.TestCase):
|
13
|
|
|
|
14
|
|
|
def test_interpret_known_expression(self):
|
15
|
|
|
class_fo = FileOperations()
|
16
|
|
|
class_en = ExtractNeeds(os.path.basename(__file__).replace('.py', ''))
|
17
|
|
|
# load testing values from JSON file
|
18
|
|
|
# where all cases are grouped
|
19
|
|
|
json_structure = class_fo.fn_open_file_and_get_content(
|
20
|
|
|
os.path.join(os.path.dirname(__file__), 'expressions.json'))
|
21
|
|
|
# flatten out all testing values
|
22
|
|
|
pair_values = []
|
23
|
|
|
for crt_list in json_structure.values():
|
24
|
|
|
pair_values += crt_list
|
25
|
|
|
# parse through all pair of values and run the test
|
26
|
|
|
class_ph = ParameterHandling()
|
27
|
|
|
for current_pair in pair_values:
|
28
|
|
|
reference_format = '%Y-%m-%d'
|
29
|
|
|
if 'reference_format' in current_pair:
|
30
|
|
|
reference_format = current_pair['reference_format']
|
31
|
|
|
reference_date = datetime.strptime(current_pair['reference_value'], reference_format)
|
32
|
|
|
expression_parts = current_pair['expression'].split('_')
|
33
|
|
|
current_pair['start-iso-weekday'] = class_ph.set_default_starting_weekday({
|
34
|
|
|
'session': current_pair,
|
35
|
|
|
'query': current_pair,
|
36
|
|
|
'sequence': current_pair,
|
37
|
|
|
})
|
38
|
|
|
value_to_assert = class_ph.interpret_known_expression(
|
39
|
|
|
reference_date, expression_parts, current_pair['start-iso-weekday'])
|
40
|
|
|
self.assertEqual(value_to_assert, current_pair['expected_value'],
|
41
|
|
|
'Provided value was "' + current_pair['reference_value']
|
42
|
|
|
+ '", Expression was "' + current_pair['expression'] + '" '
|
43
|
|
|
+ '", Expected was "' + current_pair['expected_value'] + '" '
|
44
|
|
|
+ 'but received was "' + value_to_assert + '"...')
|
45
|
|
|
|
46
|
|
|
|
47
|
|
|
if __name__ == '__main__':
|
48
|
|
|
unittest.main()
|
49
|
|
|
|
50
|
|
|
|