Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZODB
Commits
6ba5f606
Commit
6ba5f606
authored
Oct 05, 2021
by
dieter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add `fsdump/fsstats` test
parent
403f9869
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
0 deletions
+92
-0
src/ZODB/scripts/fsstats.py
src/ZODB/scripts/fsstats.py
+2
-0
src/ZODB/scripts/tests/test_fsdump_fsstats.py
src/ZODB/scripts/tests/test_fsdump_fsstats.py
+62
-0
src/ZODB/tests/util.py
src/ZODB/tests/util.py
+28
-0
No files found.
src/ZODB/scripts/fsstats.py
View file @
6ba5f606
...
...
@@ -181,6 +181,8 @@ def main(path=None):
objects = 0
txn_bytes.add(size)
if objects:
txn_objects.add(objects)
f.close()
print("
Summary
:
%
d
txns
,
%
d
objects
,
%
d
revisions
" % (
...
...
src/ZODB/scripts/tests/test_fsdump_fsstats.py
0 → 100644
View file @
6ba5f606
##############################################################################
#
# Copyright (c) 2021 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from
ZODB
import
DB
from
ZODB.scripts.fsstats
import
rx_data
from
ZODB.scripts.fsstats
import
rx_txn
from
ZODB.tests.util
import
TestCase
from
ZODB.tests.util
import
run_module_as_script
class
FsdumpFsstatsTests
(
TestCase
):
def
setUp
(
self
):
super
(
FsdumpFsstatsTests
,
self
).
setUp
()
# create (empty) storage ``data.fs``
DB
(
"data.fs"
).
close
()
def
test_fsdump
(
self
):
run_module_as_script
(
"ZODB.FileStorage.fsdump"
,
[
"data.fs"
])
# verify that ``fsstats`` will understand the output
with
open
(
"stdout"
)
as
f
:
tno
=
obno
=
0
for
li
in
f
:
if
li
.
startswith
(
" data"
):
m
=
rx_data
.
search
(
li
)
if
m
is
None
:
continue
oid
,
size
,
klass
=
m
.
groups
()
int
(
size
)
obno
+=
1
elif
li
.
startswith
(
"Trans"
):
m
=
rx_txn
.
search
(
li
)
if
not
m
:
continue
tid
,
size
=
m
.
groups
()
size
=
int
(
size
)
tno
+=
1
self
.
assertEqual
(
tno
,
1
)
self
.
assertEqual
(
obno
,
1
)
def
test_fsstats
(
self
):
# The ``fsstats`` output is complex
# currently, we just check the first (summary) line
run_module_as_script
(
"ZODB.FileStorage.fsdump"
,
[
"data.fs"
],
"data.dmp"
)
run_module_as_script
(
"ZODB.scripts.fsstats"
,
[
"data.dmp"
])
with
open
(
"stdout"
)
as
f
:
self
.
assertEqual
(
f
.
readline
().
strip
(),
"Summary: 1 txns, 1 objects, 1 revisions"
)
src/ZODB/tests/util.py
View file @
6ba5f606
...
...
@@ -16,9 +16,12 @@
from
ZODB.MappingStorage
import
DB
import
atexit
import
doctest
import
os
import
pdb
import
persistent
import
re
import
runpy
import
sys
import
tempfile
import
time
...
...
@@ -377,3 +380,28 @@ def with_high_concurrency(f):
restore
()
return
_
def
run_module_as_script
(
mod
,
args
,
stdout
=
"stdout"
,
stderr
=
"stderr"
):
"""run module *mod* as script with arguments *arg*.
stdout and stderr are redirected to files given by the
correcponding parameters.
The function is usually called in a ``setUp/tearDown`` frame
which will remove the created files.
"""
sargv
,
sout
,
serr
=
sys
.
argv
,
sys
.
stdout
,
sys
.
stderr
s_set_trace
=
pdb
.
set_trace
try
:
sys
.
argv
=
[
sargv
[
0
]]
+
args
sys
.
stdout
=
open
(
stdout
,
"w"
)
sys
.
stderr
=
open
(
stderr
,
"w"
)
# to allow debugging
pdb
.
set_trace
=
doctest
.
_OutputRedirectingPdb
(
sout
)
runpy
.
run_module
(
mod
,
run_name
=
"__main__"
,
alter_sys
=
True
)
finally
:
sys
.
stdout
.
close
()
sys
.
stderr
.
close
()
pdb
.
set_trace
=
s_set_trace
sys
.
argv
,
sys
.
stdout
,
sys
.
stderr
=
sargv
,
sout
,
serr
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment