Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
b25f83e8
Commit
b25f83e8
authored
Nov 06, 2003
by
Chris McDonough
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved warnfilter to Zope.Startup (from zLOG package).
Added tests.
parent
335c08d2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
192 additions
and
0 deletions
+192
-0
lib/python/Zope/Startup/tests/test_warnfilter.py
lib/python/Zope/Startup/tests/test_warnfilter.py
+124
-0
lib/python/Zope/Startup/warnfilter.py
lib/python/Zope/Startup/warnfilter.py
+57
-0
lib/python/Zope/Startup/warnfilter.xml
lib/python/Zope/Startup/warnfilter.xml
+10
-0
lib/python/Zope/Startup/zopeschema.xml
lib/python/Zope/Startup/zopeschema.xml
+1
-0
No files found.
lib/python/Zope/Startup/tests/test_warnfilter.py
0 → 100644
View file @
b25f83e8
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Test that the warning filter works."""
import
os
import
sys
import
cStringIO
import
tempfile
import
unittest
import
warnings
import
ZConfig
import
Zope.Startup
from
Zope.Startup
import
datatypes
from
App.config
import
getConfiguration
TEMPNAME
=
tempfile
.
mktemp
()
TEMPPRODUCTS
=
os
.
path
.
join
(
TEMPNAME
,
"Products"
)
def
getSchema
():
startup
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
Zope
.
Startup
.
__file__
))
schemafile
=
os
.
path
.
join
(
startup
,
'zopeschema.xml'
)
return
ZConfig
.
loadSchema
(
schemafile
)
class
TestSchemaWarning
(
Warning
):
pass
class
TestWarnFilter
(
unittest
.
TestCase
):
schema
=
None
def
setUp
(
self
):
if
self
.
schema
is
None
:
TestWarnFilter
.
schema
=
getSchema
()
def
tearDown
(
self
):
warnings
.
resetwarnings
()
def
load_config_text
(
self
,
text
):
# We have to create a directory of our own since the existence
# of the directory is checked. This handles this in a
# platform-independent way.
schema
=
self
.
schema
sio
=
cStringIO
.
StringIO
(
text
.
replace
(
"<<INSTANCE_HOME>>"
,
TEMPNAME
))
os
.
mkdir
(
TEMPNAME
)
os
.
mkdir
(
TEMPPRODUCTS
)
try
:
conf
,
handler
=
ZConfig
.
loadConfigFile
(
schema
,
sio
)
finally
:
os
.
rmdir
(
TEMPPRODUCTS
)
os
.
rmdir
(
TEMPNAME
)
self
.
assertEqual
(
conf
.
instancehome
,
TEMPNAME
)
return
conf
,
handler
def
test_behavior
(
self
):
conf
,
handler
=
self
.
load_config_text
(
"""
\
instancehome <<INSTANCE_HOME>>
<warnfilter>
action error
message .*test.*
category test_warnfilter.TestSchemaWarning
module .*test_warnfilter.*
lineno 0
</warnfilter>
<warnfilter>
action error
message .*test.*
</warnfilter>
"""
)
self
.
assertRaises
(
TestSchemaWarning
,
self
.
_dowarning1
)
self
.
assertRaises
(
UserWarning
,
self
.
_dowarning2
)
def
_dowarning1
(
self
):
warnings
.
warn
(
'This is only a test.'
,
TestSchemaWarning
)
def
_dowarning2
(
self
):
warnings
.
warn
(
'This is another test.'
)
def
test_warn_action
(
self
):
self
.
assertRaises
(
ZConfig
.
ConfigurationSyntaxError
,
self
.
_badwarnaction
)
def
_badwarnaction
(
self
):
conf
,
handler
=
self
.
load_config_text
(
"""
\
instancehome <<INSTANCE_HOME>>
<warnfilter>
action wontwork
category Zope.Startup.tests.test_schema.TestSchemaWarning
</warnfilter>
"""
)
def
test_warn_category
(
self
):
self
.
assertRaises
(
ZConfig
.
ConfigurationSyntaxError
,
self
.
_badwarncategory
)
def
_badwarncategory
(
self
):
conf
,
handler
=
self
.
load_config_text
(
"""
\
instancehome <<INSTANCE_HOME>>
<warnfilter>
action error
category A.Module.That.Doesnt.Exist
</warnfilter>
"""
)
def
test_suite
():
return
unittest
.
makeSuite
(
TestWarnFilter
)
if
__name__
==
"__main__"
:
unittest
.
main
(
defaultTest
=
"test_suite"
)
lib/python/Zope/Startup/warnfilter.py
0 → 100644
View file @
b25f83e8
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Datatypes for warning filter component """
def
warn_category
(
category
):
import
re
,
types
if
not
category
:
return
Warning
if
re
.
match
(
"^[a-zA-Z0-9_]+$"
,
category
):
try
:
cat
=
eval
(
category
)
except
NameError
:
raise
ValueError
(
"unknown warning category: %s"
%
`category`
)
else
:
i
=
category
.
rfind
(
"."
)
module
=
category
[:
i
]
klass
=
category
[
i
+
1
:]
try
:
m
=
__import__
(
module
,
None
,
None
,
[
klass
])
except
ImportError
:
raise
ValueError
(
"invalid module name: %s"
%
`module`
)
try
:
cat
=
getattr
(
m
,
klass
)
except
AttributeError
:
raise
ValueError
(
"unknown warning category: %s"
%
`category`
)
if
(
not
isinstance
(
cat
,
types
.
ClassType
)
or
not
issubclass
(
cat
,
Warning
)):
raise
ValueError
(
"invalid warning category: %s"
%
`category`
)
return
cat
def
warn_action
(
val
):
OK
=
(
"error"
,
"ignore"
,
"always"
,
"default"
,
"module"
,
"once"
)
if
val
not
in
OK
:
raise
ValueError
,
"warning action %s not one of %s"
%
(
val
,
OK
)
return
val
def
warning_filter_handler
(
section
):
import
warnings
# add the warning filter
warnings
.
filterwarnings
(
section
.
action
,
section
.
message
,
section
.
category
,
section
.
module
,
section
.
lineno
,
1
)
return
section
lib/python/Zope/Startup/warnfilter.xml
0 → 100644
View file @
b25f83e8
<component
prefix=
"Zope.Startup.warnfilter"
>
<sectiontype
name=
"warnfilter"
datatype=
".warning_filter_handler"
>
<key
name=
"action"
datatype=
".warn_action"
default=
"default"
/>
<key
name=
"message"
default=
""
/>
<key
name=
"category"
datatype=
".warn_category"
default=
"Warning"
/>
<key
name=
"module"
default=
""
/>
<key
name=
"lineno"
datatype=
"integer"
default=
"0"
/>
</sectiontype>
</component>
lib/python/Zope/Startup/zopeschema.xml
View file @
b25f83e8
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
<import
package=
"ZODB"
/>
<import
package=
"ZODB"
/>
<import
package=
"ZServer"
/>
<import
package=
"ZServer"
/>
<import
package=
"tempstorage"
/>
<import
package=
"tempstorage"
/>
<import
package=
"Zope.Startup"
file=
"warnfilter.xml"
/>
<sectiontype
name=
"logger"
datatype=
".LoggerFactory"
>
<sectiontype
name=
"logger"
datatype=
".LoggerFactory"
>
<description>
<description>
...
...
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