From 02e0bb8b10356748a231eab46b331050d44126f9 Mon Sep 17 00:00:00 2001 From: Patricio Paez Date: Wed, 14 Mar 2012 18:59:53 -0700 Subject: Fixed SQL tutorial functional tests for Python 3 --- docs/tutorials/wiki2/src/tests/tutorial/tests.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/tutorials/wiki2/src/tests/tutorial/tests.py b/docs/tutorials/wiki2/src/tests/tutorial/tests.py index c7b7d884b..659862a09 100644 --- a/docs/tutorials/wiki2/src/tests/tutorial/tests.py +++ b/docs/tutorials/wiki2/src/tests/tutorial/tests.py @@ -190,7 +190,7 @@ class FunctionalTests(unittest.TestCase): def test_FrontPage(self): res = self.testapp.get('/FrontPage', status=200) - self.assertTrue('FrontPage' in res.body) + self.assertTrue(b'FrontPage' in res.body) def test_unexisting_page(self): self.testapp.get('/SomePage', status=404) @@ -201,48 +201,48 @@ class FunctionalTests(unittest.TestCase): def test_failed_log_in(self): res = self.testapp.get(self.viewer_wrong_login, status=200) - self.assertTrue('login' in res.body) + self.assertTrue(b'login' in res.body) def test_logout_link_present_when_logged_in(self): self.testapp.get(self.viewer_login, status=302) res = self.testapp.get('/FrontPage', status=200) - self.assertTrue('Logout' in res.body) + self.assertTrue(b'Logout' in res.body) def test_logout_link_not_present_after_logged_out(self): self.testapp.get(self.viewer_login, status=302) self.testapp.get('/FrontPage', status=200) res = self.testapp.get('/logout', status=302) - self.assertTrue('Logout' not in res.body) + self.assertTrue(b'Logout' not in res.body) def test_anonymous_user_cannot_edit(self): res = self.testapp.get('/FrontPage/edit_page', status=200) - self.assertTrue('Login' in res.body) + self.assertTrue(b'Login' in res.body) def test_anonymous_user_cannot_add(self): res = self.testapp.get('/add_page/NewPage', status=200) - self.assertTrue('Login' in res.body) + self.assertTrue(b'Login' in res.body) def test_viewer_user_cannot_edit(self): self.testapp.get(self.viewer_login, status=302) res = self.testapp.get('/FrontPage/edit_page', status=200) - self.assertTrue('Login' in res.body) + self.assertTrue(b'Login' in res.body) def test_viewer_user_cannot_add(self): self.testapp.get(self.viewer_login, status=302) res = self.testapp.get('/add_page/NewPage', status=200) - self.assertTrue('Login' in res.body) + self.assertTrue(b'Login' in res.body) def test_editors_member_user_can_edit(self): self.testapp.get(self.editor_login, status=302) res = self.testapp.get('/FrontPage/edit_page', status=200) - self.assertTrue('Editing' in res.body) + self.assertTrue(b'Editing' in res.body) def test_editors_member_user_can_add(self): self.testapp.get(self.editor_login, status=302) res = self.testapp.get('/add_page/NewPage', status=200) - self.assertTrue('Editing' in res.body) + self.assertTrue(b'Editing' in res.body) def test_editors_member_user_can_view(self): self.testapp.get(self.editor_login, status=302) res = self.testapp.get('/FrontPage', status=200) - self.assertTrue('FrontPage' in res.body) + self.assertTrue(b'FrontPage' in res.body) -- cgit v1.2.3 From 8c2aaf80c470511de08d2fa7b66f0f635e55eff7 Mon Sep 17 00:00:00 2001 From: Diana Clarke Date: Thu, 15 Mar 2012 00:24:46 -0400 Subject: removing another # pragma: no cover - test coverage still reports 100% should probably clean up the temp file --- pyramid/scripts/pserve.py | 7 +++---- pyramid/tests/test_scripts/test_pserve.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py index dcc095d1a..ea2a4ae09 100644 --- a/pyramid/scripts/pserve.py +++ b/pyramid/scripts/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 diff --git a/pyramid/tests/test_scripts/test_pserve.py b/pyramid/tests/test_scripts/test_pserve.py index 1b45a5d90..d7b252d92 100644 --- a/pyramid/tests/test_scripts/test_pserve.py +++ b/pyramid/tests/test_scripts/test_pserve.py @@ -204,6 +204,29 @@ class TestPServeCommand(unittest.TestCase): 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 -- cgit v1.2.3