Пример #1
0
def test_modified_file_detect_modifications_in_preserved_sections(tmp_pth):
    txt = "lorem ipsum\n" * 10
    hv = compute_hash(txt)

    with open(tmp_pth, 'w') as f:
        f.write("{# pkglts, toto\n")
        f.write(txt)
        f.write("\n#}\n")

    assert not modified_file_hash(tmp_pth, {tmp_pth: dict(toto=hv)})

    with open(tmp_pth, 'w') as f:
        f.write("{# pkglts, toto\n")
        f.write(txt * 2)
        f.write("\n#}\n")

    assert modified_file_hash(tmp_pth, {tmp_pth: dict(toto=hv)})
Пример #2
0
def test_modified_file_detect_modifications_in_preserved_sections():
    txt = "lorem ipsum\n" * 10
    hv = compute_hash(txt)

    with open(ex_file, 'w') as f:
        f.write("{# pkglts, toto\n")
        f.write(txt)
        f.write("\n#}\n")

    assert not modified_file_hash(ex_file, {ex_file: dict(toto=hv)})

    with open(ex_file, 'w') as f:
        f.write("{# pkglts, toto\n")
        f.write(txt * 2)
        f.write("\n#}\n")

    assert modified_file_hash(ex_file, {ex_file: dict(toto=hv)})
Пример #3
0
def test_modified_file_if_not_same_preserved_sections(tmp_pth):
    txt = "lorem ipsum\n" * 10

    with open(tmp_pth, 'w') as f:
        f.write("{# pkglts, toto\n")
        f.write(txt)
        f.write("#}\n")

    assert modified_file_hash(tmp_pth, {tmp_pth: dict(titi="azerty")})
Пример #4
0
def test_modified_file_if_not_same_preserved_sections():
    txt = "lorem ipsum\n" * 10

    with open(ex_file, 'w') as f:
        f.write("{# pkglts, toto\n")
        f.write(txt)
        f.write("#}\n")

    assert modified_file_hash(ex_file, {ex_file: dict(titi="azerty")})
Пример #5
0
def test_modified_file_detect_modifications_only_in_preserved_sections(tmp_pth):
    with open(tmp_pth, 'w') as f:
        f.write("lorem ipsum\n" * 10)

    assert not modified_file_hash(tmp_pth, {tmp_pth: []})
Пример #6
0
def test_modified_file_raise_error_if_file_not_in_hashmap(tmp_pth):
    with open(tmp_pth, 'w') as f:
        f.write("lorem ipsum\n" * 10)

    with pytest.raises(IOError):
        modified_file_hash(tmp_pth, {})
Пример #7
0
def test_modified_file_detect_modifications_only_in_preserved_sections():
    with open(ex_file, 'w') as f:
        f.write("lorem ipsum\n" * 10)

    assert not modified_file_hash(ex_file, {ex_file: []})
Пример #8
0
def test_modified_file_raise_error_if_file_not_in_hashmap():
    with open(ex_file, 'w') as f:
        f.write("lorem ipsum\n" * 10)

    assert_raises(IOError, lambda: modified_file_hash(ex_file, {}))