(self)
| 167 | self.assertEqual(res.body[0].value.id, expected) |
| 168 | |
| 169 | def test_invalid_position_information(self): |
| 170 | invalid_linenos = [ |
| 171 | (10, 1), (-10, -11), (10, -11), (-5, -2), (-5, 1) |
| 172 | ] |
| 173 | |
| 174 | for lineno, end_lineno in invalid_linenos: |
| 175 | with self.subTest(f"Check invalid linenos {lineno}:{end_lineno}"): |
| 176 | snippet = "a = 1" |
| 177 | tree = ast.parse(snippet) |
| 178 | tree.body[0].lineno = lineno |
| 179 | tree.body[0].end_lineno = end_lineno |
| 180 | with self.assertRaises(ValueError): |
| 181 | compile(tree, '<string>', 'exec') |
| 182 | |
| 183 | invalid_col_offsets = [ |
| 184 | (10, 1), (-10, -11), (10, -11), (-5, -2), (-5, 1) |
| 185 | ] |
| 186 | for col_offset, end_col_offset in invalid_col_offsets: |
| 187 | with self.subTest(f"Check invalid col_offset {col_offset}:{end_col_offset}"): |
| 188 | snippet = "a = 1" |
| 189 | tree = ast.parse(snippet) |
| 190 | tree.body[0].col_offset = col_offset |
| 191 | tree.body[0].end_col_offset = end_col_offset |
| 192 | with self.assertRaises(ValueError): |
| 193 | compile(tree, '<string>', 'exec') |
| 194 | |
| 195 | def test_compilation_of_ast_nodes_with_default_end_position_values(self): |
| 196 | tree = ast.Module(body=[ |
nothing calls this directly
no test coverage detected