Skip to content

Target session attr (Sourcery refactored)#3

Open
sourcery-ai[bot] wants to merge 1 commit intotarget_session_attrfrom
sourcery/target_session_attr
Open

Target session attr (Sourcery refactored)#3
sourcery-ai[bot] wants to merge 1 commit intotarget_session_attrfrom
sourcery/target_session_attr

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Dec 8, 2022

Pull Request #2 refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the target_session_attr branch, then run:

git fetch origin sourcery/target_session_attr
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from JesseDeLoore December 8, 2022 07:23
@sourcery-ai
Copy link
Author

sourcery-ai bot commented Dec 8, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.09%.

Quality metrics Before After Change
Complexity 32.65 ⛔ 32.96 ⛔ 0.31 👎
Method Length 67.42 🙂 67.17 🙂 -0.25 👍
Working memory 9.09 🙂 9.20 🙂 0.11 👎
Quality 63.77% 🙂 63.68% 🙂 -0.09% 👎
Other metrics Before After Change
Lines 5227 5170 -57
Changed files Quality Before Quality After Quality Change
asyncpg/connect_utils.py 30.86% 😞 30.71% 😞 -0.15% 👎
asyncpg/connection.py 71.53% 🙂 71.60% 🙂 0.07% 👍
asyncpg/_testbase/__init__.py 81.30% ⭐ 81.22% ⭐ -0.08% 👎
asyncpg/exceptions/_base.py 79.66% ⭐ 79.17% ⭐ -0.49% 👎
tests/test_connect.py 72.52% 🙂 72.59% 🙂 0.07% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
asyncpg/connect_utils.py _parse_connect_dsn_and_args 276 ⛔ 1314 ⛔ 28 ⛔ 1.20% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
asyncpg/connect_utils.py _parse_hostlist 31 😞 205 ⛔ 17 ⛔ 23.70% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tests/test_connect.py TestConnectParams.run_testcase 13 🙂 331 ⛔ 19 ⛔ 28.32% 😞 Try splitting into smaller methods. Extract out complex expressions
asyncpg/connection.py Connection._get_statement 18 🙂 254 ⛔ 15 😞 30.77% 😞 Try splitting into smaller methods. Extract out complex expressions
asyncpg/connect_utils.py __connect_addr 15 🙂 240 ⛔ 17 ⛔ 31.76% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@sourcery-ai sourcery-ai bot force-pushed the sourcery/target_session_attr branch from 22a09c9 to e665b3c Compare December 8, 2022 07:45
Comment on lines -1306 to +1308
drop_script = []
drop_script.append('DROP ROLE ssl_user;')
drop_script = ['DROP ROLE ssl_user;']
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BaseTestSSLConnection.tearDown refactored with the following changes:

Comment on lines -1354 to +1358
dsn='postgresql://foo/postgres?sslmode=' + sslmode,
dsn=f'postgresql://foo/postgres?sslmode={sslmode}',
host=host,
user='ssl_user')
user='ssl_user',
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestSSLConnection.test_ssl_connection_sslmode refactored with the following changes:

Comment on lines -1588 to +1597
dsn = 'postgres://ssl_user@localhost/postgres?' + params_str
dsn = f'postgres://ssl_user@localhost/postgres?{params_str}'
await self._test_works(dsn=dsn)

params['sslkey'] = CLIENT_SSL_PROTECTED_KEY_FILE
params['sslpassword'] = 'secRet'
params_str = urllib.parse.urlencode(params)
dsn = 'postgres://ssl_user@localhost/postgres?' + params_str
dsn = f'postgres://ssl_user@localhost/postgres?{params_str}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestClientSSLConnection.test_ssl_connection_client_auth_dsn refactored with the following changes:

Comment on lines -1609 to +1612
await self._test_works(dsn=dsn + '&sslpassword=secRet')
await self._test_works(dsn=f'{dsn}&sslpassword=secRet')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestClientSSLConnection.test_ssl_connection_client_auth_env refactored with the following changes:

