Skip to content

Commit

Permalink
utils.astring: Fix index usage
Browse files Browse the repository at this point in the history
we already set the "index += len(tmp_word) + 1" before we get to this
exception so we must not add the tmp_index.

Signed-off-by: Lukáš Doktor <[email protected]>
  • Loading branch information
ldoktor committed Aug 19, 2024
1 parent 0a99d55 commit 10da7da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aexpect/utils/astring.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def strip_console_codes(output, custom_codes=None):
try:
special_code = re.findall(console_codes, tmp_word)[0]
except IndexError as error:
if index + tmp_index < len(output):
if index < len(output):
raise ValueError(f"{tmp_word} is not included in the known "
"console codes list "
f"{console_codes}") from error
Expand Down
8 changes: 6 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ def test_strip_console_codes(self):
strip = astring.strip_console_codes
self.assertEqual("simple color test",
strip("simple\x1b[33;1m color \x1b[0mtest"))
self.assertEqual("[33;1mstarts with code", "[33;1mstarts with code")
self.assertEqual("ends with escape\x1b", "ends with escape\x1b")
self.assertEqual("",
strip("\x1bskip-full-text"))
self.assertEqual("ignores last",
strip("ignores last\x1bbad"))
self.assertRaisesRegex(ValueError, "only is not included", strip,
"ignores\x1bonly\x1blast\x1bbad")


if __name__ == '__main__':
Expand Down

0 comments on commit 10da7da

Please sign in to comment.