def test_warn_old_comment(self, capsys): instance = Deprecations.reset_instance() assert not instance._old_comment_warned assert not instance._old_choice_warned instance.warn_old_comment() assert instance._old_comment_warned assert not instance._old_choice_warned captured = capsys.readouterr() assert "Comments starting with a semi-colon" in captured.err instance = Deprecations.reset_instance() instance.warn_old_comment("filename") captured = capsys.readouterr() assert "This syntax was found in file 'filename'." in captured.err instance = Deprecations.reset_instance() instance.warn_old_comment("filename", 12, "line") captured = capsys.readouterr() assert \ "This syntax was found in file 'filename'" + \ " at line 12: 'line'." in captured.err instance = Deprecations.reset_instance() instance.warn_old_comment(line_nb=12, line="line") captured = capsys.readouterr() assert \ "This syntax was found" + \ " at line 12: 'line'." in captured.err
def _apply_strategy(self, **kwargs): text = self._text whitespaces_rule = RuleWhitespaces(self._text, self._next_index) if whitespaces_rule.matches(): self._next_index = whitespaces_rule.get_next_index_to_match() self._update_furthest_matched_index() # ignore the tokens it found since this whitespace is not meaningful if self._next_index >= len(text): return True if ( text.startswith(COMMENT_SYM, self._next_index) or text.startswith(OLD_COMMENT_SYM, self._next_index) ): if text.startswith(OLD_COMMENT_SYM, self._next_index): Deprecations.get_or_create().warn_old_comment( *(InputFileManager \ .get_or_create() \ .get_current_line_information()) ) matched_text = text[self._next_index:] self._tokens.append(LexicalToken(TerminalType.comment, matched_text)) self._next_index = len(text) self._update_furthest_matched_index() return True # No comment found self.error_msg = \ "Invalid token. Expected a comment there (starting with '" + \ COMMENT_SYM + "' or '" + OLD_COMMENT_SYM + "')." return False
def _apply_strategy(self, **kwargs): start_char = None if self._text.startswith(OLD_CHOICE_START, self._next_index): start_char = OLD_CHOICE_START sep_char = OLD_CHOICE_SEP end_char = OLD_CHOICE_END Deprecations.get_or_create().warn_old_choice( *(InputFileManager \ .get_or_create() \ .get_current_line_information()) ) elif self._text.startswith(CHOICE_START, self._next_index): start_char = CHOICE_START sep_char = CHOICE_SEP end_char = CHOICE_END if start_char is None: self.error_msg = \ "Invalid token. Expected a choice to start there (starting " + \ "with '" + CHOICE_START + "' or '" + OLD_CHOICE_START + "')." return False self._next_index += 1 self._update_furthest_matched_index() self._tokens.append(LexicalToken(TerminalType.choice_start, start_char)) if self._text.startswith(CASE_GEN_SYM, self._next_index): self._next_index += 1 self._update_furthest_matched_index() self._tokens.append( LexicalToken(TerminalType.casegen_marker, CASE_GEN_SYM)) if not self._try_to_match_rule(RuleWhitespaces): self.error_msg = None while True: if self._text.startswith(sep_char, self._next_index): self._next_index += 1 self._update_furthest_matched_index() self._tokens.append( LexicalToken(TerminalType.choice_sep, sep_char)) if not self._try_to_match_rule(RuleWhitespaces): self.error_msg = None rule_content_rule = RuleContentRule(self._text, self._next_index) if not rule_content_rule.matches(inside_choice=True): self.error_msg = None self._update_furthest_matched_index(rule_content_rule) break self._next_index = rule_content_rule.get_next_index_to_match() self._update_furthest_matched_index(rule_content_rule) self._tokens.extend(rule_content_rule.get_lexical_tokens()) if not self._try_to_match_rule(RuleRandGen): self.error_msg = None if not self._text.startswith(end_char, self._next_index): self.error_msg = \ "Invalid token. Unmatched choice opening character. " + \ "Expected the choice to end here (using " + \ "character '" + end_char + "')." return False self._next_index += 1 self._update_furthest_matched_index() self._tokens.append(LexicalToken(TerminalType.choice_end, end_char)) return True
def reset_system(cls, *args, **kwargs): Stats.reset_instance() Deprecations.reset_instance() AST.reset_instance() InputFileManager.reset_instance(None) return cls.reset_instance(*args, **kwargs)
def test_new(self): instance = Deprecations() same = Deprecations.get_or_create() assert instance == same assert not instance._old_comment_warned assert not instance._old_choice_warned