MCPcopy Index your code
hub / github.com/python/cpython / test_ast_line_numbers_with_parentheses

Method test_ast_line_numbers_with_parentheses

Lib/test/test_fstring.py:386–499  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

384 self.assertEqual(t.body[0].value.values[1].value.end_col_offset, 16)
385
386 def test_ast_line_numbers_with_parentheses(self):
387 expr = """
388x = (
389 f" {test(t)}"
390)"""
391 t = ast.parse(expr)
392 self.assertEqual(type(t), ast.Module)
393 self.assertEqual(len(t.body), 1)
394 # check the joinedstr location
395 joinedstr = t.body[0].value
396 self.assertEqual(type(joinedstr), ast.JoinedStr)
397 self.assertEqual(joinedstr.lineno, 3)
398 self.assertEqual(joinedstr.end_lineno, 3)
399 self.assertEqual(joinedstr.col_offset, 4)
400 self.assertEqual(joinedstr.end_col_offset, 17)
401 # check the formatted value location
402 fv = t.body[0].value.values[1]
403 self.assertEqual(type(fv), ast.FormattedValue)
404 self.assertEqual(fv.lineno, 3)
405 self.assertEqual(fv.end_lineno, 3)
406 self.assertEqual(fv.col_offset, 7)
407 self.assertEqual(fv.end_col_offset, 16)
408 # check the test(t) location
409 call = t.body[0].value.values[1].value
410 self.assertEqual(type(call), ast.Call)
411 self.assertEqual(call.lineno, 3)
412 self.assertEqual(call.end_lineno, 3)
413 self.assertEqual(call.col_offset, 8)
414 self.assertEqual(call.end_col_offset, 15)
415
416 expr = """
417x = (
418 u'wat',
419 u"wat",
420 b'wat',
421 b"wat",
422 f'wat',
423 f"wat",
424)
425
426y = (
427 u'''wat''',
428 u\"\"\"wat\"\"\",
429 b'''wat''',
430 b\"\"\"wat\"\"\",
431 f'''wat''',
432 f\"\"\"wat\"\"\",
433)
434 """
435 t = ast.parse(expr)
436 self.assertEqual(type(t), ast.Module)
437 self.assertEqual(len(t.body), 2)
438 x, y = t.body
439
440 # Check the single quoted string offsets first.
441 offsets = [
442 (elt.col_offset, elt.end_col_offset)
443 for elt in x.value.elts

Callers

nothing calls this directly

Calls 3

assertEqualMethod · 0.95
assertTrueMethod · 0.95
parseMethod · 0.45

Tested by

no test coverage detected