[Zope-CVS] CVS: Packages/zpkgtools/zpkgtools/tests -
test_locationmap.py:1.2
Fred L. Drake, Jr.
fred at zope.com
Thu Mar 18 16:23:48 EST 2004
Update of /cvs-repository/Packages/zpkgtools/zpkgtools/tests
In directory cvs.zope.org:/tmp/cvs-serv6642
Modified Files:
test_locationmap.py
Log Message:
add a test that a warning is generated when a duplicate resource
definition is encountered in a map
=== Packages/zpkgtools/zpkgtools/tests/test_locationmap.py 1.1 => 1.2 ===
--- Packages/zpkgtools/zpkgtools/tests/test_locationmap.py:1.1 Tue Mar 9 10:20:37 2004
+++ Packages/zpkgtools/zpkgtools/tests/test_locationmap.py Thu Mar 18 16:23:48 2004
@@ -14,6 +14,7 @@
"""Tests for zpkgtools.cvsmap."""
import doctest
+import logging
import os.path
import unittest
@@ -103,6 +104,37 @@
self.assertEqual(e.lineno, 1)
else:
self.fail("expected MapLoadingError")
+
+ def test_duplicate_entry_generates_warning(self):
+ sio = StringIO("r1 cvs://cvs.example.org/cvsroot:foo\n"
+ "r1 cvs://cvs.example.org/cvsroot:foo\n")
+ map = self.collect_warnings(locationmap.load, sio)
+ self.assertEqual(len(map), 1)
+ self.assertEqual(len(self.warnings), 1)
+ r = self.warnings[0]
+ self.assertEqual(r.levelno, logging.WARNING)
+ self.assertEqual(r.name, "zpkgtools.locationmap")
+
+ def collect_warnings(self, callable, *args, **kw):
+ self.warnings = []
+ handler = CollectingHandler(self.warnings)
+ root_logger = logging.getLogger()
+ root_logger.addHandler(handler)
+ try:
+ return callable(*args, **kw)
+ finally:
+ root_logger.removeHandler(handler)
+
+
+class CollectingHandler(logging.StreamHandler):
+ """Log handler that simply collects emitted warning records."""
+
+ def __init__(self, list):
+ self.list = list
+ logging.StreamHandler.__init__(self)
+
+ def emit(self, record):
+ self.list.append(record)
class CvsWorkingDirectoryTestCase(CvsWorkingDirectoryBase):
More information about the Zope-CVS
mailing list