def run_testcase(self, testcase): env = testcase.get('env', {}) test_env = { 'PGHOST': None, 'PGPORT': None, 'PGUSER': None, 'PGPASSWORD': None, 'PGDATABASE': None } test_env.update(env) dsn = testcase.get('dsn') opts = testcase.get('opts', {}) user = testcase.get('user') port = testcase.get('port') host = testcase.get('host') password = testcase.get('password') database = testcase.get('database') expected = testcase.get('result') expected_error = testcase.get('error') if expected is None and expected_error is None: raise RuntimeError( 'invalid test case: either "result" or "error" key ' 'has to be specified') if expected is not None and expected_error is not None: raise RuntimeError( 'invalid test case: either "result" or "error" key ' 'has to be specified, got both') with contextlib.ExitStack() as es: es.enter_context(self.subTest(dsn=dsn, opts=opts, env=env)) es.enter_context(self.environ(**test_env)) if expected_error: es.enter_context(self.assertRaisesRegex(*expected_error)) result = _parse_connect_params(dsn=dsn, host=host, port=port, user=user, password=password, database=database, opts=opts) if expected is not None: self.assertEqual(expected, result)
def run_testcase(self, testcase): env = testcase.get('env', {}) test_env = {'PGHOST': None, 'PGPORT': None, 'PGUSER': None, 'PGPASSWORD': None, 'PGDATABASE': None} test_env.update(env) dsn = testcase.get('dsn') opts = testcase.get('opts', {}) user = testcase.get('user') port = testcase.get('port') host = testcase.get('host') password = testcase.get('password') database = testcase.get('database') expected = testcase.get('result') expected_error = testcase.get('error') if expected is None and expected_error is None: raise RuntimeError( 'invalid test case: either "result" or "error" key ' 'has to be specified') if expected is not None and expected_error is not None: raise RuntimeError( 'invalid test case: either "result" or "error" key ' 'has to be specified, got both') with contextlib.ExitStack() as es: es.enter_context(self.subTest(dsn=dsn, opts=opts, env=env)) es.enter_context(self.environ(**test_env)) if expected_error: es.enter_context(self.assertRaisesRegex(*expected_error)) result = _parse_connect_params( dsn=dsn, host=host, port=port, user=user, password=password, database=database, opts=opts) if expected is not None: self.assertEqual(expected, result)