Comment on lines -1616 to +1619
await self._test_works(dsn=dsn + '&sslpassword=secRet')
await self._test_works(dsn=f'{dsn}&sslpassword=secRet')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestClientSSLConnection.test_ssl_connection_client_auth_dot_postgresql refactored with the following changes:

Comment on lines -1637 to +1643
dsn='postgresql://foo/postgres?sslmode=' + sslmode,
dsn=f'postgresql://foo/postgres?sslmode={sslmode}',
host=host,
user='ssl_user')
user='ssl_user',
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestNoSSLConnection.test_nossl_connection_sslmode refactored with the following changes:

@sourcery-ai sourcery-ai bot force-pushed the sourcery/target_session_attr branch from e665b3c to e3926f7 Compare December 8, 2022 07:54
PGPASSFILE = 'pgpass.conf'
else:
PGPASSFILE = '.pgpass'
PGPASSFILE = 'pgpass.conf' if _system == 'Windows' else '.pgpass'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 77-80 refactored with the following changes:

Comment on lines -83 to +80
def _read_password_file(passfile: pathlib.Path) \
-> typing.List[typing.Tuple[str, ...]]:
def _read_password_file(passfile: pathlib.Path) -> typing.List[typing.Tuple[str, ...]]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _read_password_file refactored with the following changes:

Comment on lines -148 to +151
if phost != '*' and phost != host:
if phost not in ['*', host]:
continue
if pport != '*' and pport != str(port):
if pport not in ['*', str(port)]:
continue
if pdatabase != '*' and pdatabase != database:
if pdatabase not in ['*', database]:
continue
if puser != '*' and puser != user:
if puser not in ['*', user]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _read_password_from_pgpass refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator [×4] (merge-comparisons)

Comment on lines -169 to +167
'could not match {} port numbers to {} hosts'.format(
len(port), len(hosts)))
f'could not match {len(port)} port numbers to {len(hosts)} hosts'
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _validate_port_spec refactored with the following changes:

Comment on lines -178 to +180
if ',' in hostlist:
# A comma-separated list of host addresses.
hostspecs = hostlist.split(',')
else:
hostspecs = [hostlist]

hostspecs = hostlist.split(',') if ',' in hostlist else [hostlist]
hosts = []
hostlist_ports = []

if not port:
portspec = os.environ.get('PGPORT')
if portspec:
if portspec := os.environ.get('PGPORT'):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _parse_hostlist refactored with the following changes:

This removes the following comments ( why? ):

# IPv6 address
# A comma-separated list of host addresses.

Comment on lines -966 to +959
tabname = utils._quote_ident(schema_name) + '.' + tabname
tabname = f'{utils._quote_ident(schema_name)}.{tabname}'

if columns:
col_list = ', '.join(utils._quote_ident(c) for c in columns)
cols = '({})'.format(col_list)
cols = f'({col_list})'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Connection.copy_records_to_table refactored with the following changes:

Comment on lines -1010 to +1001
opts.append('{} {}'.format(k.upper(), v))
opts.append(f'{k.upper()} {v}')

if opts:
return '(' + ', '.join(opts) + ')'
else:
return ''
return '(' + ', '.join(opts) + ')' if opts else ''
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Connection._format_copy_opts refactored with the following changes:

Comment on lines -1226 to +1213
'cannot use custom codec on non-scalar type {}.{}'.format(
schema, typename))
f'cannot use custom codec on non-scalar type {schema}.{typename}'
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Connection.set_type_codec refactored with the following changes:

Comment on lines -1305 to +1292
'cannot alias non-scalar type {}.{}'.format(
schema, typename))
f'cannot alias non-scalar type {schema}.{typename}'
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Connection.set_builtin_type_codec refactored with the following changes:

Comment on lines -1517 to +1503
if self._proxy is None:
con_ref = self
else:
# `_proxy` is not None when the connection is a member
# of a connection pool. Which means that the user is working
# with a `PoolConnectionProxy` instance, and expects to see it
# (and not the actual Connection) in their event callbacks.
con_ref = self._proxy
return con_ref
return self if self._proxy is None else self._proxy
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Connection._unwrap refactored with the following changes:

