Robot Framework Integrated Development Environment (RIDE)
dataextractor.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 
17 
18 class DataExtractor():
19 
20  def __init__(self, want_name_on_first_row=None):
21  self._want_name_on_first_row_want_name_on_first_row = want_name_on_first_row or \
22  (lambda t,n: False)
23 
24  def rows_from_table(self, table):
25  if table.type in ['setting', 'variable']:
26  return self._rows_from_item_rows_from_item(table)
27  return self._rows_from_indented_table_rows_from_indented_table(table)
28 
29  def _rows_from_indented_table(self, table):
30  items = list(table)
31  for index, item in enumerate(items):
32  for row in self._rows_from_test_or_keyword_rows_from_test_or_keyword(item, table):
33  yield row
34  if not self._last_last(items, index):
35  yield []
36 
37  def _rows_from_test_or_keyword(self, test_or_keyword, table):
38  rows = list(self._rows_from_item_rows_from_item(test_or_keyword, 1))
39  for r in self._add_name_add_name(test_or_keyword.name, rows, table):
40  yield r
41 
42  def _add_name(self, name, rows, table):
43  if rows and self._want_name_on_first_row_want_name_on_first_row(table, name):
44  rows[0][0] = name
45  return rows
46  return [[name]] + rows
47 
48  def _rows_from_item(self, item, indent=0):
49  for child in item:
50  if child.is_set():
51  yield [''] * indent + child.as_list()
52  if child.is_for_loop():
53  for row in self._rows_from_item_rows_from_item(child, indent+1):
54  yield row
55  # DEBUG Must be explicit yield ['', 'END']
56 
57  def _last(self, items, index):
58  return index >= len(items) -1
Transforms table of a parsed test data file into a list of rows.
def __init__(self, want_name_on_first_row=None)
def _rows_from_test_or_keyword(self, test_or_keyword, table)