Skip to content

test_str

Functions:

long_hello_world

long_hello_world()
Source code in tests/test_str.py
6
7
8
@pytest.fixture
def long_hello_world():
    return "hello world\nanother hello world\nyet again hello world"

test_replace_text_inject

test_replace_text_inject(long_hello_world)
Source code in tests/test_str.py
11
12
13
14
15
16
17
18
19
20
def test_replace_text_inject(long_hello_world):
    assert replace_text("", [(0, 0, "test")]) == "test"
    assert replace_text("hello world", [(11, 11, "!")]) == "hello world!"
    assert (
        replace_text(
            long_hello_world,
            [(0, 0, "!"), (12, 12, "oops! ")],
        )
        == "!hello world\noops! another hello world\nyet again hello world"
    )

test_replace_text_modify

test_replace_text_modify(long_hello_world)
Source code in tests/test_str.py
29
30
31
32
33
34
35
36
37
def test_replace_text_modify(long_hello_world):
    assert replace_text("hello world", [(6, 11, "everybody")]) == "hello everybody"
    assert (
        replace_text(
            long_hello_world,
            [(0, 11, "simple"), (12, 31, "very simple"), (32, 53, "very very simple")],
        )
        == "simple\nvery simple\nvery very simple"
    )

test_replace_text_remove

test_replace_text_remove()
Source code in tests/test_str.py
23
24
25
26
def test_replace_text_remove():
    assert replace_text("", [(0, 0, "")]) == ""
    assert replace_text("hello world", [(5, 11, "")]) == "hello"
    assert replace_text("hello world", [(0, 11, "")]) == ""

test_replace_text_replacements_sort

test_replace_text_replacements_sort(long_hello_world)
Source code in tests/test_str.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def test_replace_text_replacements_sort(long_hello_world):
    assert (
        replace_text(
            long_hello_world,
            [(12, 12, "oops! "), (0, 0, "!")],
            sort_replacements=True,
        )
        == "!hello world\noops! another hello world\nyet again hello world"
    )
    with pytest.raises(ValueError):
        replace_text(
            long_hello_world,
            [(12, 12, "oops! "), (0, 0, "!")],
            sort_replacements=False,
        )