This removes the following comments ( why? ):

# with a `PoolConnectionProxy` instance, and expects to see it
# `_proxy` is not None when the connection is a member
# (and not the actual Connection) in their event callbacks.
# of a connection pool.  Which means that the user is working

Comment on lines -2345 to -2353
elif hasattr(connection_settings, 'crdb_version'):
elif hasattr(connection_settings, 'crdb_version') or hasattr(
connection_settings, 'crate_version'
):
# CockroachDB detected.
advisory_locks = False
notifications = False
plpgsql = False
sql_reset = False
sql_close_all = False
elif hasattr(connection_settings, 'crate_version'):
# CrateDB detected.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _detect_server_capabilities refactored with the following changes:

This removes the following comments ( why? ):

# CrateDB detected.

Comment on lines -121 to +124
formatted = []

for i, context in enumerate(self.__unhandled_exceptions):
formatted.append(self._format_loop_exception(context, i + 1))
formatted = [
self._format_loop_exception(context, i + 1)
for i, context in enumerate(self.__unhandled_exceptions)
]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestCase.tearDown refactored with the following changes:

Comment on lines -186 to +193
value = 'Object created at (most recent call last):\n'
value += tb.rstrip()
value = 'Object created at (most recent call last):\n' + tb.rstrip()
else:
try:
value = repr(value)
except Exception as ex:
value = ('Exception in __repr__ {!r}; '
'value type: {!r}'.format(ex, type(value)))
lines.append('[{}]: {}\n\n'.format(key, value))
lines.append(f'[{key}]: {value}\n\n')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestCase._format_loop_exception refactored with the following changes:

Comment on lines -225 to +224
if not initdb_options:
initdb_options = {}
else:
initdb_options = dict(initdb_options)

initdb_options = dict(initdb_options) if initdb_options else {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _get_initdb_options refactored with the following changes:

Comment on lines -241 to +236
pg_host = os.environ.get('PGHOST')
if pg_host:
if pg_host := os.environ.get('PGHOST'):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _init_default_cluster refactored with the following changes:

Comment on lines -199 to +207
drop_script.append('DROP ROLE {}_user;'.format(username))
drop_script.append(f'DROP ROLE {username}_user;')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestAuthentication.tearDown refactored with the following changes:

Comment on lines -211 to -216
for tried in range(3):
try:
for _ in range(3):
with contextlib.suppress(asyncpg.ConnectionDoesNotExistError):
return await self.connect(**kwargs)
except asyncpg.ConnectionDoesNotExistError:
pass

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestAuthentication._try_connect refactored with the following changes:

Comment on lines -755 to +760
old_vals = {}
for key in kwargs:
if key in os.environ:
old_vals[key] = os.environ[key]

old_vals = {key: os.environ[key] for key in kwargs if key in os.environ}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestConnectParams.environ refactored with the following changes:

Comment on lines -781 to +782
test_env.update(env)
test_env |= env
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestConnectParams.run_testcase refactored with the following changes:

Comment on lines -937 to +950
self.run_testcase({
'dsn': 'postgres://user@abc/db?passfile={}'.format(
passfile.name),
'result': (
[('abc', 5432)],
{
'password': 'password from pgpass for user@abc',
'user': 'user',
'database': 'db',
}
)
})
self.run_testcase(
{
'dsn': f'postgres://user@abc/db?passfile={passfile.name}',
'result': (
[('abc', 5432)],
{
'password': 'password from pgpass for user@abc',
'user': 'user',
'database': 'db',
},
),
}
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestConnectParams.test_connect_pgpass_regular refactored with the following changes:

Comment on lines -1222 to +1228
dsn='postgresql://foo/?sslmode=' + sslmode,
dsn=f'postgresql://foo/?sslmode={sslmode}',
user='postgres',
database='postgres',
host='localhost')
host='localhost',
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestConnection.test_connection_sslmode_no_ssl_server refactored with the following changes:

Comment on lines -1291 to +1295
create_script = []
create_script.append('CREATE ROLE ssl_user WITH LOGIN;')

create_script = ['CREATE ROLE ssl_user WITH LOGIN;']
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BaseTestSSLConnection.setUp refactored with the following changes:

Comment on lines -1306 to +1308
drop_script = []
drop_script.append('DROP ROLE ssl_user;')
drop_script = ['DROP ROLE ssl_user;']
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BaseTestSSLConnection.tearDown refactored with the following changes:

Comment on lines -1354 to +1358
dsn='postgresql://foo/postgres?sslmode=' + sslmode,
dsn=f'postgresql://foo/postgres?sslmode={sslmode}',
host=host,
user='ssl_user')
user='ssl_user',
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestSSLConnection.test_ssl_connection_sslmode refactored with the following changes:

