Commit 8af56f5d authored by Kirill Smelkov's avatar Kirill Smelkov

zodbanalyze: tests: Verify CSV mode via golden output generated during gen_testdata

Instead of putting expected output into test code.

The reason for this change is that soon, with many kinds of generated
ZODB databases, analyze output will be different for each kind, and the
only practical way to make sure that analyze works correctly is to have
good expected output for each kind.

We already do this way for zodbdump. Start doing the same for
zodbanalyze as a preparatory step as well.
parent c8636628
......@@ -18,7 +18,10 @@
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
"""generate reference database and index for tests"""
"""generate reference database and index for tests
Golden zodbdump & zodbanalyze outputs are also generated besides database itself.
"""
# NOTE result of this script must be saved in version control and should not be
# generated at the time when tests are run. This is because even though we make
......@@ -306,6 +309,7 @@ def _gen_testdb(outfs_path, zext):
# ----------------------------------------
from zodbtools.zodbdump import zodbdump
from zodbtools import zodbanalyze
from zodbtools.test.testutil import zext_supported
def main():
......@@ -321,10 +325,23 @@ def main():
for f in glob.glob(dbname + '.*'):
os.remove(f)
gen_testdb("%s.fs" % dbname, zext=zext)
# prepare zdump.ok for generated database
stor = FileStorage("%s.fs" % dbname, read_only=True)
for pretty in ('raw', 'zpickledis'):
with open("%s.zdump.%s.ok" % (dbname, pretty), "wb") as f:
zodbdump(stor, None, None, pretty=pretty, out=f)
# prepare zanalyze.csv.ok
sys_stdout = sys.stdout
sys.stdout = open("%s.zanalyze.csv.ok" % dbname, "w")
zodbanalyze.report(
zodbanalyze.analyze("%s.fs" % dbname, use_dbm=False, delta_fs=False, tidmin=None, tidmax=None),
csv=True,
)
sys.stdout.close()
sys.stdout = sys_stdout
if __name__ == '__main__':
main()
......@@ -25,8 +25,9 @@ from golang import b
def test_zodbanalyze(tmpdir, capsys):
testdata = os.path.join(os.path.dirname(__file__), "testdata")
tfs1 = fs1_testdata_py23(tmpdir,
os.path.join(os.path.dirname(__file__), "testdata", "1.fs"))
os.path.join(testdata, "1.fs"))
for use_dbm in (False, True):
report(
......@@ -55,13 +56,11 @@ def test_zodbanalyze(tmpdir, capsys):
csv=True,
)
captured = capsys.readouterr()
assert (
"""Class Name,T.Count,T.Bytes,Pct,AvgSize,C.Count,C.Bytes,O.Count,O.Bytes
persistent.mapping.PersistentMapping,3,639,22.468354%,213.000000,1,213,2,426
__main__.Object,65,2205,77.531646%,33.923077,9,310,56,1895
"""
== captured.out
)
with open('%s/1.zanalyze.csv.ok' % testdata, 'r') as f:
zanalyze_csv_ok = f.read()
assert captured.out == zanalyze_csv_ok
assert captured.err == ""
# empty range
......
Class Name,T.Count,T.Bytes,Pct,AvgSize,C.Count,C.Bytes,O.Count,O.Bytes
persistent.mapping.PersistentMapping,3,639,22.523793%,213.000000,1,213,2,426
__main__.Object,65,2198,77.476207%,33.815385,9,317,56,1881
Class Name,T.Count,T.Bytes,Pct,AvgSize,C.Count,C.Bytes,O.Count,O.Bytes
persistent.mapping.PersistentMapping,3,639,22.523793%,213.000000,1,213,2,426
__main__.Object,65,2198,77.476207%,33.815385,9,317,56,1881
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