Skip to content

Commit 038cf6b

Browse files
committed
Add option for parse main key column
1 parent 3ee2f6e commit 038cf6b

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

Examples/BasicDataDrivenExample.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ Validate user data template
1212
Log ${password}
1313
Log ${email}
1414
Should Be True '${password}' != '${None}'
15-
Should Match Regexp ${email} [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}
15+
# Should Match Regexp ${email} [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}
-106 Bytes
Binary file not shown.

ExcelDataDriver/ExcelParser/ABCParserStrategy.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ class ABCParserStrategy:
88

99
__metaclass__ = ABCMeta
1010

11-
def __init__(self):
11+
def __init__(self, main_column_key):
1212
self.MANDATORY_TEST_DATA_COLUMN = MANDATORY_TEST_DATA_COLUMN
1313
self.DEFAULT_COLUMN_INDEXS = self.MANDATORY_TEST_DATA_COLUMN.values()
1414
self.start_row = 1
1515
self.max_column = 50
1616
self.maximum_column_index_row = 5
17+
self.main_column_key = main_column_key
1718

1819
def is_ws_column_valid(self, ws, validate_result):
1920
ws_column_indexes = self.parsing_column_indexs(ws)
@@ -56,8 +57,9 @@ def parsing_column_indexs(self, ws):
5657
continue
5758
for cell in row:
5859
if (cell.value is not None) and (cell.value not in self.DEFAULT_COLUMN_INDEXS):
59-
ws_column_indexs[str(cell.value).lower().strip()] = column_index_from_string(coordinate_from_string(cell.coordinate)[0])
60-
print('Optional : '+str(str(cell.value).lower().strip()) + ' : ' + str(cell.coordinate) + ' : ' + str(column_index_from_string(coordinate_from_string(cell.coordinate)[0])))
60+
field_name = str(cell.value).lower().strip().replace(" ", "_")
61+
ws_column_indexs[field_name] = column_index_from_string(coordinate_from_string(cell.coordinate)[0])
62+
print('Optional : '+field_name + ' : ' + str(cell.coordinate) + ' : ' + str(column_index_from_string(coordinate_from_string(cell.coordinate)[0])))
6163
break
6264
print('Done parsing column indexes')
6365
return ws_column_indexs

ExcelDataDriver/ExcelParser/DefaultParserStrategy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
class DefaultParserStrategy(ABCParserStrategy):
66

7-
def __init__(self):
8-
ABCParserStrategy.__init__(self)
7+
def __init__(self, main_column_key):
8+
ABCParserStrategy.__init__(self, main_column_key)
99

1010
def is_test_data_valid(self, ws_column_indexes, ws_title, row_index, row):
1111
return True
@@ -17,7 +17,8 @@ def map_data_row_into_test_data_obj(self, ws_column_indexes, ws_title, row_index
1717
tags = row[ws_column_indexes[self.MANDATORY_TEST_DATA_COLUMN['tags']] - 1]
1818

1919
# Excel library send the last row with None data.
20-
if row[-1].value is None:
20+
main_key = row[ws_column_indexes[self.main_column_key] - 1]
21+
if main_key is None:
2122
return None
2223

2324
test_data_row = ExcelTestDataRow(ws_title, row_index, row, ws_column_indexes, status, log_message, screenshot, tags)

ExcelDataDriver/ExcelParser/DefaultReferenceParserStrategy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
class DefaultReferenceParserStrategy(ABCParserStrategy):
66

7-
def __init__(self):
8-
ABCParserStrategy.__init__(self)
7+
def __init__(self, main_column_key):
8+
ABCParserStrategy.__init__(self, main_column_key)
99

1010
def is_ws_column_valid(self, ws, validate_result):
1111
return validate_result
@@ -15,7 +15,8 @@ def is_test_data_valid(self, ws_column_indexes, ws_title, row_index, row):
1515

1616
def map_data_row_into_test_data_obj(self, ws_column_indexes, ws_title, row_index, row):
1717
# Excel library send the last row with None data.
18-
if row[-1].value is None:
18+
main_key = row[ws_column_indexes[self.main_column_key] - 1]
19+
if main_key is None:
1920
return None
2021

2122
test_data_row = ExcelReferenceDataRow(ws_title, row_index, row, ws_column_indexes)

ExcelDataDriver/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from ExcelDataDriver.Config.CaptureScreenShotOption import CaptureScreenShotOption
4040

4141

42-
__version__ = '1.1.0'
42+
__version__ = '1.1.1'
4343

4444

4545
class ExcelDataDriver:
@@ -55,10 +55,11 @@ class ExcelDataDriver:
5555
select_test_data = None
5656
parser_strategy = None
5757

58-
def __init__(self, file=None, custom_parser=None, capture_screenshot='Always', manually_test=False, validate_data_only=False):
58+
def __init__(self, file=None, main_column_key=None, custom_parser=None, capture_screenshot='Always', manually_test=False, validate_data_only=False):
5959
"""ExcelDataDriver can be imported with several optional arguments.
6060
6161
- ``file``: Excel xlsx test data file.
62+
- ``main_column_key``: Excel column key name.
6263
- ``custom_parser``: Default will use 'DefaultParserStrategy'.
6364
- ``capture_screenshot``: Config capture screen shot strategy. Option (Always, OnFailed, Skip) Default (Always).
6465
- ``validate_data_only``: For only validate the data in the excel file should be valid
@@ -71,10 +72,10 @@ def __init__(self, file=None, custom_parser=None, capture_screenshot='Always', m
7172
self.ROBOT_LIBRARY_LISTENER = self
7273
self.file = file
7374

74-
self.custom_parser = DefaultParserStrategy()
75+
self.custom_parser = DefaultParserStrategy(main_column_key)
7576
if custom_parser is not None:
7677
CustomExcelParser = self.load_module(custom_parser)
77-
self.custom_parser = CustomExcelParser.CustomExcelParser()
78+
self.custom_parser = CustomExcelParser.CustomExcelParser(main_column_key)
7879
self.capture_screenshot_option = CaptureScreenShotOption[capture_screenshot]
7980
self.manually_test = manually_test
8081
if self.file is None:

0 commit comments

Comments
 (0)