Comment on lines -1588 to +1597
dsn = 'postgres://ssl_user@localhost/postgres?' + params_str
dsn = f'postgres://ssl_user@localhost/postgres?{params_str}'
await self._test_works(dsn=dsn)

params['sslkey'] = CLIENT_SSL_PROTECTED_KEY_FILE
params['sslpassword'] = 'secRet'
params_str = urllib.parse.urlencode(params)
dsn = 'postgres://ssl_user@localhost/postgres?' + params_str
dsn = f'postgres://ssl_user@localhost/postgres?{params_str}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestClientSSLConnection.test_ssl_connection_client_auth_dsn refactored with the following changes:

Comment on lines -1609 to +1612
await self._test_works(dsn=dsn + '&sslpassword=secRet')
await self._test_works(dsn=f'{dsn}&sslpassword=secRet')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestClientSSLConnection.test_ssl_connection_client_auth_env refactored with the following changes:

Comment on lines -1616 to +1619
await self._test_works(dsn=dsn + '&sslpassword=secRet')
await self._test_works(dsn=f'{dsn}&sslpassword=secRet')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestClientSSLConnection.test_ssl_connection_client_auth_dot_postgresql refactored with the following changes:

Comment on lines -1637 to +1643
dsn='postgresql://foo/postgres?sslmode=' + sslmode,
dsn=f'postgresql://foo/postgres?sslmode={sslmode}',
host=host,
user='ssl_user')
user='ssl_user',
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestNoSSLConnection.test_nossl_connection_sslmode refactored with the following changes:

@sourcery-ai sourcery-ai bot force-pushed the sourcery/target_session_attr branch from e3926f7 to a7674f2 Compare December 8, 2022 08:22
PGPASSFILE = 'pgpass.conf'
else:
PGPASSFILE = '.pgpass'
PGPASSFILE = 'pgpass.conf' if _system == 'Windows' else '.pgpass'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 77-80 refactored with the following changes:

Comment on lines -83 to +80
def _read_password_file(passfile: pathlib.Path) \
-> typing.List[typing.Tuple[str, ...]]:
def _read_password_file(passfile: pathlib.Path) -> typing.List[typing.Tuple[str, ...]]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _read_password_file refactored with the following changes:

Comment on lines -148 to +151
if phost != '*' and phost != host:
if phost not in ['*', host]:
continue
if pport != '*' and pport != str(port):
if pport not in ['*', str(port)]:
continue
if pdatabase != '*' and pdatabase != database:
if pdatabase not in ['*', database]:
continue
if puser != '*' and puser != user:
if puser not in ['*', user]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _read_password_from_pgpass refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator [×4] (merge-comparisons)

Comment on lines -169 to +167
'could not match {} port numbers to {} hosts'.format(
len(port), len(hosts)))
f'could not match {len(port)} port numbers to {len(hosts)} hosts'
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _validate_port_spec refactored with the following changes:

Comment on lines -178 to +180
if ',' in hostlist:
# A comma-separated list of host addresses.
hostspecs = hostlist.split(',')
else:
hostspecs = [hostlist]

hostspecs = hostlist.split(',') if ',' in hostlist else [hostlist]
hosts = []
hostlist_ports = []

