Robot Framework Integrated Development Environment (RIDE)
aligners.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 from .dataextractor import DataExtractor
17 
18 
19 class _Aligner():
20 
21  def __init__(self, widths=None):
22  self._widths_widths = widths or []
23 
24  def align_rows(self, rows):
25  return [self.align_rowalign_row(r) for r in rows]
26 
27  def align_row(self, row):
28  for index, col in enumerate(row):
29  if len(self._widths_widths) <= index:
30  break
31  row[index] = row[index].ljust(self._widths_widths[index])
32  return row
33 
34 
36 
37  def __init__(self, first_column_width):
38  _Aligner.__init__(self, [first_column_width])
39 
40 
42 
43  def __init__(self, first_column_width, table):
44  _Aligner.__init__(self, self._count_widths_count_widths(first_column_width, table))
45 
46  def _count_widths(self, first_column_width, table):
47  result = [first_column_width] + [len(h) for h in table.header[1:]]
48  for row in DataExtractor().rows_from_table(table):
49  for index, col in enumerate(row[1:]):
50  index += 1
51  if len(result) <= index:
52  result.append(len(col))
53  else:
54  result[index] = max(len(col), result[index])
55  return result
56 
57 
59 
60  def align_rows(self, rows):
61  return rows
62 
63  def align_row(self, row):
64  return row
def __init__(self, first_column_width, table)
Definition: aligners.py:43
def _count_widths(self, first_column_width, table)
Definition: aligners.py:46
Transforms table of a parsed test data file into a list of rows.