| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -317,7 +317,7 @@ def test_with_errored_file(self): | |||
| 317 | 317 | with TemporaryPyFile(SOURCE_CODES["wrong_indented"]) as file_path: | |
| 318 | 318 | stderr = f"{file_path!r}: Token Error: " | |
| 319 | 319 | stderr += ('unindent does not match any outer indentation level' | |
| 320 | - ' (<tokenize>, line 3)') | ||
| 320 | + ' (<string>, line 3)') | ||
| 321 | 321 | self.validate_cmd(file_path, stderr=stderr, expect_failure=True) | |
| 322 | 322 | ||
| 323 | 323 | def test_with_error_free_file(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -92,9 +92,18 @@ def k(x): | |||
| 92 | 92 | readline = BytesIO(indent_error_file).readline | |
| 93 | 93 | with self.assertRaisesRegex(IndentationError, | |
| 94 | 94 | "unindent does not match any " | |
| 95 | - "outer indentation level"): | ||
| 95 | + "outer indentation level") as e: | ||
| 96 | 96 | for tok in tokenize(readline): | |
| 97 | 97 | pass | |
| 98 | + self.assertEqual(e.exception.lineno, 3) | ||
| 99 | + self.assertEqual(e.exception.filename, '<string>') | ||
| 100 | + self.assertEqual(e.exception.end_lineno, None) | ||
| 101 | + self.assertEqual(e.exception.end_offset, None) | ||
| 102 | + self.assertEqual( | ||
| 103 | + e.exception.msg, | ||
| 104 | + 'unindent does not match any outer indentation level') | ||
| 105 | + self.assertEqual(e.exception.offset, 9) | ||
| 106 | + self.assertEqual(e.exception.text, ' x += 5\n') | ||
| 98 | 107 | ||
| 99 | 108 | def test_int(self): | |
| 100 | 109 | # Ordinary integers and binary operators | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,11 +89,9 @@ _tokenizer_error(struct tok_state *tok) | |||
| 89 | 89 | } | |
| 90 | 90 | return -1; | |
| 91 | 91 | case E_DEDENT: | |
| 92 | - PyErr_Format(PyExc_IndentationError, | ||
| 93 | - "unindent does not match any outer indentation level " | ||
| 94 | - "(<tokenize>, line %d)", | ||
| 95 | - tok->lineno); | ||
| 96 | - return -1; | ||
| 92 | + msg = "unindent does not match any outer indentation level"; | ||
| 93 | + errtype = PyExc_IndentationError; | ||
| 94 | + break; | ||
| 97 | 95 | case E_INTR: | |
| 98 | 96 | if (!PyErr_Occurred()) { | |
| 99 | 97 | PyErr_SetNone(PyExc_KeyboardInterrupt); | |
@@ -131,7 +129,12 @@ _tokenizer_error(struct tok_state *tok) | |||
| 131 | 129 | goto exit; | |
| 132 | 130 | } | |
| 133 | 131 | ||
| 134 | - tmp = Py_BuildValue("(OnnOii)", tok->filename, tok->lineno, 0, error_line, 0, 0); | ||
| 132 | + Py_ssize_t offset = _PyPegen_byte_offset_to_character_offset(error_line, tok->inp - tok->buf); | ||
| 133 | + if (offset == -1) { | ||
| 134 | + result = -1; | ||
| 135 | + goto exit; | ||
| 136 | + } | ||
| 137 | + tmp = Py_BuildValue("(OnnOOO)", tok->filename, tok->lineno, offset, error_line, Py_None, Py_None); | ||
| 135 | 138 | if (!tmp) { | |
| 136 | 139 | result = -1; | |
| 137 | 140 | goto exit; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments