summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-10-08 13:44:08 -0400
committerChris McDonough <chrism@plope.com>2011-10-08 13:44:08 -0400
commit04a0cbb3ef5a16f5a032ea5de72f5ddaf63ada91 (patch)
treed09da24db281a366e5d623dec2932f360203676a
parent339208eb2ccefde01535142e897bd31e2ff0c510 (diff)
downloadpyramid-04a0cbb3ef5a16f5a032ea5de72f5ddaf63ada91.tar.gz
pyramid-04a0cbb3ef5a16f5a032ea5de72f5ddaf63ada91.tar.bz2
pyramid-04a0cbb3ef5a16f5a032ea5de72f5ddaf63ada91.zip
more lameass tests
-rw-r--r--pyramid/scripts/pserve.py10
-rw-r--r--pyramid/tests/test_scripts/test_pserve.py70
2 files changed, 75 insertions, 5 deletions
diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py
index 157b0f869..fdadf5175 100644
--- a/pyramid/scripts/pserve.py
+++ b/pyramid/scripts/pserve.py
@@ -709,7 +709,7 @@ class _methodwrapper(object):
"classinstancemethod")
return self.func(*((self.obj, self.type) + args), **kw)
-class Monitor(object):
+class Monitor(object): # pragma: no cover
"""
A file monitor and server restarter.
@@ -768,14 +768,14 @@ class Monitor(object):
# flush open files, etc. In otherwords, it is rude.
os._exit(3)
- def periodic_reload(self): # pragma: no cover
+ def periodic_reload(self):
while True:
if not self.check_reload():
self._exit()
break
time.sleep(self.poll_interval)
- def check_reload(self): # pragma: no cover
+ def check_reload(self):
filenames = list(self.extra_files)
for file_callback in self.file_callbacks:
try:
@@ -809,7 +809,7 @@ class Monitor(object):
return False
return True
- def watch_file(self, cls, filename): # pragma: no cover
+ def watch_file(self, cls, filename):
"""Watch the named file for changes"""
filename = os.path.abspath(filename)
if self is None:
@@ -821,7 +821,7 @@ class Monitor(object):
watch_file = classinstancemethod(watch_file)
- def add_file_callback(self, cls, callback): # pragma: no cover
+ def add_file_callback(self, cls, callback):
"""Add a callback -- a function that takes no parameters -- that will
return a list of filenames to watch for changes."""
if self is None:
diff --git a/pyramid/tests/test_scripts/test_pserve.py b/pyramid/tests/test_scripts/test_pserve.py
index d23c81f10..1f6175bb9 100644
--- a/pyramid/tests/test_scripts/test_pserve.py
+++ b/pyramid/tests/test_scripts/test_pserve.py
@@ -74,3 +74,73 @@ class Test_main(unittest.TestCase):
result = self._callFUT(['pserve'])
self.assertEqual(result, None)
+class TestLazyWriter(unittest.TestCase):
+ def _makeOne(self, filename, mode='w'):
+ from pyramid.scripts.pserve import LazyWriter
+ return LazyWriter(filename, mode)
+
+ def test_open(self):
+ import tempfile
+ filename = tempfile.mktemp()
+ try:
+ inst = self._makeOne(filename)
+ fp = inst.open()
+ self.assertEqual(fp.name, filename)
+ finally:
+ os.remove(filename)
+
+ def test_write(self):
+ import tempfile
+ filename = tempfile.mktemp()
+ try:
+ inst = self._makeOne(filename)
+ inst.write('hello')
+ finally:
+ with open(filename) as f:
+ data = f.read()
+ self.assertEqual(data, 'hello')
+ os.remove(filename)
+
+ def test_writeline(self):
+ import tempfile
+ filename = tempfile.mktemp()
+ try:
+ inst = self._makeOne(filename)
+ inst.writelines('hello')
+ finally:
+ with open(filename) as f:
+ data = f.read()
+ self.assertEqual(data, 'hello')
+ os.remove(filename)
+
+ def test_flush(self):
+ import tempfile
+ filename = tempfile.mktemp()
+ try:
+ inst = self._makeOne(filename)
+ inst.flush()
+ fp = inst.fileobj
+ self.assertEqual(fp.name, filename)
+ finally:
+ os.remove(filename)
+
+class Test__methodwrapper(unittest.TestCase):
+ def _makeOne(self, func, obj, type):
+ from pyramid.scripts.pserve import _methodwrapper
+ return _methodwrapper(func, obj, type)
+
+ def test___call__succeed(self):
+ def foo(self, cls, a=1): return 1
+ class Bar(object): pass
+ wrapper = self._makeOne(foo, Bar, None)
+ result = wrapper(a=1)
+ self.assertEqual(result, 1)
+
+ def test___call__fail(self):
+ def foo(self, cls, a=1): return 1
+ class Bar(object): pass
+ wrapper = self._makeOne(foo, Bar, None)
+ self.assertRaises(AssertionError, wrapper, cls=1)
+
+
+