Commit 65ebbe7b authored by Kirill Smelkov's avatar Kirill Smelkov

analyze: test: Fix tidmin thinko in "empty range" test

Empty-range test added in b4824ad5 (analyze: fix ZeroDivisionErrors when
report is empty) intended to use 0xffffffffffffffff TID, but used just
'ffffffffffffffff' string instead. It was passing on py2 partly by luck,
but on py3 it fails because tidmin type is mismatched:

    _______________________________ test_zodbanalyze _______________________________

    tmpdir = local('/tmp/pytest-of-kirr/pytest-30/test_zodbanalyze0')
    capsys = <_pytest.capture.CaptureFixture object at 0x7f7bb3f9a4f0>

        def test_zodbanalyze(tmpdir, capsys):
            ...

            # empty range
            report(
    >           analyze(
                    tfs1,
                    use_dbm=False,
                    delta_fs=False,
                    tidmin="ffffffffffffffff",
                    tidmax=None,
                ),
                csv=False,
            )

    zodbtools/test/test_analyze.py:68:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    ../../venv/py3.venv/lib/python3.9/site-packages/decorator.py:232: in fun
        return caller(func, *(extras + args), **kw)
    ../../../tools/go/pygolang/golang/__init__.py:103: in _
        return f(*argv, **kw)
    zodbtools/zodbanalyze.py:181: in analyze
        fsi = fs.iterator(tidmin, tidmax)
    ../ZODB/src/ZODB/FileStorage/FileStorage.py:1381: in iterator
        return FileIterator(self._file_name, start, stop)
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    self = <ZODB.FileStorage.FileStorage.FileIterator object at 0x7f7bb348c6d0>
    filename = '/tmp/pytest-of-kirr/pytest-30/test_zodbanalyze0/1.fs'
    start = 'ffffffffffffffff', stop = None, pos = 4

        def __init__(self, filename, start=None, stop=None, pos=4):
            assert isinstance(filename, STRING_TYPES)
            file = open(filename, 'rb')
            self._file = file
            self._file_name = filename
            if file.read(4) != packed_version:
                raise FileStorageFormatError(file.name)
            file.seek(0, 2)
            self._file_size = file.tell()
            if (pos < 4) or pos > self._file_size:
                raise ValueError("Given position is greater than the file size",
                                 pos, self._file_size)
            self._pos = pos
    >       assert start is None or isinstance(start, bytes)
    E       AssertionError

    ../ZODB/src/ZODB/FileStorage/FileStorage.py:1816: AssertionError
    ------------------------------ Captured log call -------------------------------
    ERROR    ZODB.FileStorage:FileStorage.py:480 loading index
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xb7 in position 25: ordinal not in range(128)

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
      File "/home/kirr/src/wendelin/z/ZODB/src/ZODB/FileStorage/FileStorage.py", line 478, in _restore_index
        info = fsIndex.load(index_name)
      File "/home/kirr/src/wendelin/z/ZODB/src/ZODB/fsIndex.py", line 138, in load
        v = unpickler.load()
    SystemError: <built-in method read of _io.BufferedReader object at 0x7f7bb3df03b0> returned a result with an error set
    ERROR    ZODB.FileStorage:FileStorage.py:480 loading index
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xb7 in position 25: ordinal not in range(128)

    ...

-> Fix it by preparing tidmin in the test a 8-bytes binary properly.
parent 9861c136
......@@ -19,6 +19,7 @@
from zodbtools.zodbanalyze import analyze, report
from zodbtools.test.testutil import fs1_testdata_py23
from zodbtools.util import fromhex
import os.path
from golang import b
......@@ -69,7 +70,7 @@ __main__.Object,56,1880,54.366686%,33.571429,9,303,47,1577
tfs1,
use_dbm=False,
delta_fs=False,
tidmin="ffffffffffffffff",
tidmin=fromhex("ffffffffffffffff"),
tidmax=None,
),
csv=False,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment