Commit 12f7995a authored by Marius Gedminas's avatar Marius Gedminas

Fix a bunch of ResourceWarnings in iterator.test

parent 5472857b
...@@ -37,6 +37,8 @@ By default, we start at the beginning: ...@@ -37,6 +37,8 @@ By default, we start at the beginning:
>>> it.next().tid == tids[0] >>> it.next().tid == tids[0]
True True
>>> it.close()
The file iterator has an optimization to deal with large files. It The file iterator has an optimization to deal with large files. It
can serarch from either the front or the back of the file, depending can serarch from either the front or the back of the file, depending
on the starting transaction given. To see this, we'll turn on debug on the starting transaction given. To see this, we'll turn on debug
...@@ -55,30 +57,42 @@ seems best and set the next record to that: ...@@ -55,30 +57,42 @@ seems best and set the next record to that:
>>> it.next().tid == tids[0] >>> it.next().tid == tids[0]
True True
>>> it.close()
>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[1]) >>> it = ZODB.FileStorage.FileIterator('data.fs', tids[1])
Scan forward data.fs:4 looking for '\x03z\xbd\xd8\xd06\x9c\xcc' Scan forward data.fs:4 looking for '\x03z\xbd\xd8\xd06\x9c\xcc'
>>> it.next().tid == tids[1] >>> it.next().tid == tids[1]
True True
>>> it.close()
>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[30]) >>> it = ZODB.FileStorage.FileIterator('data.fs', tids[30])
Scan forward data.fs:4 looking for '\x03z\xbd\xd8\xdc\x96.\xcc' Scan forward data.fs:4 looking for '\x03z\xbd\xd8\xdc\x96.\xcc'
>>> it.next().tid == tids[30] >>> it.next().tid == tids[30]
True True
>>> it.close()
>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[70]) >>> it = ZODB.FileStorage.FileIterator('data.fs', tids[70])
Scan backward data.fs:117080 looking for '\x03z\xbd\xd8\xed\xa7>\xcc' Scan backward data.fs:117080 looking for '\x03z\xbd\xd8\xed\xa7>\xcc'
>>> it.next().tid == tids[70] >>> it.next().tid == tids[70]
True True
>>> it.close()
>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[-2]) >>> it = ZODB.FileStorage.FileIterator('data.fs', tids[-2])
Scan backward data.fs:117080 looking for '\x03z\xbd\xd8\xfa\x06\xd0\xcc' Scan backward data.fs:117080 looking for '\x03z\xbd\xd8\xfa\x06\xd0\xcc'
>>> it.next().tid == tids[-2] >>> it.next().tid == tids[-2]
True True
>>> it.close()
>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[-1]) >>> it = ZODB.FileStorage.FileIterator('data.fs', tids[-1])
>>> it.next().tid == tids[-1] >>> it.next().tid == tids[-1]
True True
>>> it.close()
We can also supply a file position. This can speed up finding the We can also supply a file position. This can speed up finding the
starting point, or just pick up where another iterator left off: starting point, or just pick up where another iterator left off:
...@@ -86,28 +100,40 @@ starting point, or just pick up where another iterator left off: ...@@ -86,28 +100,40 @@ starting point, or just pick up where another iterator left off:
>>> it.next().tid == tids[51] >>> it.next().tid == tids[51]
True True
>>> it.close()
>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[0], pos=4) >>> it = ZODB.FileStorage.FileIterator('data.fs', tids[0], pos=4)
>>> it.next().tid == tids[0] >>> it.next().tid == tids[0]
True True
>>> it.close()
>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[-1], pos=poss[-2]) >>> it = ZODB.FileStorage.FileIterator('data.fs', tids[-1], pos=poss[-2])
>>> it.next().tid == tids[-1] >>> it.next().tid == tids[-1]
True True
>>> it.close()
>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[50], pos=poss[50]) >>> it = ZODB.FileStorage.FileIterator('data.fs', tids[50], pos=poss[50])
Scan backward data.fs:35936 looking for '\x03z\xbd\xd8\xe5\x1e\xb6\xcc' Scan backward data.fs:35936 looking for '\x03z\xbd\xd8\xe5\x1e\xb6\xcc'
>>> it.next().tid == tids[50] >>> it.next().tid == tids[50]
True True
>>> it.close()
>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[49], pos=poss[50]) >>> it = ZODB.FileStorage.FileIterator('data.fs', tids[49], pos=poss[50])
Scan backward data.fs:35936 looking for '\x03z\xbd\xd8\xe4\xb1|\xcc' Scan backward data.fs:35936 looking for '\x03z\xbd\xd8\xe4\xb1|\xcc'
>>> it.next().tid == tids[49] >>> it.next().tid == tids[49]
True True
>>> it.close()
>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[51], pos=poss[50]) >>> it = ZODB.FileStorage.FileIterator('data.fs', tids[51], pos=poss[50])
>>> it.next().tid == tids[51] >>> it.next().tid == tids[51]
True True
>>> it.close()
>>> logging.getLogger().setLevel(old_log_level) >>> logging.getLogger().setLevel(old_log_level)
>>> logging.getLogger().removeHandler(handler) >>> logging.getLogger().removeHandler(handler)
...@@ -120,12 +146,16 @@ then the first transaction is returned. ...@@ -120,12 +146,16 @@ then the first transaction is returned.
>>> it.next().tid == tids[0] >>> it.next().tid == tids[0]
True True
>>> it.close()
If it is after the last transaction, then iteration be empty: If it is after the last transaction, then iteration be empty:
>>> it = ZODB.FileStorage.FileIterator('data.fs', p64(u64(tids[-1])+1)) >>> it = ZODB.FileStorage.FileIterator('data.fs', p64(u64(tids[-1])+1))
>>> list(it) >>> list(it)
[] []
>>> it.close()
Even if we write more transactions: Even if we write more transactions:
>>> it = ZODB.FileStorage.FileIterator('data.fs', p64(u64(tids[-1])+1)) >>> it = ZODB.FileStorage.FileIterator('data.fs', p64(u64(tids[-1])+1))
...@@ -135,8 +165,9 @@ Even if we write more transactions: ...@@ -135,8 +165,9 @@ Even if we write more transactions:
>>> list(it) >>> list(it)
[] []
>>> it.close()
.. Cleanup .. Cleanup
>>> time.time = time_time >>> time.time = time_time
>>> it.close()
>>> db.close() >>> db.close()
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