def test_stop_is_idempotent(self): self.dbms = pgtools.PostgresServer(port=UNUSED_PORT) self.dbms.initdb() self.dbms.start() self.dbms.stop() self.dbms.stop() self.dbms.stop() assert self.dbms.is_running() is False
def test_is_running_tries_bogus(self): self.dbms = pgtools.PostgresServer(port=UNUSED_PORT) self.dbms.initdb() with pytest.raises(ValueError): self.dbms.is_running(-1) with pytest.raises(ValueError): self.dbms.is_running(-10) with pytest.raises(ValueError): self.dbms.is_running(0)
def dbms(self, request): cls = request.cls cls.port = UNUSED_PORT cls.dbms = pgtools.PostgresServer(port=cls.port) cls.dbms.initdb() cls.dbms.start() yield cls.dbms.destroy() del cls.dbms
def test_is_running(self): self.dbms = pgtools.PostgresServer(port=UNUSED_PORT) assert self.dbms.is_running() is False self.dbms.initdb() assert self.dbms.is_running() is False self.dbms.start() assert self.dbms.is_running() is True self.dbms.stop() assert self.dbms.is_running() is False
def test_pid_returns_None_when_not_running(self): self.dbms = pgtools.PostgresServer(port=UNUSED_PORT) assert self.dbms.pid is None self.dbms.initdb() assert self.dbms.pid is None self.dbms.start() assert self.dbms.pid is not None os.kill(self.dbms.pid, 0) self.dbms.stop() assert self.dbms.pid is None
def test_pid(self): self.dbms = pgtools.PostgresServer(port=UNUSED_PORT) self.dbms.initdb() self.dbms.start() pid = self.dbms.pid # Weak test -- just check to see whether such a process exists. os.kill(pid, 0) self.dbms.stop() with pytest.raises(OSError): os.kill(pid, 0)
def test_destroy_handles_deleted_directory(self): self.dbms = pgtools.PostgresServer(host='localhost', port=UNUSED_PORT) self.dbms.initdb() # Reach under the covers and pre-emptively delete the directory. # (But first, some checking to prevent hideously # self-destructive acts.) assert self.dbms.base_pathname is not None assert self.dbms.base_pathname != '' assert self.dbms.base_pathname != '.' shutil.rmtree(self.dbms.base_pathname) self.dbms.destroy()
def test_start_raises_NotInitializedError_when_uninitialized(self): self.dbms = pgtools.PostgresServer(port=UNUSED_PORT) with pytest.raises(pgtools.NotInitializedError): self.dbms.start()
def test_start_ok(self): self.dbms = pgtools.PostgresServer(port=UNUSED_PORT) self.dbms.initdb() self.dbms.start() assert self.dbms.is_running() is True
def test_start_port_value_error(self): self.dbms = pgtools.PostgresServer(port='BOGUS') self.dbms.initdb() errors = CalledProcessError, RuntimeError with pytest.raises(errors): self.dbms.start()
def test_start_port_out_of_range(self): self.dbms = pgtools.PostgresServer(port=99999999) self.dbms.initdb() errors = CalledProcessError, RuntimeError with pytest.raises(errors): self.dbms.start()
def test_start_host_bogus(self): # Hostnames aren't checked until the postgres server starts up self.dbms = pgtools.PostgresServer(host='no.such.host.exists') self.dbms.initdb() with pytest.raises(RuntimeError): self.dbms.start()
def test___init__ok(self): self.dbms = pgtools.PostgresServer(host='localhost', port=UNUSED_PORT)
def test_initdb_ok(self): self.dbms = pgtools.PostgresServer(port=UNUSED_PORT) self.dbms.initdb()
def test_initdb_base_pathname_bogus(self): self.dbms = pgtools.PostgresServer(port=UNUSED_PORT, base_pathname='/n&^fX:d#f9') with pytest.raises((OSError, IOError)): self.dbms.initdb()
def test_destroy_is_idempotent(self): self.dbms = pgtools.PostgresServer(host='localhost', port=UNUSED_PORT) self.dbms.destroy() self.dbms.destroy() self.dbms.destroy()
def test___str__(self): self.dbms = pgtools.PostgresServer(host='localhost', port=UNUSED_PORT) assert str(self.dbms) == ( 'PostgreSQL server at %s:%s (with storage at %s)' % (self.dbms.host, self.dbms.port, self.dbms.base_pathname))
def test___repr__(self): self.dbms = pgtools.PostgresServer(host='localhost', port=UNUSED_PORT) assert repr(self.dbms) == ( 'PostgresServer(host=localhost, port=%s, ' 'base_pathname=%s, superuser=%s)' % (self.dbms.port, self.dbms.base_pathname, self.dbms.superuser))