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
nexedi
ZODB
Commits
e114fa06
Commit
e114fa06
authored
Oct 08, 2001
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some minimal tests
parent
ad2e08df
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
0 deletions
+119
-0
src/zLOG/tests/__init__.py
src/zLOG/tests/__init__.py
+1
-0
src/zLOG/tests/testzLog.py
src/zLOG/tests/testzLog.py
+118
-0
No files found.
src/zLOG/tests/__init__.py
0 → 100644
View file @
e114fa06
# nothing to see here
src/zLOG/tests/testzLog.py
0 → 100644
View file @
e114fa06
import
os
import
sys
import
tempfile
import
unittest
import
zLOG
severity_string
=
{
-
300
:
'TRACE'
,
-
200
:
'DEBUG'
,
-
100
:
'BLATHER'
,
0
:
'INFO'
,
100
:
'PROBLEM'
,
200
:
'ERROR'
,
300
:
'PANIC'
,
}
class
StupidLogTest
(
unittest
.
TestCase
):
"""Test zLOG with the default implementation.
The default implementation uses the environment variables
STUPID_LOG_FILE and STUPID_LOG_SEVERITY. I am not making this
up.
"""
def
setUp
(
self
):
self
.
path
=
tempfile
.
mktemp
()
self
.
_severity
=
0
def
tearDown
(
self
):
try
:
os
.
remove
(
self
.
path
)
except
os
.
error
:
pass
if
os
.
environ
.
has_key
(
'STUPID_LOG_FILE'
):
del
os
.
environ
[
'STUPID_LOG_FILE'
]
if
os
.
environ
.
has_key
(
'STUPID_LOG_SEVERITY'
):
del
os
.
environ
[
'STUPID_LOG_SEVERITY'
]
def
setLog
(
self
,
severity
=
0
):
os
.
environ
[
'STUPID_LOG_FILE'
]
=
self
.
path
if
severity
:
os
.
environ
[
'STUPID_LOG_SEVERITY'
]
=
str
(
severity
)
self
.
_severity
=
severity
zLOG
.
MinimalLogger
.
log_write
.
reinitialize
()
def
verifyEntry
(
self
,
f
,
time
=
None
,
subsys
=
None
,
severity
=
None
,
summary
=
None
,
detail
=
None
,
error
=
None
):
# skip to the beginning of next entry
line
=
f
.
readline
()
while
line
!=
"------
\
n
"
:
line
=
file
.
readline
()
line
=
f
.
readline
().
strip
()
_time
,
rest
=
line
.
split
(
" "
,
1
)
if
time
is
not
None
:
self
.
assertEqual
(
_time
,
time
)
if
subsys
is
not
None
:
self
.
assert_
(
rest
.
find
(
subsys
)
!=
-
1
,
"subsystem mismatch"
)
if
severity
is
not
None
and
severity
>=
self
.
_severity
:
s
=
severity_string
[
severity
]
self
.
assert_
(
rest
.
find
(
s
)
!=
-
1
,
"severity mismatch"
)
if
summary
is
not
None
:
self
.
assert_
(
rest
.
find
(
summary
)
!=
-
1
,
"summary mismatch"
)
if
detail
is
not
None
:
line
=
f
.
readline
()
self
.
assert_
(
line
.
find
(
detail
)
!=
-
1
,
"missing detail"
)
if
error
is
not
None
:
line
=
f
.
readline
()
self
.
assert_
(
line
.
startswith
(
'Traceback'
),
"missing traceback"
)
last
=
"%s: %s
\
n
"
%
(
error
[
0
],
error
[
1
])
if
last
.
startswith
(
"exceptions."
):
last
=
last
[
len
(
"exceptions."
):]
while
1
:
line
=
f
.
readline
()
if
not
line
:
self
.
fail
(
"couldn't find end of traceback"
)
if
line
==
"------
\
n
"
:
self
.
fail
(
"couldn't find end of traceback"
)
if
line
==
last
:
break
def
checkBasics
(
self
):
self
.
setLog
()
zLOG
.
LOG
(
"basic"
,
zLOG
.
INFO
,
"summary"
)
f
=
open
(
self
.
path
,
'rb'
)
self
.
verifyEntry
(
f
,
subsys
=
"basic"
,
summary
=
"summary"
)
def
checkDetail
(
self
):
self
.
setLog
()
zLOG
.
LOG
(
"basic"
,
zLOG
.
INFO
,
"xxx"
,
"this is a detail"
)
f
=
open
(
self
.
path
,
'rb'
)
self
.
verifyEntry
(
f
,
subsys
=
"basic"
,
detail
=
"detail"
)
def
checkError
(
self
):
self
.
setLog
()
try
:
1
/
0
except
ZeroDivisionError
,
err
:
err
=
sys
.
exc_info
()
zLOG
.
LOG
(
"basic"
,
zLOG
.
INFO
,
"summary"
)
zLOG
.
LOG
(
"basic"
,
zLOG
.
ERROR
,
"raised exception"
,
error
=
err
)
f
=
open
(
self
.
path
,
'rb'
)
self
.
verifyEntry
(
f
,
subsys
=
"basic"
,
summary
=
"summary"
)
self
.
verifyEntry
(
f
,
subsys
=
"basic"
,
severity
=
zLOG
.
ERROR
,
error
=
err
)
def
test_suite
():
return
unittest
.
makeSuite
(
StupidLogTest
,
'check'
)
if
__name__
==
"__main__"
:
loader
=
unittest
.
TestLoader
()
loader
.
testMethodPrefix
=
"check"
unittest
.
main
(
testLoader
=
loader
)
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