if not port:
portspec = os.environ.get('PGPORT')
if portspec:
if portspec := os.environ.get('PGPORT'):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _parse_hostlist refactored with the following changes:

This removes the following comments ( why? ):

# IPv6 address
# A comma-separated list of host addresses.

Comment on lines -966 to +959
tabname = utils._quote_ident(schema_name) + '.' + tabname
tabname = f'{utils._quote_ident(schema_name)}.{tabname}'

if columns:
col_list = ', '.join(utils._quote_ident(c) for c in columns)
cols = '({})'.format(col_list)
cols = f'({col_list})'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Connection.copy_records_to_table refactored with the following changes:

Comment on lines -1010 to +1001
opts.append('{} {}'.format(k.upper(), v))
opts.append(f'{k.upper()} {v}')

if opts:
return '(' + ', '.join(opts) + ')'
else:
return ''
return '(' + ', '.join(opts) + ')' if opts else ''
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Connection._format_copy_opts refactored with the following changes:

Comment on lines -1226 to +1213
'cannot use custom codec on non-scalar type {}.{}'.format(
schema, typename))
f'cannot use custom codec on non-scalar type {schema}.{typename}'
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Connection.set_type_codec refactored with the following changes:

Comment on lines -1305 to +1292
'cannot alias non-scalar type {}.{}'.format(
schema, typename))
f'cannot alias non-scalar type {schema}.{typename}'
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Connection.set_builtin_type_codec refactored with the following changes:

Comment on lines -1517 to +1503
if self._proxy is None:
con_ref = self
else:
# `_proxy` is not None when the connection is a member
# of a connection pool. Which means that the user is working
# with a `PoolConnectionProxy` instance, and expects to see it
# (and not the actual Connection) in their event callbacks.
con_ref = self._proxy
return con_ref
return self if self._proxy is None else self._proxy
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Connection._unwrap refactored with the following changes:

This removes the following comments ( why? ):

# with a `PoolConnectionProxy` instance, and expects to see it
# `_proxy` is not None when the connection is a member
# (and not the actual Connection) in their event callbacks.
# of a connection pool.  Which means that the user is working

Comment on lines -2345 to -2353
elif hasattr(connection_settings, 'crdb_version'):
elif hasattr(connection_settings, 'crdb_version') or hasattr(
connection_settings, 'crate_version'
):
# CockroachDB detected.
advisory_locks = False
notifications = False
plpgsql = False
sql_reset = False
sql_close_all = False
elif hasattr(connection_settings, 'crate_version'):
# CrateDB detected.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _detect_server_capabilities refactored with the following changes:

This removes the following comments ( why? ):

# CrateDB detected.

Comment on lines -121 to +124
formatted = []

for i, context in enumerate(self.__unhandled_exceptions):
formatted.append(self._format_loop_exception(context, i + 1))
formatted = [
self._format_loop_exception(context, i + 1)
for i, context in enumerate(self.__unhandled_exceptions)
]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestCase.tearDown refactored with the following changes:

Comment on lines -186 to +193
value = 'Object created at (most recent call last):\n'
value += tb.rstrip()
value = 'Object created at (most recent call last):\n' + tb.rstrip()
else:
try:
value = repr(value)
except Exception as ex:
value = ('Exception in __repr__ {!r}; '
'value type: {!r}'.format(ex, type(value)))
lines.append('[{}]: {}\n\n'.format(key, value))
lines.append(f'[{key}]: {value}\n\n')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestCase._format_loop_exception refactored with the following changes:

Comment on lines -225 to +224
if not initdb_options:
initdb_options = {}
else:
initdb_options = dict(initdb_options)

