MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_char_index_at

Function test_char_index_at

lib/matplotlib/tests/test_text.py:361–384  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

359
360
361def test_char_index_at():
362 fig = plt.figure()
363 text = fig.text(0.1, 0.9, "")
364
365 text.set_text("i")
366 bbox = text.get_window_extent()
367 size_i = bbox.x1 - bbox.x0
368
369 text.set_text("m")
370 bbox = text.get_window_extent()
371 size_m = bbox.x1 - bbox.x0
372
373 text.set_text("iiiimmmm")
374 bbox = text.get_window_extent()
375 origin = bbox.x0
376
377 assert text._char_index_at(origin - size_i) == 0 # left of first char
378 assert text._char_index_at(origin) == 0
379 assert text._char_index_at(origin + 0.499*size_i) == 0
380 assert text._char_index_at(origin + 0.501*size_i) == 1
381 assert text._char_index_at(origin + size_i*3) == 3
382 assert text._char_index_at(origin + size_i*4 + size_m*3) == 7
383 assert text._char_index_at(origin + size_i*4 + size_m*4) == 8
384 assert text._char_index_at(origin + size_i*4 + size_m*10) == 8
385
386
387@pytest.mark.parametrize('text', ['', 'O'], ids=['empty', 'non-empty'])

Callers

nothing calls this directly

Calls 5

figureMethod · 0.80
_char_index_atMethod · 0.80
textMethod · 0.45
set_textMethod · 0.45
get_window_extentMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…