Permalink
Browse files

Merge pull request #488 from dianaclarke/pserve-unit-tests

removing another # pragma: no cover
  • Loading branch information...
2 parents d90b437 + 8c2aaf8 commit c03eac42cf20e62d6e5beae9ead0af8f14427928 @mcdonc mcdonc committed Mar 15, 2012
Showing with 26 additions and 4 deletions.
  1. +3 −4 pyramid/scripts/pserve.py
  2. +23 −0 pyramid/tests/test_scripts/test_pserve.py
@@ -628,12 +628,11 @@ def live_pidfile(pidfile): # pragma: no cover
return pid
return None
-def read_pidfile(filename): # pragma: no cover
+def read_pidfile(filename):
if os.path.exists(filename):
try:
- f = open(filename)
- content = f.read()
- f.close()
+ with open(filename) as f:
+ content = f.read()
return int(content.strip())
except (ValueError, IOError):
return None
@@ -204,6 +204,29 @@ def test_parse_vars_bad(self):
inst = self._makeOne('development.ini')
self.assertRaises(ValueError, inst.parse_vars, vars)
+class Test_read_pidfile(unittest.TestCase):
+ def _callFUT(self, filename):
+ from pyramid.scripts.pserve import read_pidfile
+ return read_pidfile(filename)
+
+ def test_read_pidfile(self):
+ filename = tempfile.mktemp()
+ try:
+ with open(filename, 'w') as f:
+ f.write('12345')
+ result = self._callFUT(filename)
+ self.assertEqual(result, 12345)
+ finally:
+ os.remove(filename)
+
+ def test_read_pidfile_no_pid_file(self):
+ result = self._callFUT('some unknown path')
+ self.assertEqual(result, None)
+
+ def test_read_pidfile_not_a_number(self):
+ result = self._callFUT(__file__)
+ self.assertEqual(result, None)
+
class Test_main(unittest.TestCase):
def _callFUT(self, argv):
from pyramid.scripts.pserve import main

0 comments on commit c03eac4

Please sign in to comment.