Tres Seaver <tsea...@agendaless.com> added the comment:
I plan to check in an alternate patch which uses 'tempfile.mkdtemp',
with appropriate cleanup of the tempdir. Can you confirm that it
works for you on Windows?
__________________________________
Repoze Bugs <b...@bugs.repoze.org>
<http://bugs.repoze.org/issue79>
__________________________________
Index: repoze/who/plugins/tests/test_authtkt.py
===================================================================
--- repoze/who/plugins/tests/test_authtkt.py (revision 4784)
+++ repoze/who/plugins/tests/test_authtkt.py (working copy)
@@ -1,7 +1,16 @@
import unittest
class TestAuthTktCookiePlugin(unittest.TestCase):
+ tempdir = None
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ if self.tempdir is not None:
+ import shutil
+ shutil.rmtree(self.tempdir)
+
def _getTargetClass(self):
from repoze.who.plugins.auth_tkt import AuthTktCookiePlugin
return AuthTktCookiePlugin
@@ -280,11 +289,15 @@
self.assertEqual(plugin.secure, False)
def test_factory_w_secretfile(self):
- from tempfile import NamedTemporaryFile
+ import os
+ from tempfile import mkdtemp
from repoze.who.plugins.auth_tkt import make_plugin
- ntf = NamedTemporaryFile()
- ntf.write('s33kr1t\n')
- ntf.flush()
- plugin = make_plugin(secretfile=ntf.name)
+ tempdir = self.tempdir = mkdtemp()
+ path = os.path.join(tempdir, 'who.secret')
+ secret = open(path, 'w')
+ secret.write('s33kr1t\n')
+ secret.flush()
+ secret.close()
+ plugin = make_plugin(secretfile=path)
self.assertEqual(plugin.secret, 's33kr1t')
Index: repoze/who/tests/test_config.py
===================================================================
--- repoze/who/tests/test_config.py (revision 4784)
+++ repoze/who/tests/test_config.py (working copy)
@@ -326,62 +326,68 @@
"""
class TestConfigMiddleware(unittest.TestCase):
- tempfile = None
+ tempdir = None
def setUp(self):
pass
def tearDown(self):
- if self.tempfile is not None:
- self.tempfile.close()
+ if self.tempdir is not None:
+ import shutil
+ shutil.rmtree(self.tempdir)
def _getFactory(self):
from repoze.who.config import make_middleware_with_config
return make_middleware_with_config
def _getTempfile(self, text):
+ import os
import tempfile
- tf = self.tempfile = tempfile.NamedTemporaryFile()
- tf.write(text)
- tf.flush()
- return tf
+ tempdir = self.tempdir = tempfile.mkdtemp()
+ path = os.path.join(tempdir, 'who.ini')
+ config = open(path, 'w')
+ config.write(text)
+ config.flush()
+ config.close()
+ return path
def test_sample_config(self):
+ import logging
+ from repoze.who.interfaces import IIdentifier
+ from repoze.who.interfaces import IAuthenticator
+ from repoze.who.interfaces import IChallenger
app = DummyApp()
factory = self._getFactory()
- tempfile = self._getTempfile(SAMPLE_CONFIG)
+ path = self._getTempfile(SAMPLE_CONFIG)
global_conf = {'here': '/'}
- middleware = factory(app, global_conf, config_file=tempfile.name,
+ middleware = factory(app, global_conf, config_file=path,
log_file='STDOUT', log_level='debug')
- from repoze.who.interfaces import IIdentifier
- from repoze.who.interfaces import IAuthenticator
- from repoze.who.interfaces import IChallenger
self.assertEqual(len(middleware.registry[IIdentifier]), 3)
self.assertEqual(len(middleware.registry[IAuthenticator]), 1)
self.assertEqual(len(middleware.registry[IChallenger]), 2)
self.failUnless(middleware.logger, middleware.logger)
- import logging
self.assertEqual(middleware.logger.getEffectiveLevel(), logging.DEBUG)
def test_sample_config_no_log_level(self):
+ import logging
app = DummyApp()
factory = self._getFactory()
- tempfile = self._getTempfile(SAMPLE_CONFIG)
+ path = self._getTempfile(SAMPLE_CONFIG)
global_conf = {'here': '/'}
- middleware = factory(app, global_conf, config_file=tempfile.name,
+ middleware = factory(app, global_conf, config_file=path,
log_file='STDOUT')
- import logging
self.assertEqual(middleware.logger.getEffectiveLevel(), logging.INFO)
def test_sample_config_w_log_file(self):
+ import logging
+ import os
app = DummyApp()
factory = self._getFactory()
- tempfile = self._getTempfile(SAMPLE_CONFIG)
- logfile = self._getTempfile('')
+ path = self._getTempfile(SAMPLE_CONFIG)
+ logfile = os.path.join(self.tempdir, 'who.log')
global_conf = {'here': '/'}
- middleware = factory(app, global_conf, config_file=tempfile.name,
- log_file=logfile.name)
- import logging
+ middleware = factory(app, global_conf, config_file=path,
+ log_file=logfile)
self.assertEqual(middleware.logger.getEffectiveLevel(), logging.INFO)
SAMPLE_CONFIG = """\
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev