def _get_cell_position(self, col): # TODO: refactor if self.parent.has_template(): return CellPosition(CellType.UNKNOWN, None) col -= len(self._step.assign) if col < 0: return CellPosition(CellType.ASSIGN, None) if col == 0: return CellPosition(CellType.KEYWORD, None) info = self.get_keyword_info(self._step.keyword) if not info: return CellPosition(CellType.UNKNOWN, None) args = info.arguments args_amount = len(args) if args_amount == 0: return CellPosition(CellType.MUST_BE_EMPTY, None) if col >= args_amount and self._last_argument_is_varargs(args): return CellPosition(CellType.OPTIONAL, args[-1]) if self._has_list_var_value_before(col - 1): return CellPosition(CellType.UNKNOWN, None) if col > args_amount: return CellPosition(CellType.MUST_BE_EMPTY, None) if col <= self._number_of_mandatory_arguments(args, args_amount): return CellPosition(CellType.MANDATORY, args[col - 1]) return CellPosition(CellType.OPTIONAL, args[col - 1])
def test_optional_has_no_error(self): assert_false( CellInfo(CellContent(ContentType.EMPTY, '', ''), CellPosition(CellType.OPTIONAL, None)).has_error()) assert_false( CellInfo(CellContent(ContentType.STRING, '', ''), CellPosition(CellType.OPTIONAL, None)).has_error())
def test_for_loop_too_many_args(self): cell = CellInfo(CellContent(ContentType.STRING, 'something'), CellPosition(CellType.MUST_BE_EMPTY, None), for_loop=True) msg = TipMessage(cell) assert_true(msg) assert_equals(str(msg), _ForLoopTooltipMessage.TOO_MANY_ARGUMENTS)
def test_known_keyword(self): cell = CellInfo(CellContent(ContentType.USER_KEYWORD, 'Known', 'my_source'), CellPosition(CellType.KEYWORD, None)) msg = TipMessage(cell) assert_true(msg) assert_equal(str(msg), html_escape(_TooltipMessage.KEYWORD % 'my_source'))
def _get_cell_position(self, col): until_range = len(self._step.vars) + 1 if col == 0: return CellPosition(CellType.MANDATORY, None) if col < until_range: return CellPosition(CellType.ASSIGN, None) if col == until_range: return CellPosition(CellType.MANDATORY, None) if not self._step.range: return CellPosition(CellType.OPTIONAL, None) if col <= until_range + 1: return CellPosition(CellType.MANDATORY, None) if col <= until_range + 3: return CellPosition(CellType.OPTIONAL, None) return CellPosition(CellType.MUST_BE_EMPTY, None)
def get_cell_info(self, row, column): return CellInfo( CellContent(self._get(self.content_types), self._get_data(), None), CellPosition(self._get(self.cell_types), None))
def _get_cell_position(self, col): if col == 0: return CellPosition(CellType.MUST_BE_EMPTY, None) return StepController._get_cell_position(self, col - 1)
def test_empty_tooltip(self): cell = CellInfo(CellContent(ContentType.EMPTY, None), CellPosition(CellType.UNKNOWN, None)) assert_false(TipMessage(cell))
def test_unknown_variable(self): cell = CellInfo( CellContent(ContentType.UNKNOWN_VARIABLE, '${unknown}'), CellPosition(CellType.UNKNOWN, None)) assert_true(TipMessage(cell))
def test_for_loop_var(self): cell = CellInfo(CellContent(ContentType.VARIABLE, '${i}'), CellPosition(CellType.MANDATORY, None), for_loop=True) assert_false(TipMessage(cell))
def test_for_loop_start(self): cell = CellInfo(CellContent(ContentType.STRING, ':FOR'), CellPosition(CellType.MANDATORY, None), for_loop=True) assert_false(TipMessage(cell))
def test_unknown_keyword(self): cell = CellInfo(CellContent(ContentType.STRING, 'What?'), CellPosition(CellType.KEYWORD, None)) msg = TipMessage(cell) assert_true(msg) assert_equals(str(msg), _TooltipMessage.KEYWORD_NOT_FOUND)
def test_empty_mandatory_empty_is_not_error(self): cell = CellInfo(CellContent(ContentType.EMPTY, '', ''), CellPosition(CellType.MUST_BE_EMPTY, None)) assert_false(cell.has_error()) assert_false(cell.too_many_arguments())
def test_commented_mandatory_is_error(self): cell = CellInfo(CellContent(ContentType.COMMENTED, '', ''), CellPosition(CellType.MANDATORY, None)) assert_true(cell.has_error()) assert_true(cell.argument_missing())
def test_none_empty_mandatory_is_not_error(self): cell = CellInfo(CellContent(ContentType.LIBRARY_KEYWORD, '', ''), CellPosition(CellType.MANDATORY, None)) assert_false(cell.has_error()) assert_false(cell.argument_missing())