initdb_options = dict(initdb_options) if initdb_options else {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _get_initdb_options refactored with the following changes:

Comment on lines -241 to +236
pg_host = os.environ.get('PGHOST')
if pg_host:
if pg_host := os.environ.get('PGHOST'):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _init_default_cluster refactored with the following changes:

Comment on lines -199 to +207
drop_script.append('DROP ROLE {}_user;'.format(username))
drop_script.append(f'DROP ROLE {username}_user;')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestAuthentication.tearDown refactored with the following changes:

Comment on lines -211 to -216
for tried in range(3):
try:
for _ in range(3):
with contextlib.suppress(asyncpg.ConnectionDoesNotExistError):
return await self.connect(**kwargs)
except asyncpg.ConnectionDoesNotExistError:
pass

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestAuthentication._try_connect refactored with the following changes:

Comment on lines -755 to +760
old_vals = {}
for key in kwargs:
if key in os.environ:
old_vals[key] = os.environ[key]

old_vals = {key: os.environ[key] for key in kwargs if key in os.environ}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestConnectParams.environ refactored with the following changes:

Comment on lines -781 to +782
test_env.update(env)
test_env |= env
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestConnectParams.run_testcase refactored with the following changes:

Comment on lines -937 to +950
self.run_testcase({
'dsn': 'postgres://user@abc/db?passfile={}'.format(
passfile.name),
'result': (
[('abc', 5432)],
{
'password': 'password from pgpass for user@abc',
'user': 'user',
'database': 'db',
}
)
})
self.run_testcase(
{
'dsn': f'postgres://user@abc/db?passfile={passfile.name}',
'result': (
[('abc', 5432)],
{
'password': 'password from pgpass for user@abc',
'user': 'user',
'database': 'db',
},
),
}
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestConnectParams.test_connect_pgpass_regular refactored with the following changes:

Comment on lines -1222 to +1228
dsn='postgresql://foo/?sslmode=' + sslmode,
dsn=f'postgresql://foo/?sslmode={sslmode}',
user='postgres',
database='postgres',
host='localhost')
host='localhost',
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestConnection.test_connection_sslmode_no_ssl_server refactored with the following changes:

Comment on lines -1291 to +1295
create_script = []
create_script.append('CREATE ROLE ssl_user WITH LOGIN;')

create_script = ['CREATE ROLE ssl_user WITH LOGIN;']
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BaseTestSSLConnection.setUp refactored with the following changes:

Comment on lines -1306 to +1308
drop_script = []
drop_script.append('DROP ROLE ssl_user;')
drop_script = ['DROP ROLE ssl_user;']
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BaseTestSSLConnection.tearDown refactored with the following changes:

Comment on lines -1354 to +1358
dsn='postgresql://foo/postgres?sslmode=' + sslmode,
dsn=f'postgresql://foo/postgres?sslmode={sslmode}',
host=host,
user='ssl_user')
user='ssl_user',
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestSSLConnection.test_ssl_connection_sslmode refactored with the following changes:

Comment on lines -1588 to +1597
dsn = 'postgres://ssl_user@localhost/postgres?' + params_str
dsn = f'postgres://ssl_user@localhost/postgres?{params_str}'
await self._test_works(dsn=dsn)

params['sslkey'] = CLIENT_SSL_PROTECTED_KEY_FILE
params['sslpassword'] = 'secRet'
params_str = urllib.parse.urlencode(params)
dsn = 'postgres://ssl_user@localhost/postgres?' + params_str
dsn = f'postgres://ssl_user@localhost/postgres?{params_str}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestClientSSLConnection.test_ssl_connection_client_auth_dsn refactored with the following changes:

Comment on lines -1609 to +1612
await self._test_works(dsn=dsn + '&sslpassword=secRet')
await self._test_works(dsn=f'{dsn}&sslpassword=secRet')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestClientSSLConnection.test_ssl_connection_client_auth_env refactored with the following changes:

Comment on lines -1616 to +1619
await self._test_works(dsn=dsn + '&sslpassword=secRet')
await self._test_works(dsn=f'{dsn}&sslpassword=secRet')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestClientSSLConnection.test_ssl_connection_client_auth_dot_postgresql refactored with the following changes:

Comment on lines -1637 to +1643
dsn='postgresql://foo/postgres?sslmode=' + sslmode,
dsn=f'postgresql://foo/postgres?sslmode={sslmode}',
host=host,
user='ssl_user')
user='ssl_user',
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestNoSSLConnection.test_nossl_connection_sslmode refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants