1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
From 659829a63f423c495e6fbcc7a053235426234513 Mon Sep 17 00:00:00 2001
From: Dominik George <nik@naturalnet.de>
Date: Thu, 13 Oct 2016 13:40:10 +0200
Subject: =?UTF-8?q?From:=20Takeshi=20KOMIYA=20<i.tkomiya@gmail.com>=0ADate?=
=?UTF-8?q?:=20Fri,=205=20Feb=202016=2021:56:57=20+0900=0ASubject:=20[PATC?=
=?UTF-8?q?H]=20Use=20utility=20methods=20of=20testing.common.database=20>?=
=?UTF-8?q?=3D=201.1.0=0AOrigin:=20upstream,=20https://github.com/tk0miya/?=
=?UTF-8?q?testing.postgresql/commit/738c8eb19a4b064dd74ff851c379dd1cbf11b?=
=?UTF-8?q?c65.patch=0AApplied-Upstream:=20commit:738c8eb19a4b064dd74ff851?=
=?UTF-8?q?c379dd1cbf11bc65?=
---
setup.py | 2 +-
tests/test_postgresql.py | 41 ++++++++++++++---------------------------
2 files changed, 15 insertions(+), 28 deletions(-)
diff --git a/setup.py b/setup.py
index 08095cd..9e95298 100644
--- a/setup.py
+++ b/setup.py
@@ -18,7 +18,7 @@ classifiers = [
"Topic :: Software Development :: Testing",
]
-install_requires = ['testing.common.database', 'pg8000 >= 1.10']
+install_requires = ['testing.common.database >= 1.1.0', 'pg8000 >= 1.10']
if sys.version_info < (2, 7):
install_requires.append('unittest2')
diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py
index 29e2b7e..b3603a2 100644
--- a/tests/test_postgresql.py
+++ b/tests/test_postgresql.py
@@ -47,38 +47,31 @@ class TestPostgresql(unittest.TestCase):
conn.close()
finally:
# shutting down
- pid = pgsql.pid
- self.assertTrue(pid)
- os.kill(pid, 0) # process is alive
+ pid = pgsql.server_pid
+ self.assertTrue(pgsql.is_alive())
pgsql.stop()
sleep(1)
- self.assertIsNone(pgsql.pid)
+ self.assertFalse(pgsql.is_alive())
with self.assertRaises(OSError):
os.kill(pid, 0) # process is down
def test_stop(self):
# start postgresql server
pgsql = testing.postgresql.Postgresql()
- self.assertIsNotNone(pgsql.pid)
self.assertTrue(os.path.exists(pgsql.base_dir))
- pid = pgsql.pid
- os.kill(pid, 0) # process is alive
+ self.assertTrue(pgsql.is_alive())
# call stop()
pgsql.stop()
- self.assertIsNone(pgsql.pid)
self.assertFalse(os.path.exists(pgsql.base_dir))
- with self.assertRaises(OSError):
- os.kill(pid, 0) # process is down
+ self.assertFalse(pgsql.is_alive())
# call stop() again
pgsql.stop()
- self.assertIsNone(pgsql.pid)
self.assertFalse(os.path.exists(pgsql.base_dir))
- with self.assertRaises(OSError):
- os.kill(pid, 0) # process is down
+ self.assertFalse(pgsql.is_alive())
# delete postgresql object after stop()
del pgsql
@@ -98,20 +91,17 @@ class TestPostgresql(unittest.TestCase):
self.assertIsNotNone(conn)
conn.close()
- pid = pgsql.pid
- os.kill(pid, 0) # process is alive
+ self.assertTrue(pgsql.is_alive())
- self.assertIsNone(pgsql.pid)
- with self.assertRaises(OSError):
- os.kill(pid, 0) # process is down
+ self.assertFalse(pgsql.is_alive())
def test_multiple_postgresql(self):
pgsql1 = testing.postgresql.Postgresql()
pgsql2 = testing.postgresql.Postgresql()
- self.assertNotEqual(pgsql1.pid, pgsql2.pid)
+ self.assertNotEqual(pgsql1.server_pid, pgsql2.server_pid)
- os.kill(pgsql1.pid, 0) # process is alive
- os.kill(pgsql2.pid, 0) # process is alive
+ self.assertTrue(pgsql1.is_alive())
+ self.assertTrue(pgsql2.is_alive())
def test_postgresql_is_not_found(self):
try:
@@ -135,21 +125,18 @@ class TestPostgresql(unittest.TestCase):
else:
os.wait()
sleep(1)
- self.assertTrue(pgsql.pid)
- os.kill(pgsql.pid, 0) # process is alive (delete pgsql obj in child does not effect)
+ self.assertTrue(pgsql.is_alive()) # process is alive (delete pgsql obj in child does not effect)
def test_stop_on_child_process(self):
pgsql = testing.postgresql.Postgresql()
if os.fork() == 0:
pgsql.stop()
- self.assertTrue(pgsql.pid)
- os.kill(pgsql.pid, 0) # process is alive (calling stop() is ignored)
+ os.kill(pgsql.server_pid, 0) # process is alive (calling stop() is ignored)
os.kill(os.getpid(), signal.SIGTERM) # exit tests FORCELY
else:
os.wait()
sleep(1)
- self.assertTrue(pgsql.pid)
- os.kill(pgsql.pid, 0) # process is alive (calling stop() in child is ignored)
+ self.assertTrue(pgsql.is_alive()) # process is alive (calling stop() in child is ignored)
def test_copy_data_from(self):
try:
|