RKrahl / archive-tools

Tools for managing archives
Apache License 2.0
1 stars 2 forks source link

Spurious error from test test_03_cli_error.py #24

Closed RKrahl closed 5 years ago

RKrahl commented 5 years ago

The test test_03_cli_error.py may occasionally yield spurious errors:

============================= test session starts ==============================
platform linux -- Python 3.4.6, pytest-3.3.2, py-1.5.2, pluggy-0.6.0
rootdir: /home/rolf/Progs/archive-tools/tests, inifile: pytest.ini
plugins: dependency-0.3.2
collected 115 items                                                            

test_01_create.py ................................                       [ 27%]
test_02_create_errors.py .......                                         [ 33%]
test_02_create_misc.py ...                                               [ 36%]
test_02_verify_errors.py ........                                        [ 43%]
test_03_cli.py .........................................                 [ 79%]
test_03_cli_check.py ............                                        [ 89%]
test_03_cli_error.py ...........F                                        [100%]

=================================== FAILURES ===================================
_______________________ test_cli_integrity_missing_file ________________________

test_dir = PosixPath('/tmp/archive-tools-test-rxz4gr1c')
archive_name = 'archive-test_cli_integrity_missing_file.tar'
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f707140d160>

    def test_cli_integrity_missing_file(test_dir, archive_name, monkeypatch):
        monkeypatch.chdir(str(test_dir))
        base = Path("base")
        missing = base / "data" / "not-present"
        with missing.open("wt") as f:
            f.write("Hello!")
        manifest = Manifest(paths=[base])
        with open("manifest.yaml", "wb") as f:
            manifest.write(f)
        missing.unlink()
        with tarfile.open(archive_name, "w") as tarf:
            with open("manifest.yaml", "rb") as f:
                manifest_info = tarf.gettarinfo(arcname="base/.manifest.yaml",
                                                fileobj=f)
                manifest_info.mode = stat.S_IFREG | 0o444
                tarf.addfile(manifest_info, f)
            tarf.add("base")
        with TemporaryFile(mode="w+t", dir=str(test_dir)) as f:
            args = ["verify", archive_name]
            with pytest.raises(subprocess.CalledProcessError) as exc_info:
                callscript("archive-tool.py", args, stderr=f)
            assert exc_info.value.returncode == 3
            f.seek(0)
            line = f.readline()
>           assert "%s:%s: missing" % (archive_name, missing) in line
E           AssertionError: assert ('%s:%s: missing' % ('archive-test_cli_integrity_missing_file.tar', PosixPath('base/data/not-present'))) in 'archive-tool.py verify: error: archive-test_cli_integrity_missing_file.tar:base/data: wrong modification time\n'

/home/rolf/Progs/archive-tools/tests/test_03_cli_error.py:206: AssertionError
----------------------------- Captured stdout call -----------------------------

> /usr/bin/python3 /home/rolf/Progs/archive-tools/build/scripts-3.4/archive-tool.py verify archive-test_cli_integrity_missing_file.tar
==================== 1 failed, 114 passed in 10.50 seconds =====================

The reason is obvious: unlinking the file touches the modification time of the parent directory so that it doesn't match the metadata recorded in the manifest.