From 64b907961d9c380bc72cca5f3fda4dd16421a307 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 11:37:32 +0300 Subject: [PATCH 01/21] NodeApp::_paramlist_append is updated (pylance) --- src/node_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_app.py b/src/node_app.py index 8d6e40c2..48377ced 100644 --- a/src/node_app.py +++ b/src/node_app.py @@ -249,7 +249,7 @@ def _paramlist_append( assert updated_params is not None if updated_params is user_params: - return [*user_params, param] + return [*updated_params, param] updated_params.append(param) return updated_params From 6f971edb238309b6becd899ed8300bc0e0c20e20 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 11:40:09 +0300 Subject: [PATCH 02/21] PostgresNode::source_walsender is updated Asserts are added to fix a problem with pylance. --- src/node.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/node.py b/src/node.py index bf33cb66..a6b6e17d 100644 --- a/src/node.py +++ b/src/node.py @@ -565,10 +565,23 @@ def source_walsender(self): assert type(self.master) is PostgresNode with self.master.connect() as con: - for row in con.execute(sql, self.name): + execute_r = con.execute(sql, self.name) + assert execute_r is not None + assert isinstance(execute_r, typing.Iterable) + for row in execute_r: + assert row is not None + assert type(row) in [list, tuple] + assert len(row) == 1 + row_col0 = row[0] + assert row_col0 is not None + row_col0_typed = int(row[0]) for child in self.master.auxiliary_processes: - if child.pid == int(row[0]): - return child + if child.pid != row_col0_typed: + continue + + assert child.pid == row_col0_typed + return child + continue msg = "Master doesn't send WAL to {}".format(self.name) raise TestgresException(msg) From 2e7a525dd9ffecc645a4fd8c421e35832cf5bd8c Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 11:41:54 +0300 Subject: [PATCH 03/21] PostgresNode::_try_shutdown_internal is updated Asserts are added to fix a problem with pylance. --- src/node.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/node.py b/src/node.py index a6b6e17d..77a43a17 100644 --- a/src/node.py +++ b/src/node.py @@ -709,11 +709,16 @@ def _try_shutdown_internal(self, max_attempts, with_force): ps_command = ['ps', '-o', 'pid=', '-p', str(node_pid)] - ps_output = self._os_ops.run( + run_r = self._os_ops.run( cmd=ps_command, shell=True, check=False, - ).stdout.decode('utf-8') + ) + assert run_r is not None + assert run_r.stdout is not None + assert type(run_r.stdout) is bytes + + ps_output = run_r.stdout.decode('utf-8') assert type(ps_output) is str if ps_output == "": @@ -735,11 +740,16 @@ def _try_shutdown_internal(self, max_attempts, with_force): pass # Check that node stopped - print only column pid without headers - ps_output = self._os_ops.run( + run_r = self._os_ops.run( cmd=ps_command, shell=True, check=False, - ).stdout.decode('utf-8') + ) + assert run_r is not None + assert run_r.stdout is not None + assert type(run_r.stdout) is bytes + + ps_output = run_r.stdout.decode('utf-8') assert type(ps_output) is str if ps_output == "": From 9e0c06b5479dff654303450e3ac4515fea297b61 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 15:31:04 +0300 Subject: [PATCH 04/21] fix: TestTestgresCommon::tag_rmdirs_protector::proxy__rmdirs is corrected --- tests/test_testgres_common.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_testgres_common.py b/tests/test_testgres_common.py index c8617275..6c215fc2 100644 --- a/tests/test_testgres_common.py +++ b/tests/test_testgres_common.py @@ -3253,7 +3253,13 @@ def __exit__(self, exc_type, exc_val, exc_tb): self._os_ops.rmdirs = self._old_rmdirs return False - def proxy__rmdirs(self, path, ignore_errors=True): + def proxy__rmdirs( + self, + path, + ignore_errors=True, + attempts: int = 3, + delay: OsOperations.T_DELAY = 1, + ) -> bool: raise Exception("Call of rmdirs is not expected!") def test_node_app__make_empty__base_dir_is_None(self, node_svc: PostgresNodeService): From 528e916cda5dff32cc8ef235d227a02fff8d0cad Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 15:34:10 +0300 Subject: [PATCH 05/21] TestOsOpsCommon::test_popen_garbage_collection is updated (pylance) getattr is used. --- tests/test_os_ops_common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_os_ops_common.py b/tests/test_os_ops_common.py index fa8df96d..4d9e31a7 100644 --- a/tests/test_os_ops_common.py +++ b/tests/test_os_ops_common.py @@ -5007,9 +5007,9 @@ def test_popen_garbage_collection( # Запоминаем локальный процесс транспорта, чтобы проверить его смерть в конце if type(controller).__name__ == "LocalProcessController": - local_p = controller._local_process + local_p = getattr(controller, "_local_process") elif type(controller).__name__ == "RemoteProcessController": - local_p = controller._local_process + local_p = getattr(controller, "_local_process") else: raise RuntimeError("Unknown controller type: {}.".format( type(controller).__name__, From 041d3d2a2dc4c8a35898d273831c5fdfb9c6ecdb Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 15:38:45 +0300 Subject: [PATCH 06/21] misc (formatting) --- tests/test_testgres_common.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_testgres_common.py b/tests/test_testgres_common.py index 6c215fc2..b286d42a 100644 --- a/tests/test_testgres_common.py +++ b/tests/test_testgres_common.py @@ -2547,9 +2547,11 @@ def test_pgbench(self, node_svc: PostgresNodeService): ).pgbench_run(time=2) # run TPC-B benchmark - proc = node.pgbench(stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - options=['-T3']) + proc = node.pgbench( + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + options=['-T3'], + ) out = proc.communicate()[0] assert (b'tps = ' in out) From 8838cd2c8c25da79568790ba9446314f2d2e738b Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 15:42:42 +0300 Subject: [PATCH 07/21] TestTestgresCommon::test_pgbench is updated (pyright, asserts) --- tests/test_testgres_common.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_testgres_common.py b/tests/test_testgres_common.py index b286d42a..5273a44b 100644 --- a/tests/test_testgres_common.py +++ b/tests/test_testgres_common.py @@ -2552,8 +2552,15 @@ def test_pgbench(self, node_svc: PostgresNodeService): stderr=subprocess.STDOUT, options=['-T3'], ) - out = proc.communicate()[0] + communicate_r = proc.communicate() + assert type(communicate_r) is not None + assert type(communicate_r) is tuple + assert len(communicate_r) == 2 + out = communicate_r[0] + assert out is not None + assert type(out) is bytes assert (b'tps = ' in out) + return def test_unix_sockets(self, node_svc: PostgresNodeService): assert isinstance(node_svc, PostgresNodeService) From 43a7058b0d3490ad4d677de0e640a38c86fbb56e Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 15:48:28 +0300 Subject: [PATCH 08/21] TestTestgresCommon::test_poll_query_until is updated (formatting) --- tests/test_testgres_common.py | 45 ++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/tests/test_testgres_common.py b/tests/test_testgres_common.py index 5273a44b..df65af8e 100644 --- a/tests/test_testgres_common.py +++ b/tests/test_testgres_common.py @@ -1615,36 +1615,46 @@ def test_poll_query_until(self, node_svc: PostgresNodeService): # check 0 columns with pytest.raises(expected_exception=QueryException): node.poll_query_until( - query='select from pg_catalog.pg_class limit 1') + query='select from pg_catalog.pg_class limit 1', + ) # check None, fail with pytest.raises(expected_exception=QueryException): - node.poll_query_until(query='create table abc (val int)') + node.poll_query_until( + query='create table abc (val int)', + ) # check None, ok - node.poll_query_until(query='create table def()', - expected=None) # returns nothing + node.poll_query_until( + query='create table def()', + expected=None, + ) # returns nothing # check 0 rows equivalent to expected=None node.poll_query_until( query='select * from pg_catalog.pg_class where true = false', - expected=None) + expected=None, + ) # check arbitrary expected value, fail with pytest.raises(expected_exception=QueryTimeoutException): - node.poll_query_until(query='select 3', - expected=1, - max_attempts=3, - sleep_time=0.01) + node.poll_query_until( + query='select 3', + expected=1, + max_attempts=3, + sleep_time=0.01, + ) # check arbitrary expected value, ok node.poll_query_until(query='select 2', expected=2) # check timeout with pytest.raises(expected_exception=QueryTimeoutException): - node.poll_query_until(query='select 1 > 2', - max_attempts=3, - sleep_time=0.01) + node.poll_query_until( + query='select 1 > 2', + max_attempts=3, + sleep_time=0.01, + ) # check ProgrammingError, fail with pytest.raises(expected_exception=ProgrammingError): @@ -1652,13 +1662,16 @@ def test_poll_query_until(self, node_svc: PostgresNodeService): # check ProgrammingError, ok with pytest.raises(expected_exception=(QueryTimeoutException)): - node.poll_query_until(query='dummy2', - max_attempts=3, - sleep_time=0.01, - suppress={ProgrammingError}) + node.poll_query_until( + query='dummy2', + max_attempts=3, + sleep_time=0.01, + suppress={ProgrammingError}, + ) # check 1 arg, ok node.poll_query_until('select true') + return def test_logging(self, node_svc: PostgresNodeService): assert isinstance(node_svc, PostgresNodeService) From 2fb4241d1dc99faf56f64fd1f2ac34d718011387 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 15:53:19 +0300 Subject: [PATCH 09/21] fix: (node::poll_query_until) expected has type typing.Any (pylance) --- src/node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node.py b/src/node.py index 77a43a17..39919a3a 100644 --- a/src/node.py +++ b/src/node.py @@ -1966,7 +1966,7 @@ def poll_query_until( username: typing.Optional[str] = None, max_attempts: int = 0, sleep_time: typing.Union[int, float] = 1, - expected: bool = True, + expected: typing.Any = True, commit: bool = True, suppress: typing.Optional[typing.Iterable[BaseException]] = None, ) -> None: From f4edcf40065a489aa8e59219b6b06ac8dc19c57e Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 16:03:59 +0300 Subject: [PATCH 10/21] TestTestgresCommon::test_init_unique_system_id is updated/corrected (pyright) --- tests/test_testgres_common.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/test_testgres_common.py b/tests/test_testgres_common.py index df65af8e..7731cfc8 100644 --- a/tests/test_testgres_common.py +++ b/tests/test_testgres_common.py @@ -380,9 +380,23 @@ def test_init_unique_system_id(self, node_svc: PostgresNodeService): query = 'select system_identifier from pg_control_system()' + def LOCAL__read_id(exec_r) -> int: + assert exec_r is not None + assert type(exec_r) is list + assert len(exec_r) == 1 + exec_r0 = exec_r[0] + assert exec_r0 is not None + assert type(exec_r0) in [list, tuple] + assert len(exec_r0) == 1 + id = exec_r0[0] + assert id is not None + return int(id) + with scoped_config(cache_initdb=False): with __class__.helper__get_node(node_svc).init().start() as node0: - id0 = node0.execute(query)[0] + id0 = LOCAL__read_id(node0.execute(query)) + + logging.info("id0={}".format(id0)) with scoped_config(cache_initdb=True, cached_initdb_unique=True) as config: @@ -392,12 +406,16 @@ def test_init_unique_system_id(self, node_svc: PostgresNodeService): # spawn two nodes; ids must be different with __class__.helper__get_node(node_svc).init().start() as node1, \ __class__.helper__get_node(node_svc).init().start() as node2: - id1 = node1.execute(query)[0] - id2 = node2.execute(query)[0] + id1 = LOCAL__read_id(node1.execute(query)) + id2 = LOCAL__read_id(node2.execute(query)) + + logging.info("id1={}".format(id1)) + logging.info("id2={}".format(id2)) # ids must increase assert (id1 > id0) assert (id2 > id1) + return def test_node_exit(self, node_svc: PostgresNodeService): assert isinstance(node_svc, PostgresNodeService) From e980ad047172abaf15f127c8d3ef4e09823d39db Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 16:06:22 +0300 Subject: [PATCH 11/21] TestTestgresCommon::test_custom_init__hba is updated (pyright) --- tests/test_testgres_common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_testgres_common.py b/tests/test_testgres_common.py index 7731cfc8..eda81d66 100644 --- a/tests/test_testgres_common.py +++ b/tests/test_testgres_common.py @@ -341,6 +341,7 @@ def normalize_line(line_str): # We collect a list of rules that already exist in the file (in the form of word lists) existing_normalized = [] for s in lines: + assert type(s) is str s_clean = s.strip() if s_clean and not s_clean.startswith("#"): existing_normalized.append(normalize_line(s_clean)) From 6d814eeb84d569dfb9b5b9641b2356323efb86b7 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 23:27:09 +0300 Subject: [PATCH 12/21] fix: (PostgresNode::poll_query_until) type of 'suppress' is fixed Arg 'suppress' has type typing.Iterable[typing.Type[BaseException]], not typing.Optional[T_SUPPRESS_EXCS]. --- src/node.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/node.py b/src/node.py index 39919a3a..b0f6db1b 100644 --- a/src/node.py +++ b/src/node.py @@ -1958,6 +1958,8 @@ def restore( except ExecUtilException: self.psql(filename=filename, dbname=dbname, username=username) + T_SUPPRESS_EXCS = typing.Iterable[typing.Type[BaseException]] + @method_decorator(positional_args_hack(['dbname', 'query'])) def poll_query_until( self, @@ -1968,7 +1970,7 @@ def poll_query_until( sleep_time: typing.Union[int, float] = 1, expected: typing.Any = True, commit: bool = True, - suppress: typing.Optional[typing.Iterable[BaseException]] = None, + suppress: typing.Optional[T_SUPPRESS_EXCS] = None, ) -> None: """ Run a query once per second until it returns 'expected'. From 6cdc8df1dc99291faa4b23236c2fe5df94b990b7 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Tue, 24 Nov 2026 00:09:21 +0300 Subject: [PATCH 13/21] NodeApp::make_simple is updated (pylance) --- src/node_app.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/node_app.py b/src/node_app.py index 48377ced..4e2745b9 100644 --- a/src/node_app.py +++ b/src/node_app.py @@ -157,11 +157,16 @@ def make_simple( ) # set major version - pg_version_file = self._os_ops.read(self._os_ops.build_path(node.data_dir, 'PG_VERSION')) + pg_version_file = self._os_ops.read( + self._os_ops.build_path(node.data_dir, 'PG_VERSION'), + ) + assert type(pg_version_file) is str # What is it ??? - node.major_version_str = str(pg_version_file.rstrip()) - node.major_version = float(node.major_version_str) + major_version_str = pg_version_file.rstrip() + setattr(node, "major_version_str", major_version_str) + major_version = float(major_version_str) + setattr(node, "major_version", major_version) # Set default parameters options = { @@ -187,7 +192,7 @@ def make_simple( options['ptrack.map_size'] = '1' options['shared_preload_libraries'] = 'ptrack' - if node.major_version >= 13: + if major_version >= 13: options['wal_keep_size'] = '200MB' else: options['wal_keep_segments'] = '12' @@ -208,7 +213,7 @@ def make_simple( # kludge for testgres # https://github.com/postgrespro/testgres/issues/54 # for PG >= 13 remove 'wal_keep_segments' parameter - if node.major_version >= 13: + if major_version >= 13: node.set_auto_conf( {}, 'postgresql.conf', From b5516828c6e21440de3b58ddedfca04edc584f72 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Tue, 24 Nov 2026 00:11:10 +0300 Subject: [PATCH 14/21] cached_initdb is updated (pylance, asserts) --- src/cache.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cache.py b/src/cache.py index 4fa53ded..ab905a10 100644 --- a/src/cache.py +++ b/src/cache.py @@ -65,6 +65,7 @@ def call_initdb(initdb_dir, log=logfile): cached_data_dir = testgres_config.cached_initdb_dir # Initialize cached initdb + assert cached_data_dir is not None if not os_ops.path_exists(cached_data_dir) or \ not os_ops.listdir(cached_data_dir): @@ -82,6 +83,8 @@ def call_initdb(initdb_dir, log=logfile): pg_control = os_ops.build_path(data_dir, XLOG_CONTROL_FILE) system_id = generate_system_id() cur_pg_control = os_ops.read(pg_control, binary=True) + assert cur_pg_control is not None + assert type(cur_pg_control) is bytes new_pg_control = system_id + cur_pg_control[len(system_id):] os_ops.write(pg_control, new_pg_control, truncate=True, binary=True, read_and_write=True) From 684e7d10a9d8fde2b04152d8dae4bec2b8e6a6d2 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Tue, 24 Nov 2026 00:12:04 +0300 Subject: [PATCH 15/21] safe_psql overloads are added (pylance) --- src/node.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/node.py b/src/node.py index b0f6db1b..060fed43 100644 --- a/src/node.py +++ b/src/node.py @@ -1809,13 +1809,30 @@ def _psql( assert type(r) is OsCommandResult return r - @method_decorator(positional_args_hack(['dbname', 'query'])) + @typing.overload def safe_psql( + self, + query: typing.Optional[str] = None, + expect_error: bool = False, + **kwargs: typing.Any, + ) -> typing.Any: ... + + @typing.overload + def safe_psql( + self, + dbname: str, + query: str, + expect_error: bool = False, + **kwargs: typing.Any, + ) -> typing.Any: ... + + @method_decorator(positional_args_hack(['dbname', 'query'])) + def safe_psql( # pyright: ignore[reportInconsistentOverload] self, query=None, expect_error=False, **kwargs, - ): + ) -> typing.Any: """ Execute a query using psql. From 8d5e7c3d6c8653d0bbaea2f92be4574b6a1a2367 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Tue, 24 Nov 2026 00:12:45 +0300 Subject: [PATCH 16/21] fix: PortManager__Generic::_guard has type typing.Any (pylance) --- src/impl/port_manager__generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl/port_manager__generic.py b/src/impl/port_manager__generic.py index 3d5b1490..29a5065b 100755 --- a/src/impl/port_manager__generic.py +++ b/src/impl/port_manager__generic.py @@ -14,7 +14,7 @@ class PortManager__Generic(PortManager): _C_MAX_PORT_NUMBER = 65535 _os_ops: OsOperations - _guard: object + _guard: typing.Any # TODO: is there better to use bitmap fot _available_ports? _available_ports: typing.Set[int] _reserved_ports: typing.Set[int] From 5274ce9907dec5d2ec3cfcc8823d9e70d4c7a94c Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Tue, 24 Nov 2026 00:14:53 +0300 Subject: [PATCH 17/21] NodeConnection::begin is updated (T_ISOLATIONLEVEL_OR_STR) --- src/impl/connection_psycopg2.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/impl/connection_psycopg2.py b/src/impl/connection_psycopg2.py index 56e49021..108c760d 100644 --- a/src/impl/connection_psycopg2.py +++ b/src/impl/connection_psycopg2.py @@ -90,7 +90,12 @@ def __exit__(self, type, value, traceback): self.close() return - def begin(self, isolation_level=IsolationLevel.ReadCommitted): + T_ISOLATIONLEVEL_OR_STR = typing.Union[IsolationLevel, str] + + def begin( + self, + isolation_level: T_ISOLATIONLEVEL_OR_STR = IsolationLevel.ReadCommitted, + ): # Check if level isn't an IsolationLevel if not isinstance(isolation_level, IsolationLevel): # Get name of isolation level From f89454062621038611a34f4fc03a38fc2fba8920 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Tue, 24 Nov 2026 00:15:46 +0300 Subject: [PATCH 18/21] test_testgres_remote::util_exists is updated (pylance) --- tests/test_testgres_remote.py | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/tests/test_testgres_remote.py b/tests/test_testgres_remote.py index 3f97ffa6..25115ef8 100755 --- a/tests/test_testgres_remote.py +++ b/tests/test_testgres_remote.py @@ -25,19 +25,37 @@ def util_exists(util): - def good_properties(f): - return (testgres_config.os_ops.path_exists(f) and # noqa: W504 - testgres_config.os_ops.isfile(f) and # noqa: W504 - testgres_config.os_ops.is_executable(f)) # yapf: disable + def LOCAL__good_properties(f): + if not testgres_config.os_ops.path_exists(f): + return False + + if not testgres_config.os_ops.isfile(f): + return False + + if not testgres_config.os_ops.is_executable(f): + return False + + return True # try to resolve it - if good_properties(get_bin_path(util)): + if LOCAL__good_properties(get_bin_path(util)): return True # check if util is in PATH - for path in testgres_config.os_ops.environ("PATH").split(testgres_config.os_ops.pathsep): - if good_properties(os.path.join(path, util)): - return True + path = testgres_config.os_ops.environ("PATH") + + if path is None: + return False + + assert path is not None + assert type(path) is str + + for path in path.split(testgres_config.os_ops.pathsep): + if not LOCAL__good_properties(os.path.join(path, util)): + continue + return True + + return False class TestTestgresRemote: From b0466491cac301247ab01a08524c816e8a3148de Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Tue, 24 Nov 2026 00:16:51 +0300 Subject: [PATCH 19/21] test_testgres_local::test_upgrade_node is updated (+assert) --- tests/test_testgres_local.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_testgres_local.py b/tests/test_testgres_local.py index 012ec12d..470a638c 100644 --- a/tests/test_testgres_local.py +++ b/tests/test_testgres_local.py @@ -131,6 +131,7 @@ def test_upgrade_node(self): with get_new_node(prefix='node_new', bin_dir=new_bin_dir) as node_new: node_new.init(cached=False) res = node_new.upgrade_from(old_node=node_old) + assert res is not None node_new.start() assert (b'Upgrade Complete' in res) From 8e4c43be6b08f10880049f9aaaca699ccba5ca49 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Tue, 24 Nov 2026 00:17:25 +0300 Subject: [PATCH 20/21] test_file_line_reader::helper__player is corrected --- tests/units/impl/test_file_line_reader.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/units/impl/test_file_line_reader.py b/tests/units/impl/test_file_line_reader.py index 0118aebf..83774d01 100755 --- a/tests/units/impl/test_file_line_reader.py +++ b/tests/units/impl/test_file_line_reader.py @@ -216,7 +216,11 @@ def helper__player( continue continue - assert file_line_reader.read_line() is None + if file_line_reader is None: + pass + else: + assert file_line_reader.read_line() is None + pass os_ops.rmdirs(tmpdir) assert not os_ops.path_exists(tmpdir) From 9417bd5a1d189281ee34142d8451f583cc321d87 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Tue, 24 Nov 2026 00:18:39 +0300 Subject: [PATCH 21/21] test_testgres_common is updated (pylance) --- tests/test_testgres_common.py | 78 ++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 15 deletions(-) diff --git a/tests/test_testgres_common.py b/tests/test_testgres_common.py index eda81d66..d9657103 100644 --- a/tests/test_testgres_common.py +++ b/tests/test_testgres_common.py @@ -421,12 +421,15 @@ def LOCAL__read_id(exec_r) -> int: def test_node_exit(self, node_svc: PostgresNodeService): assert isinstance(node_svc, PostgresNodeService) + base_dir = None + with pytest.raises(expected_exception=QueryException): with __class__.helper__get_node(node_svc).init() as node: base_dir = node.base_dir node.safe_psql('select 1') # we should save the DB for "debugging" + assert type(base_dir) is str assert (node_svc.os_ops.path_exists(base_dir)) node_svc.os_ops.rmdirs(base_dir, ignore_errors=True) @@ -435,6 +438,7 @@ def test_node_exit(self, node_svc: PostgresNodeService): # should have been removed by default assert not (node_svc.os_ops.path_exists(base_dir)) + return def test_double_start(self, node_svc: PostgresNodeService): assert isinstance(node_svc, PostgresNodeService) @@ -754,8 +758,10 @@ def test_reload(self, node_svc: PostgresNodeService): # check new value cmm_new = node.execute('show client_min_messages') + assert cmm_new is not None assert ('debug1' == cmm_new[0][0].lower()) assert (cmm_old != cmm_new) + return def test_pg_ctl(self, node_svc: PostgresNodeService): assert isinstance(node_svc, PostgresNodeService) @@ -764,7 +770,10 @@ def test_pg_ctl(self, node_svc: PostgresNodeService): node.init().start() status = node.pg_ctl(['status']) - assert ('PID' in status) + assert status is not None + assert type(status) is str + assert 'PID' in status + return def test_status(self, node_svc: PostgresNodeService): assert isinstance(node_svc, PostgresNodeService) @@ -1619,15 +1628,26 @@ def test_users(self, node_svc: PostgresNodeService): def test_poll_query_until(self, node_svc: PostgresNodeService): assert isinstance(node_svc, PostgresNodeService) + + def LOCAL__get_col1(rows): + assert rows is not None + assert type(rows) is list + assert len(rows) == 1 + row0 = rows[0] + assert row0 is not None + assert type(row0) in [list, tuple] + assert len(row0) == 1 + return row0[0] + with __class__.helper__get_node(node_svc) as node: node.init().start() get_time = 'select extract(epoch from now())' check_time = 'select extract(epoch from now()) - {} >= 5' - start_time = node.execute(get_time)[0][0] + start_time = LOCAL__get_col1(node.execute(get_time)) node.poll_query_until(query=check_time.format(start_time)) - end_time = node.execute(get_time)[0][0] + end_time = LOCAL__get_col1(node.execute(get_time)) assert (end_time - start_time >= 5) @@ -1773,15 +1793,20 @@ def LOCAL__test_lines(lines: typing.Iterable[str]) -> bool: master.start() logging.info("Master node is restaring...") master.restart() - assert (master._logger.is_alive()) + assert master._logger is not None + assert master._logger.is_alive() finally: # It is a hack code to logging cleanup - with logging._lock: + logging_lock = getattr(logging, "_lock") + assert logging_lock is not None + with logging_lock: assert logging.Logger.manager is not None assert C_NODE_NAME in logging.Logger.manager.loggerDict.keys() logging.Logger.manager.loggerDict.pop(C_NODE_NAME, None) assert C_NODE_NAME not in logging.Logger.manager.loggerDict.keys() - assert handler not in logging._handlers.values() + logging_handlers = getattr(logging, "_handlers") + assert logging_handlers is not None + assert handler not in logging_handlers.values() # GO HOME! return @@ -1873,6 +1898,8 @@ def test_psql__another_bad_host(self, node_svc: PostgresNodeService): res2 = __class__.helper__rm_carriage_returns(res) assert res2[0] != 0 + assert res[2] is not None + assert type(res[2]) is bytes assert b"DUMMY_HOST_NAME" in res[2] def test_safe_psql__another_port(self, node_svc: PostgresNodeService): @@ -3723,19 +3750,40 @@ def helper__skip_test_if_util_not_exist(os_ops: OsOperations, name: str): pytest.skip('might be missing') @staticmethod - def helper__util_exists(os_ops: OsOperations, util): + def helper__util_exists( + os_ops: OsOperations, + util: str, + ) -> bool: assert isinstance(os_ops, OsOperations) - def good_properties(f): - return (os_ops.path_exists(f) and # noqa: W504 - os_ops.isfile(f) and # noqa: W504 - os_ops.is_executable(f)) # yapf: disable + def LOCAL__good_properties(f): + if not os_ops.path_exists(f): + return False + + if not os_ops.isfile(f): + return False + + if not os_ops.is_executable(f): + return False + + return True # try to resolve it - if good_properties(get_bin_path2(os_ops, util)): + if LOCAL__good_properties(get_bin_path2(os_ops, util)): return True # check if util is in PATH - for path in os_ops.environ("PATH").split(os.pathsep): - if good_properties(os.path.join(path, util)): - return True + path = os_ops.environ("PATH") + + if path is None: + return False + + assert path is not None + assert type(path) is str + + for path in path.split(os.pathsep): + if not LOCAL__good_properties(os.path.join(path, util)): + continue + return True + + return False