def setUp(cls): cls.pg_ctl_exe = pgtest.which('pg_ctl') cls.temp_dir = tempfile.mkdtemp() cls.curr_dir = os.path.dirname(__file__) cls.data_dir = os.path.join(cls.temp_dir, 'data') cmd = ('"{pg_ctl}" initdb -D "{cluster}" -o "-U postgres -A trust"' ).format(pg_ctl=cls.pg_ctl_exe, cluster=cls.data_dir) subprocess.check_output(cmd, shell=True)
def test_copy_data(self): pg_ctl_exe = pgtest.which('pg_ctl') temp_dir = tempfile.mkdtemp() data_dir = os.path.join(temp_dir, 'data') cmd = ('"{pg_ctl}" initdb -D "{cluster}" -o "-U postgres -A trust"' ).format(pg_ctl=pg_ctl_exe, cluster=data_dir) subprocess.check_output(cmd, shell=True) with pgtest.PGTest(copy_cluster=data_dir) as pg: self.assertTrue(pgtest.is_server_running(pg.cluster)) shutil.rmtree(temp_dir, ignore_errors=True)
def test_pgtest_argument(self): """ Create a temporary profile, passing the pgtest argument. """ from pgtest.pgtest import which # this should fail pgtest = {'pg_ctl': 'notapath'} with self.assertRaises(AssertionError): self.test_manager.use_temporary_profile(backend=self.backend, pgtest=pgtest) # pg_ctl is what PGTest also looks for (although it might be more clever) pgtest = {'pg_ctl': which('pg_ctl')} self.test_manager.use_temporary_profile(backend=self.backend, pgtest=pgtest)
# -*- coding: utf-8 -*- """Test compatibility with pgtest. """ from pgtest.pgtest import PGTest, which import pytest from pgsu import PGSU, PostgresConnectionMode try: PG_CTL = which('pg_ctl') except FileNotFoundError: PG_CTL = None @pytest.mark.skipif(not PG_CTL, reason='pg_ctl not found in PATH') def test_pgtest_compatibility(): """Test using a temporary postgres cluster set up via PGTest. """ with PGTest() as cluster: pgsu = PGSU(dsn=cluster.dsn) # make sure we've connected to the right cluster assert cluster.dsn['port'] == pgsu.dsn['port'] # we should be connecting via psycopg assert pgsu.connection_mode == PostgresConnectionMode.PSYCOPG
def test_pg_ctl_exe_valid(self): pg_ctl_exe = pgtest.which('pg_ctl') with pgtest.PGTest(pg_ctl=pg_ctl_exe) as pg: self.assertTrue(pgtest.is_server_running(pg.cluster))
def test_windows_which_is_not_executable(self): self.assertEqual(None, pgtest.which('does not exist'))
def test_windows_which_path_with_extension_is_executable(self): self.assertEqual('C:\\Windows\\system32\\ping.exe', pgtest.which('C:/Windows/system32/ping.exe'))
def test_windows_which_is_executable(self): self.assertEqual('C:\\Windows\\system32\\ping.exe', pgtest.which('ping'))
def test_windows_which_unicode(self): self.assertEqual('C:\\Windows\\system32\\ping.exe', pgtest.which(u'ping'))
def test_unix_which_unicode(self): self.assertEqual('/bin/ping', pgtest.which(u'ping'))
def test_which_non_string(self): with self.assertRaises(TypeError): pgtest.which(1)
def testunix_which_path_is_executable(self): self.assertEqual('/bin/ping', pgtest.which('/bin/ping'))
def test_pg_ctl_valid(self): self.assertIsNotNone(pgtest.which(self.pg.pg_ctl))
def setUpClass(cls): cls.pg_ctl_exe = pgtest.which('pg_ctl') cls.pg = pgtest.PGTest()