Commit e66451c0 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 a2c660a7
...@@ -18,7 +18,10 @@ ...@@ -18,7 +18,10 @@
# #
# See COPYING file for full licensing terms. # See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options. # 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 # 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 # 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): ...@@ -306,6 +309,7 @@ def _gen_testdb(outfs_path, zext):
# ---------------------------------------- # ----------------------------------------
from zodbtools.zodbdump import zodbdump from zodbtools.zodbdump import zodbdump
from zodbtools import zodbanalyze
from zodbtools.test.testutil import zext_supported from zodbtools.test.testutil import zext_supported
def main(): def main():
...@@ -321,10 +325,23 @@ def main(): ...@@ -321,10 +325,23 @@ def main():
for f in glob.glob(dbname + '.*'): for f in glob.glob(dbname + '.*'):
os.remove(f) os.remove(f)
gen_testdb("%s.fs" % dbname, zext=zext) gen_testdb("%s.fs" % dbname, zext=zext)
# prepare zdump.ok for generated database
stor = FileStorage("%s.fs" % dbname, read_only=True) stor = FileStorage("%s.fs" % dbname, read_only=True)
for pretty in ('raw', 'zpickledis'): for pretty in ('raw', 'zpickledis'):
with open("%s.zdump.%s.ok" % (dbname, pretty), "wb") as f: with open("%s.zdump.%s.ok" % (dbname, pretty), "wb") as f:
zodbdump(stor, None, None, pretty=pretty, out=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__': if __name__ == '__main__':
main() main()
...@@ -25,8 +25,9 @@ from golang import b ...@@ -25,8 +25,9 @@ from golang import b
def test_zodbanalyze(tmpdir, capsys): def test_zodbanalyze(tmpdir, capsys):
testdata = os.path.join(os.path.dirname(__file__), "testdata")
tfs1 = fs1_testdata_py23(tmpdir, 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): for use_dbm in (False, True):
report( report(
...@@ -55,13 +56,11 @@ def test_zodbanalyze(tmpdir, capsys): ...@@ -55,13 +56,11 @@ def test_zodbanalyze(tmpdir, capsys):
csv=True, csv=True,
) )
captured = capsys.readouterr() captured = capsys.readouterr()
assert (
"""Class Name,T.Count,T.Bytes,Pct,AvgSize,C.Count,C.Bytes,O.Count,O.Bytes with open('%s/1.zanalyze.csv.ok' % testdata, 'r') as f:
persistent.mapping.PersistentMapping,3,639,22.468354%,213.000000,1,213,2,426 zanalyze_csv_ok = f.read()
__main__.Object,65,2205,77.531646%,33.923077,9,310,56,1895
""" assert captured.out == zanalyze_csv_ok
== captured.out
)
assert captured.err == "" assert captured.err == ""
# empty range # 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