diff --git a/docs/source/conf.py b/docs/source/conf.py index 4c133a9c..4c91ab5c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -18,9 +18,9 @@ assert testgres.__path__ is not None assert len(testgres.__path__) == 1 -assert type(testgres.__path__[0] == str) # noqa: E721 +assert type(testgres.__path__[0]) is str p = os.path.dirname(testgres.__path__[0]) -assert type(p) == str # noqa: E721 +assert type(p) is str sys.path.insert(0, os.path.abspath(p)) # -- Project information ----------------------------------------------------- diff --git a/src/backup.py b/src/backup.py index 06e6ef2d..6b1b1bc6 100644 --- a/src/backup.py +++ b/src/backup.py @@ -160,7 +160,7 @@ def spawn_primary(self, name=None, destroy=True): node = NodeClass(name=name, base_dir=base_dir, conn_params=self.original_node.os_ops.conn_params) assert node is not None - assert type(node) == self.original_node.__class__ # noqa: E721 + assert type(node) is self.original_node.__class__ with clean_on_error(node) as node: # Set a new port diff --git a/src/cache.py b/src/cache.py index 95ae0a94..72ec5698 100644 --- a/src/cache.py +++ b/src/cache.py @@ -34,7 +34,7 @@ def cached_initdb(data_dir, logfile=None, params=None, os_ops: OsOperations = No def make_utility_path(name): assert name is not None - assert type(name) == str # noqa: E721 + assert type(name) is str if bin_path: return os_ops.build_path(bin_path, name) diff --git a/src/exceptions.py b/src/exceptions.py index a46c12c9..fecc9bc1 100644 --- a/src/exceptions.py +++ b/src/exceptions.py @@ -15,14 +15,14 @@ def __init__( self, message: typing.Optional[str] = None, ): - assert message is None or type(message) == str # noqa: E721 + assert message is None or type(message) is str super().__init__(message) self._message = message return @property def message(self) -> str: - assert self._message is None or type(self._message) == str # noqa: E721 + assert self._message is None or type(self._message) is str if self._message is None: return "" return self._message @@ -53,8 +53,8 @@ def __init__( message: typing.Optional[str] = None, query: typing.Optional[str] = None ): - assert message is None or type(message) == str # noqa: E721 - assert query is None or type(query) == str # noqa: E721 + assert message is None or type(message) is str + assert query is None or type(query) is str super().__init__(message) @@ -64,8 +64,8 @@ def __init__( @property def message(self) -> str: - assert self._description is None or type(self._description) == str # noqa: E721 - assert self._query is None or type(self._query) == str # noqa: E721 + assert self._description is None or type(self._description) is str + assert self._query is None or type(self._query) is str msg = [] @@ -76,17 +76,17 @@ def message(self) -> str: msg.append(u'Query: {}'.format(self._query)) r = six.text_type('\n').join(msg) - assert type(r) == str # noqa: E721 + assert type(r) is str return r @property def description(self) -> typing.Optional[str]: - assert self._description is None or type(self._description) == str # noqa: E721 + assert self._description is None or type(self._description) is str return self._description @property def query(self) -> typing.Optional[str]: - assert self._query is None or type(self._query) == str # noqa: E721 + assert self._query is None or type(self._query) is str return self._query def __repr__(self) -> str: @@ -114,8 +114,8 @@ def __init__( message: typing.Optional[str] = None, query: typing.Optional[str] = None ): - assert message is None or type(message) == str # noqa: E721 - assert query is None or type(query) == str # noqa: E721 + assert message is None or type(message) is str + assert query is None or type(query) is str super().__init__(message, query) return @@ -133,14 +133,14 @@ def __init__( self, message: typing.Optional[str] = None, ): - assert message is None or type(message) == str # noqa: E721 + assert message is None or type(message) is str super().__init__(message) self._message = message return @property def message(self) -> str: - assert self._message is None or type(self._message) == str # noqa: E721 + assert self._message is None or type(self._message) is str if self._message is None: return "" return self._message @@ -171,7 +171,7 @@ def __init__( message: typing.Optional[str] = None, files: typing.Optional[typing.Iterable] = None ): - assert message is None or type(message) == str # noqa: E721 + assert message is None or type(message) is str assert files is None or isinstance(files, typing.Iterable) super().__init__(message) @@ -182,7 +182,7 @@ def __init__( @property def message(self) -> str: - assert self._description is None or type(self._description) == str # noqa: E721 + assert self._description is None or type(self._description) is str assert self._files is None or isinstance(self._files, typing.Iterable) msg = [] @@ -191,7 +191,7 @@ def message(self) -> str: msg.append(self._description) for f, lines in self._files or []: - assert type(f) == str # noqa: E721 + assert type(f) is str assert type(lines) in [str, bytes] # noqa: E721 msg.append(u'{}\n----\n{}\n'.format(f, lines)) @@ -199,7 +199,7 @@ def message(self) -> str: @property def description(self) -> typing.Optional[str]: - assert self._description is None or type(self._description) == str # noqa: E721 + assert self._description is None or type(self._description) is str return self._description @property @@ -233,14 +233,14 @@ def __init__( self, message: typing.Optional[str] = None, ): - assert message is None or type(message) == str # noqa: E721 + assert message is None or type(message) is str super().__init__(message) self._message = message return @property def message(self) -> str: - assert self._message is None or type(self._message) == str # noqa: E721 + assert self._message is None or type(self._message) is str if self._message is None: return "" return self._message @@ -268,14 +268,14 @@ def __init__( self, message: typing.Optional[str] = None, ): - assert message is None or type(message) == str # noqa: E721 + assert message is None or type(message) is str super().__init__(message) self._message = message return @property def message(self) -> str: - assert self._message is None or type(self._message) == str # noqa: E721 + assert self._message is None or type(self._message) is str if self._message is None: return "" return self._message diff --git a/src/impl/internal_utils.py b/src/impl/internal_utils.py index dae7ccd3..6a2275c8 100644 --- a/src/impl/internal_utils.py +++ b/src/impl/internal_utils.py @@ -2,19 +2,19 @@ def send_log(level: int, msg: str) -> None: - assert type(level) == int # noqa: E721 - assert type(msg) == str # noqa: E721 + assert type(level) is int + assert type(msg) is str return logging.log(level, "[testgres] " + msg) def send_log_info(msg: str) -> None: - assert type(msg) == str # noqa: E721 + assert type(msg) is str return send_log(logging.INFO, msg) def send_log_debug(msg: str) -> None: - assert type(msg) == str # noqa: E721 + assert type(msg) is str return send_log(logging.DEBUG, msg) diff --git a/src/impl/platforms/internal_platform_utils.py b/src/impl/platforms/internal_platform_utils.py index 021753f7..6af2b7b0 100644 --- a/src/impl/platforms/internal_platform_utils.py +++ b/src/impl/platforms/internal_platform_utils.py @@ -23,15 +23,15 @@ def __init__( code: InternalPlatformUtils.FindPostmasterResultCode, pid: typing.Optional[int] ): - assert type(code) == InternalPlatformUtils.FindPostmasterResultCode # noqa: E721 - assert pid is None or type(pid) == int # noqa: E721 + assert type(code) is InternalPlatformUtils.FindPostmasterResultCode + assert pid is None or type(pid) is int self.code = code self.pid = pid return @staticmethod def create_ok(pid: int) -> InternalPlatformUtils.FindPostmasterResult: - assert type(pid) == int # noqa: E721 + assert type(pid) is int return __class__(InternalPlatformUtils.FindPostmasterResultCode.ok, pid) @staticmethod @@ -57,6 +57,6 @@ def FindPostmaster( data_dir: str ) -> FindPostmasterResult: assert isinstance(os_ops, OsOperations) - assert type(bin_dir) == str # noqa: E721 - assert type(data_dir) == str # noqa: E721 + assert type(bin_dir) is str + assert type(data_dir) is str raise NotImplementedError("InternalPlatformUtils::FindPostmaster is not implemented.") diff --git a/src/impl/platforms/internal_platform_utils_factory.py b/src/impl/platforms/internal_platform_utils_factory.py index d34fde92..1098185e 100644 --- a/src/impl/platforms/internal_platform_utils_factory.py +++ b/src/impl/platforms/internal_platform_utils_factory.py @@ -9,7 +9,7 @@ def create_internal_platform_utils( assert isinstance(os_ops, OsOperations) platform_name = os_ops.get_platform() - assert type(platform_name) == str # noqa: E721 + assert type(platform_name) is str if platform_name == "linux": from .linux import internal_platform_utils as x diff --git a/src/impl/platforms/linux/internal_platform_utils.py b/src/impl/platforms/linux/internal_platform_utils.py index 86eb197d..b8ca8588 100644 --- a/src/impl/platforms/linux/internal_platform_utils.py +++ b/src/impl/platforms/linux/internal_platform_utils.py @@ -26,10 +26,10 @@ def FindPostmaster( data_dir: str ) -> InternalPlatformUtils.FindPostmasterResult: assert isinstance(os_ops, OsOperations) - assert type(bin_dir) == str # noqa: E721 - assert type(data_dir) == str # noqa: E721 - assert type(__class__.C_BASH_EXE) == str # noqa: E721 - assert type(__class__.sm_exec_env) == dict # noqa: E721 + assert type(bin_dir) is str + assert type(data_dir) is str + assert type(__class__.C_BASH_EXE) is str + assert type(__class__.sm_exec_env) is dict assert len(__class__.C_BASH_EXE) > 0 assert len(bin_dir) > 0 assert len(data_dir) > 0 @@ -37,8 +37,8 @@ def FindPostmaster( pg_path_e = re.escape(os_ops.build_path(bin_dir, "postgres")) data_dir_e = re.escape(data_dir) - assert type(pg_path_e) == str # noqa: E721 - assert type(data_dir_e) == str # noqa: E721 + assert type(pg_path_e) is str + assert type(data_dir_e) is str regexp = r"^\s*[0-9]+\s+" + pg_path_e + r"(\s+.*)?\s+\-[D]\s+" + data_dir_e + r"(\s+.*)?" @@ -55,14 +55,14 @@ def FindPostmaster( exec_env=__class__.sm_exec_env, ) - assert type(output_b) == bytes # noqa: E721 - assert type(error_b) == bytes # noqa: E721 + assert type(output_b) is bytes + assert type(error_b) is bytes output = output_b.decode("utf-8") error = error_b.decode("utf-8") - assert type(output) == str # noqa: E721 - assert type(error) == str # noqa: E721 + assert type(output) is str + assert type(error) is str if exit_status == 1: return __class__.FindPostmasterResult.create_not_found() @@ -78,7 +78,7 @@ def FindPostmaster( ) lines = output.splitlines() - assert type(lines) == list # noqa: E721 + assert type(lines) is list if len(lines) == 0: return __class__.FindPostmasterResult.create_not_found() @@ -88,7 +88,7 @@ def FindPostmaster( msgs.append("Many processes like a postmaster are found: {}.".format(len(lines))) for i in range(len(lines)): - assert type(lines[i]) == str # noqa: E721 + assert type(lines[i]) is str lines.append("[{}] '{}'".format(i, lines[i])) continue @@ -96,7 +96,7 @@ def FindPostmaster( return __class__.FindPostmasterResult.create_many_processes() def is_space_or_tab(ch) -> bool: - assert type(ch) == str # noqa: E721 + assert type(ch) is str return ch == " " or ch == "\t" line = lines[0] @@ -115,6 +115,6 @@ def is_space_or_tab(ch) -> bool: return __class__.FindPostmasterResult.create_has_problems() pid = int(line[start:pos]) - assert type(pid) == int # noqa: E721 + assert type(pid) is int return __class__.FindPostmasterResult.create_ok(pid) diff --git a/src/impl/platforms/win32/internal_platform_utils.py b/src/impl/platforms/win32/internal_platform_utils.py index 661bd234..846950f0 100644 --- a/src/impl/platforms/win32/internal_platform_utils.py +++ b/src/impl/platforms/win32/internal_platform_utils.py @@ -12,6 +12,6 @@ def FindPostmaster( data_dir: str ) -> InternalPlatformUtils.FindPostmasterResult: assert isinstance(os_ops, OsOperations) - assert type(bin_dir) == str # noqa: E721 - assert type(data_dir) == str # noqa: E721 + assert type(bin_dir) is str + assert type(data_dir) is str return __class__.FindPostmasterResult.create_not_implemented() diff --git a/src/impl/port_manager__generic.py b/src/impl/port_manager__generic.py index 6c156992..6b587ec1 100755 --- a/src/impl/port_manager__generic.py +++ b/src/impl/port_manager__generic.py @@ -38,8 +38,8 @@ def __init__(self, os_ops: OsOperations): def reserve_port(self) -> int: assert self._guard is not None - assert type(self._available_ports) == set # noqa: E721t - assert type(self._reserved_ports) == set # noqa: E721 + assert type(self._available_ports) is set + assert type(self._reserved_ports) is set with self._guard: t = tuple(self._available_ports) @@ -48,8 +48,8 @@ def reserve_port(self) -> int: t = None for port in sampled_ports: - assert type(port) == int # noqa: E721 - assert not (port in self._reserved_ports) + assert type(port) is int # noqa: E721 + assert port not in self._reserved_ports assert port in self._available_ports assert port >= __class__._C_MIN_PORT_NUMBER @@ -61,26 +61,26 @@ def reserve_port(self) -> int: self._reserved_ports.add(port) self._available_ports.discard(port) assert port in self._reserved_ports - assert not (port in self._available_ports) + assert port not in self._available_ports __class__.helper__send_debug_msg("Port {} is reserved.", port) return port raise PortForException("Can't select a port.") def release_port(self, number: int) -> None: - assert type(number) == int # noqa: E721 + assert type(number) is int assert number >= __class__._C_MIN_PORT_NUMBER assert number <= __class__._C_MAX_PORT_NUMBER assert self._guard is not None - assert type(self._reserved_ports) == set # noqa: E721 + assert type(self._reserved_ports) is set with self._guard: assert number in self._reserved_ports - assert not (number in self._available_ports) + assert number not in self._available_ports self._available_ports.add(number) self._reserved_ports.discard(number) - assert not (number in self._reserved_ports) + assert number not in self._reserved_ports assert number in self._available_ports __class__.helper__send_debug_msg("Port {} is released.", number) return @@ -89,8 +89,8 @@ def release_port(self, number: int) -> None: def helper__send_debug_msg(msg_template: str, *args) -> None: assert msg_template is not None assert args is not None - assert type(msg_template) == str # noqa: E721 - assert type(args) == tuple # noqa: E721 + assert type(msg_template) is str + assert type(args) is tuple assert msg_template != "" s = "[port manager] " s += msg_template.format(*args) diff --git a/src/impl/port_manager__this_host.py b/src/impl/port_manager__this_host.py index 0d56f356..c7520d80 100755 --- a/src/impl/port_manager__this_host.py +++ b/src/impl/port_manager__this_host.py @@ -15,19 +15,19 @@ def get_single_instance() -> PortManager: assert __class__.sm_single_instance_guard is not None if __class__.sm_single_instance is not None: - assert type(__class__.sm_single_instance) == __class__ # noqa: E721 + assert type(__class__.sm_single_instance) is __class__ return __class__.sm_single_instance with __class__.sm_single_instance_guard: if __class__.sm_single_instance is None: __class__.sm_single_instance = __class__() assert __class__.sm_single_instance is not None - assert type(__class__.sm_single_instance) == __class__ # noqa: E721 + assert type(__class__.sm_single_instance) is __class__ return __class__.sm_single_instance def reserve_port(self) -> int: return utils.reserve_port() def release_port(self, number: int) -> None: - assert type(number) == int # noqa: E721 + assert type(number) is int return utils.release_port(number) diff --git a/src/node.py b/src/node.py index 0b1d3f3e..e40c4385 100644 --- a/src/node.py +++ b/src/node.py @@ -127,14 +127,14 @@ class ProcessProxy(object): def __init__(self, process, ptype: typing.Optional[ProcessType] = None): assert process is not None - assert ptype is None or type(ptype) == ProcessType # noqa: E721 + assert ptype is None or type(ptype) is ProcessType self._process = process if ptype is not None: self._ptype = ptype else: self._ptype = ProcessType.from_process(process) - assert type(self._ptype) == ProcessType # noqa: E721 + assert type(self._ptype) is ProcessType return def __getattr__(self, name): @@ -153,7 +153,7 @@ def process(self) -> typing.Any: @property def ptype(self) -> ProcessType: - assert type(self._ptype) == ProcessType # noqa: E721 + assert type(self._ptype) is ProcessType return self._ptype @@ -190,12 +190,12 @@ def __init__(self, os_ops: None or correct OS operation object. port_manager: None or correct port manager object. """ - assert port is None or type(port) == int # noqa: E721 + assert port is None or type(port) is int assert os_ops is None or isinstance(os_ops, OsOperations) assert port_manager is None or isinstance(port_manager, PortManager) if conn_params is not None: - assert type(conn_params) == ConnectionParams # noqa: E721 + assert type(conn_params) is ConnectionParams raise InvalidOperationException("conn_params is deprecated, please use os_ops parameter instead.") @@ -221,7 +221,7 @@ def __init__(self, self._name = name or generate_app_name() if port is not None: - assert type(port) == int # noqa: E721 + assert type(port) is int assert port_manager is None self._port = port self._should_free_port = False @@ -240,10 +240,10 @@ def __init__(self, assert isinstance(self._port_manager, PortManager) self._port = self._port_manager.reserve_port() # raises - assert type(self._port) == int # noqa: E721 + assert type(self._port) is int self._should_free_port = True - assert type(self._port) == int # noqa: E721 + assert type(self._port) is int # defaults for __exit__() self.cleanup_on_good_exit = testgres_config.node_cleanup_on_good_exit @@ -262,7 +262,7 @@ def __enter__(self): def __exit__(self, type, value, traceback): # NOTE: Ctrl+C does not count! - got_exception = type is not None and type != KeyboardInterrupt + got_exception = type is not None and type is not KeyboardInterrupt c1 = self.cleanup_on_good_exit and not got_exception c2 = self.cleanup_on_bad_exit and got_exception @@ -298,7 +298,7 @@ def _get_port_manager(os_ops: OsOperations) -> PortManager: if os_ops is LocalOperations.get_single_instance(): assert utils._old_port_manager is not None - assert type(utils._old_port_manager) == PortManager__Generic # noqa: E721 + assert type(utils._old_port_manager) is PortManager__Generic assert utils._old_port_manager._os_ops is os_ops return PortManager__ThisHost.get_single_instance() @@ -306,8 +306,8 @@ def _get_port_manager(os_ops: OsOperations) -> PortManager: return PortManager__Generic(os_ops) def clone_with_new_name_and_base_dir(self, name: str, base_dir: str): - assert name is None or type(name) == str # noqa: E721 - assert base_dir is None or type(base_dir) == str # noqa: E721 + assert name is None or type(name) is str + assert base_dir is None or type(base_dir) is str assert __class__ == PostgresNode @@ -344,7 +344,7 @@ def port_manager(self) -> typing.Optional[PortManager]: def name(self) -> str: if self._name is None: raise InvalidOperationException("PostgresNode name is not defined.") - assert type(self._name) == str # noqa: E721 + assert type(self._name) is str return self._name @property @@ -358,7 +358,7 @@ def port(self) -> int: if self._port is None: raise InvalidOperationException("PostgresNode port is not defined.") - assert type(self._port) == int # noqa: E721 + assert type(self._port) is int return self._port @property @@ -374,14 +374,14 @@ def pid(self) -> int: """ x = self._get_node_state() - assert type(x) == utils.PostgresNodeState # noqa: E721 + assert type(x) is utils.PostgresNodeState if x.pid is None: assert x.node_status != NodeStatus.Running return 0 assert x.node_status == NodeStatus.Running - assert type(x.pid) == int # noqa: E721 + assert type(x.pid) is int return x.pid @property @@ -389,7 +389,7 @@ def is_started(self) -> bool: if self._manually_started_pm_pid is None: return False - assert type(self._manually_started_pm_pid) == int # noqa: E721 + assert type(self._manually_started_pm_pid) is int return True @property @@ -401,7 +401,7 @@ def auxiliary_pids(self) -> typing.Dict[ProcessType, typing.List[int]]: result = {} for process in self.auxiliary_processes: - assert type(process) == ProcessProxy # noqa: E721 + assert type(process) is ProcessProxy if process.ptype not in result: result[process.ptype] = [] @@ -416,7 +416,7 @@ def auxiliary_processes(self) -> typing.List[ProcessProxy]: Each process is represented by :class:`.ProcessProxy` object. """ def is_aux(process: ProcessProxy) -> bool: - assert type(process) == ProcessProxy # noqa: E721 + assert type(process) is ProcessProxy return process.ptype != ProcessType.Unknown return list(filter(is_aux, self.child_processes)) @@ -430,8 +430,7 @@ def child_processes(self) -> typing.List[ProcessProxy]: # get a list of postmaster's children x = self._get_node_state() - assert type(x) == utils.PostgresNodeState # noqa: E721 - + assert type(x) is utils.PostgresNodeState if x.pid is None: assert x.node_status != NodeStatus.Running RaiseError.node_err__cant_enumerate_child_processes( @@ -439,11 +438,11 @@ def child_processes(self) -> typing.List[ProcessProxy]: ) assert x.node_status == NodeStatus.Running - assert type(x.pid) == int # noqa: E721 + assert type(x.pid) is int return self._get_child_processes(x.pid) def _get_child_processes(self, pid: int) -> typing.List[ProcessProxy]: - assert type(pid) == int # noqa: E721 + assert type(pid) is int assert isinstance(self._os_ops, OsOperations) # get a list of postmaster's children @@ -466,7 +465,7 @@ def source_walsender(self): if self.master is None: raise TestgresException("Node doesn't have a master") - assert type(self.master) == PostgresNode # noqa: E721 + assert type(self.master) is PostgresNode # master should be on the same host assert self.master.host == self.host @@ -507,7 +506,7 @@ def logs_dir(self): assert isinstance(self._os_ops, OsOperations) path = self._os_ops.build_path(self.base_dir, LOGS_DIR) - assert type(path) == str # noqa: E721 + assert type(path) is str # NOTE: it's safe to create a new dir if not self.os_ops.path_exists(path): @@ -522,7 +521,7 @@ def data_dir(self): # NOTE: we can't run initdb without user's args path = self._os_ops.build_path(self.base_dir, DATA_DIR) - assert type(path) == str # noqa: E721 + assert type(path) is str return path @property @@ -531,7 +530,7 @@ def utils_log_file(self): assert isinstance(self._os_ops, OsOperations) path = self._os_ops.build_path(self.logs_dir, UTILS_LOG_FILE) - assert type(path) == str # noqa: E721 + assert type(path) is str return path @property @@ -540,7 +539,7 @@ def pg_log_file(self): assert isinstance(self._os_ops, OsOperations) path = self._os_ops.build_path(self.logs_dir, PG_LOG_FILE) - assert type(path) == str # noqa: E721 + assert type(path) is str return path @property @@ -554,8 +553,8 @@ def version(self): return self._pg_version def _try_shutdown(self, max_attempts, with_force=False): - assert type(max_attempts) == int # noqa: E721 - assert type(with_force) == bool # noqa: E721 + assert type(max_attempts) is int + assert type(with_force) is bool assert max_attempts > 0 attempts = 0 @@ -579,7 +578,7 @@ def _try_shutdown(self, max_attempts, with_force=False): node_pid = self.pid assert node_pid is not None - assert type(node_pid) == int # noqa: E721 + assert type(node_pid) is int if node_pid == 0: return @@ -589,7 +588,7 @@ def _try_shutdown(self, max_attempts, with_force=False): ps_command = ['ps', '-o', 'pid=', '-p', str(node_pid)] ps_output = self.os_ops.exec_command(cmd=ps_command, shell=True, ignore_errors=True).decode('utf-8') - assert type(ps_output) == str # noqa: E721 + assert type(ps_output) is str if ps_output == "": return @@ -608,7 +607,7 @@ def _try_shutdown(self, max_attempts, with_force=False): # Check that node stopped - print only column pid without headers ps_output = self.os_ops.exec_command(cmd=ps_command, shell=True, ignore_errors=True).decode('utf-8') - assert type(ps_output) == str # noqa: E721 + assert type(ps_output) is str if ps_output == "": eprint('Node {0} has been stopped successfully.'.format(self.name)) @@ -624,8 +623,8 @@ def _try_shutdown(self, max_attempts, with_force=False): @staticmethod def _throw_bugcheck__unexpected_result_of_ps(result, cmd): - assert type(result) == str # noqa: E721 - assert type(cmd) == list # noqa: E721 + assert type(result) is str + assert type(cmd) is list errLines = [] errLines.append("[BUG CHECK] Unexpected result of command ps:") errLines.append(result) @@ -669,7 +668,7 @@ def _create_recovery_conf(self, username, slot=None): assert isinstance(self._os_ops, OsOperations) signal_name = self._os_ops.build_path(self.data_dir, "standby.signal") - assert type(signal_name) == str # noqa: E721 + assert type(signal_name) is str self.os_ops.touch(signal_name) else: line += "standby_mode=on\n" @@ -928,7 +927,7 @@ def status(self): An instance of :class:`.NodeStatus`. """ x = self._get_node_state() - assert type(x) == utils.PostgresNodeState # noqa: E721 + assert type(x) is utils.PostgresNodeState return x.node_status def _get_node_state(self) -> utils.PostgresNodeState: @@ -972,7 +971,7 @@ def slow_start(self, replica=False, dbname='template1', username=None, max_attem If False, waits for the instance to be in primary mode. Default is False. max_attempts: """ - assert exec_env is None or type(exec_env) == dict # noqa: E721 + assert exec_env is None or type(exec_env) is dict self.start(exec_env=exec_env) @@ -1021,9 +1020,9 @@ def start( Returns: This instance of :class:`.PostgresNode`. """ - assert params is None or type(params) == list # noqa: E721 - assert type(wait) == bool # noqa: E721 - assert exec_env is None or type(exec_env) == dict # noqa: E721 + assert params is None or type(params) is list + assert type(wait) is bool + assert exec_env is None or type(exec_env) is dict self._start(params, wait, exec_env) @@ -1035,7 +1034,7 @@ def start( if self._manually_started_pm_pid is None: self._raise_cannot_start_node(None, "Cannot detect postmaster pid.") - assert type(self._manually_started_pm_pid) == int # noqa: E721 + assert type(self._manually_started_pm_pid) is int return self def start2( @@ -1057,9 +1056,9 @@ def start2( Returns: None. """ - assert params is None or type(params) == list # noqa: E721 - assert type(wait) == bool # noqa: E721 - assert exec_env is None or type(exec_env) == dict # noqa: E721 + assert params is None or type(params) is list + assert type(wait) is bool + assert exec_env is None or type(exec_env) is dict self._start(params, wait, exec_env) return @@ -1070,16 +1069,16 @@ def _start( wait: bool = True, exec_env: typing.Optional[typing.Dict] = None, ) -> None: - assert params is None or type(params) == list # noqa: E721 - assert type(wait) == bool # noqa: E721 - assert exec_env is None or type(exec_env) == dict # noqa: E721 + assert params is None or type(params) is list + assert type(wait) is bool + assert exec_env is None or type(exec_env) is dict assert __class__._C_MAX_START_ATEMPTS > 1 if self._port is None: raise InvalidOperationException("Can't start PostgresNode. Port is not defined.") - assert type(self._port) == int # noqa: E721 + assert type(self._port) is int _params = [ self._get_bin_path("pg_ctl"), @@ -1090,13 +1089,13 @@ def _start( ] if params is not None: - assert type(params) == list # noqa: E721 + assert type(params) is list _params += params def LOCAL__start_node(): # 'error' will be None on Windows _, _, error = execute_utility2(self.os_ops, _params, self.utils_log_file, verbose=True, exec_env=exec_env) - assert error is None or type(error) == str # noqa: E721 + assert error is None or type(error) is str if error and 'does not exist' in error: raise Exception(error) @@ -1162,7 +1161,7 @@ def _raise_cannot_start_node( msg: str ): assert from_exception is None or isinstance(from_exception, Exception) - assert type(msg) == str # noqa: E721 + assert type(msg) is str files = self._collect_special_files() raise_from(StartNodeException(msg, files), from_exception) @@ -1200,14 +1199,14 @@ def kill(self, someone=None): If None, the main PostgreSQL node process will be killed. Defaults to None. """ x = self._get_node_state() - assert type(x) == utils.PostgresNodeState # noqa: E721 + assert type(x) is utils.PostgresNodeState if x.node_status != NodeStatus.Running: RaiseError.node_err__cant_kill(x.node_status) assert False assert x.node_status == NodeStatus.Running - assert type(x.pid) == int # noqa: E721 + assert type(x.pid) is int sig = signal.SIGKILL if os.name != 'nt' else signal.SIGBREAK if someone is None: self._os_ops.kill(x.pid, sig) @@ -1215,7 +1214,7 @@ def kill(self, someone=None): else: childs = self._get_child_processes(x.pid) for c in childs: - assert type(c) == ProcessProxy # noqa: E721 + assert type(c) is ProcessProxy if c.ptype == someone: self._os_ops.kill(c.process.pid, sig) continue @@ -1402,9 +1401,9 @@ def psql(self, >>> psql(query='select 3', ON_ERROR_STOP=1) """ - assert host is None or type(host) == str # noqa: E721 - assert port is None or type(port) == int # noqa: E721 - assert type(variables) == dict # noqa: E721 + assert host is None or type(host) is str + assert port is None or type(port) is int + assert type(variables) is dict return self._psql( ignore_errors=True, @@ -1429,16 +1428,16 @@ def _psql( host: typing.Optional[str] = None, port: typing.Optional[int] = None, **variables): - assert host is None or type(host) == str # noqa: E721 - assert port is None or type(port) == int # noqa: E721 - assert type(variables) == dict # noqa: E721 + assert host is None or type(host) is str + assert port is None or type(port) is int + assert type(variables) is dict # # We do not support encoding. It may be added later. Ok? # if input is None: pass - elif type(input) == bytes: # noqa: E721 + elif type(input) is bytes: pass else: raise Exception("Input data must be None or bytes.") @@ -1451,8 +1450,8 @@ def _psql( assert host is not None assert port is not None - assert type(host) == str # noqa: E721 - assert type(port) == int # noqa: E721 + assert type(host) is str + assert type(port) is int psql_params = [ self._get_bin_path("psql"), @@ -1505,9 +1504,9 @@ def safe_psql(self, query=None, expect_error=False, **kwargs): Returns: psql's output as str. """ - assert type(kwargs) == dict # noqa: E721 - assert not ("ignore_errors" in kwargs.keys()) - assert not ("expect_error" in kwargs.keys()) + assert type(kwargs) is dict + assert "ignore_errors" not in kwargs.keys() + assert "expect_error" not in kwargs.keys() # force this setting kwargs['ON_ERROR_STOP'] = 1 @@ -1517,7 +1516,7 @@ def safe_psql(self, query=None, expect_error=False, **kwargs): if not expect_error: raise QueryException(e.message, query) - if type(e.error) == bytes: # noqa: E721 + if type(e.error) is bytes: return e.error.decode("utf-8") # throw # [2024-12-09] This situation is not expected @@ -1647,7 +1646,7 @@ def poll_query_until(self, """ # sanity checks - assert type(max_attempts) == int # noqa: E721 + assert type(max_attempts) is int assert max_attempts >= 0 assert type(sleep_time) in [int, float] assert sleep_time > 0 @@ -1999,20 +1998,20 @@ def table_checksum( table: str, dbname: str = "postgres" ) -> int: - assert type(table) == str # noqa: E721 - assert type(dbname) == str # noqa: E721 + assert type(table) is str + assert type(dbname) is str cn = self.connect(dbname=dbname) - assert type(cn) == NodeConnection # noqa: E721 + assert type(cn) is NodeConnection try: sum = __class__._table_checksum__use_cn(cn, table) - assert type(sum) == int # noqa: E721 + assert type(sum) is int finally: - assert type(cn) == NodeConnection # noqa: E721 + assert type(cn) is NodeConnection cn.close() - assert type(sum) == int # noqa: E721 + assert type(sum) is int return sum sm_pgbench_tables = [ @@ -2027,13 +2026,13 @@ def pgbench_table_checksums( dbname: str = "postgres", pgbench_tables: typing.Iterable[str] = sm_pgbench_tables ) -> typing.Set[typing.Tuple[str, int]]: - assert type(dbname) == str # noqa: E721 + assert type(dbname) is str r1 = self._tables_checksum(dbname, pgbench_tables) - assert type(r1) == list # noqa: E721 + assert type(r1) is list r2 = set(r1) - assert type(r2) == set # noqa: E721 + assert type(r2) is set return r2 def set_auto_conf(self, options, config='postgresql.auto.conf', rm_options={}): @@ -2083,16 +2082,16 @@ def set_auto_conf(self, options, config='postgresql.auto.conf', rm_options={}): current_options[name] = var for option in options: - assert type(option) == str # noqa: E721 + assert type(option) is str assert option != "" assert option.strip() == option value = options[option] valueType = type(value) - if valueType == str: + if valueType is str: value = __class__._escape_config_value(value) - elif valueType == bool: + elif valueType is bool: value = "on" if value else "off" current_options[option] = value @@ -2145,12 +2144,12 @@ def _release_resources(self): self._free_port() def _free_port(self): - assert type(self._should_free_port) == bool # noqa: E721 + assert type(self._should_free_port) is bool if not self._should_free_port: self._port = None else: - assert type(self._port) == int # noqa: E721 + assert type(self._port) is int assert self._port_manager is not None assert isinstance(self._port_manager, PortManager) @@ -2172,7 +2171,7 @@ def _get_bin_path(self, filename): @staticmethod def _escape_config_value(value): - assert type(value) == str # noqa: E721 + assert type(value) is str result = "'" @@ -2201,28 +2200,28 @@ def _tables_checksum( tables: typing.Iterable[str], ) -> typing.List[typing.Tuple[str, int]]: assert isinstance(tables, typing.Iterable) - assert type(dbname) == str # noqa: E721 + assert type(dbname) is str result = [] cn = self.connect(dbname=dbname) - assert type(cn) == NodeConnection # noqa: E721 + assert type(cn) is NodeConnection try: cn.begin() for table in tables: - assert type(table) == str # noqa: E721 + assert type(table) is str sum = __class__._table_checksum__use_cn(cn, table) - assert type(sum) == int # noqa: E721 + assert type(sum) is int result.append((table, sum)) cn.commit() finally: - assert type(cn) == NodeConnection # noqa: E721 + assert type(cn) is NodeConnection cn.close() - assert type(result) == list # noqa: E721 + assert type(result) is list return result @staticmethod @@ -2230,8 +2229,8 @@ def _table_checksum__use_cn( cn: NodeConnection, table: str, ) -> int: - assert type(cn) == NodeConnection # noqa: E721 - assert type(table) == str # noqa: E721 + assert type(cn) is NodeConnection + assert type(table) is str sum = 0 @@ -2252,7 +2251,7 @@ def _table_checksum__use_cn( finally: cursor.close() - assert type(sum) == int # noqa: E721 + assert type(sum) is int return sum @staticmethod @@ -2291,9 +2290,9 @@ def __init__( position: int, data: str ): - assert type(file_name) == str # noqa: E721 - assert type(position) == int # noqa: E721 - assert type(data) == str # noqa: E721 + assert type(file_name) is str + assert type(position) is int + assert type(data) is str assert file_name != "" assert position >= 0 self._file_name = file_name @@ -2302,19 +2301,19 @@ def __init__( @property def file_name(self) -> str: - assert type(self._file_name) == str # noqa: E721 + assert type(self._file_name) is str assert self._file_name != "" return self._file_name @property def position(self) -> int: - assert type(self._position) == int # noqa: E721 + assert type(self._position) is int assert self._position >= 0 return self._position @property def data(self) -> str: - assert type(self._data) == str # noqa: E721 + assert type(self._data) is str return self._data # -------------------------------------------------------------------- @@ -2325,7 +2324,7 @@ def data(self) -> str: def __init__(self, node: PostgresNode, from_beginnig: bool): assert node is not None assert isinstance(node, PostgresNode) - assert type(from_beginnig) == bool # noqa: E721 + assert type(from_beginnig) is bool self._node = node @@ -2334,7 +2333,7 @@ def __init__(self, node: PostgresNode, from_beginnig: bool): else: self._logs = self._collect_logs() - assert type(self._logs) == dict # noqa: E721 + assert type(self._logs) is dict return def read(self) -> typing.List[LogDataBlock]: @@ -2343,31 +2342,31 @@ def read(self) -> typing.List[LogDataBlock]: cur_logs: typing.Dict[str, __class__.LogInfo] = self._collect_logs() assert cur_logs is not None - assert type(cur_logs) == dict # noqa: E721 + assert type(cur_logs) is dict - assert type(self._logs) == dict # noqa: E721 + assert type(self._logs) is dict result = list() for file_name, cur_log_info in cur_logs.items(): - assert type(file_name) == str # noqa: E721 - assert type(cur_log_info) == __class__.LogInfo # noqa: E721 + assert type(file_name) is str + assert type(cur_log_info) is __class__.LogInfo read_pos = 0 if file_name in self._logs.keys(): prev_log_info = self._logs[file_name] - assert type(prev_log_info) == __class__.LogInfo # noqa: E721 + assert type(prev_log_info) is __class__.LogInfo read_pos = prev_log_info.position # the previous size file_content_b = self._node.os_ops.read_binary(file_name, read_pos) - assert type(file_content_b) == bytes # noqa: E721 + assert type(file_content_b) is bytes # # A POTENTIAL PROBLEM: file_content_b may contain an incompleted UTF-8 symbol. # file_content_s = file_content_b.decode() - assert type(file_content_s) == str # noqa: E721 + assert type(file_content_s) is str next_read_pos = read_pos + len(file_content_b) @@ -2401,14 +2400,14 @@ def _collect_logs(self) -> typing.Dict[str, LogInfo]: result = dict() for f in files: - assert type(f) == str # noqa: E721 + assert type(f) is str # skip missing files if not self._node.os_ops.path_exists(f): continue file_size = self._node.os_ops.get_file_size(f) - assert type(file_size) == int # noqa: E721 + assert type(file_size) is int assert file_size >= 0 result[f] = __class__.LogInfo(file_size) @@ -2419,13 +2418,13 @@ def _collect_logs(self) -> typing.Dict[str, LogInfo]: class PostgresNodeUtils: @staticmethod def delect_port_conflict(log_reader: PostgresNodeLogReader) -> bool: - assert type(log_reader) == PostgresNodeLogReader # noqa: E721 + assert type(log_reader) is PostgresNodeLogReader blocks = log_reader.read() - assert type(blocks) == list # noqa: E721 + assert type(blocks) is list for block in blocks: - assert type(block) == PostgresNodeLogReader.LogDataBlock # noqa: E721 + assert type(block) is PostgresNodeLogReader.LogDataBlock if 'Is another postmaster already running on port' in block.data: return True diff --git a/src/node_app.py b/src/node_app.py index 479b92b9..27334f8a 100644 --- a/src/node_app.py +++ b/src/node_app.py @@ -26,7 +26,7 @@ def __init__( os_ops: typing.Optional[OsOperations] = None, port_manager: typing.Optional[PortManager] = None, ): - assert test_path is None or type(test_path) == str # noqa: E721 + assert test_path is None or type(test_path) is str assert os_ops is None or isinstance(os_ops, OsOperations) assert port_manager is None or isinstance(port_manager, PortManager) @@ -51,7 +51,7 @@ def __init__( @property def test_path(self) -> str: - assert type(self._test_path) == str # noqa: E721 + assert type(self._test_path) is str return self._test_path @property @@ -66,7 +66,7 @@ def port_manager(self) -> PortManager: @property def nodes_to_cleanup(self) -> typing.List[PostgresNode]: - assert type(self._nodes_to_cleanup) == list # noqa: E721 + assert type(self._nodes_to_cleanup) is list return self._nodes_to_cleanup def make_empty( @@ -75,12 +75,12 @@ def make_empty( port: typing.Optional[int] = None, bin_dir: typing.Optional[str] = None ) -> PostgresNode: - assert type(base_dir) == str # noqa: E721 - assert port is None or type(port) == int # noqa: E721 - assert bin_dir is None or type(bin_dir) == str # noqa: E721 + assert type(base_dir) is str + assert port is None or type(port) is int + assert bin_dir is None or type(bin_dir) is str assert isinstance(self._os_ops, OsOperations) - assert type(self._test_path) == str # noqa: E721 + assert type(self._test_path) is str if base_dir is None: raise ValueError("Argument 'base_dir' is not defined.") @@ -106,7 +106,7 @@ def make_empty( ) try: - assert type(self._nodes_to_cleanup) == list # noqa: E721 + assert type(self._nodes_to_cleanup) is list self._nodes_to_cleanup.append(node) except: # noqa: E722 node.cleanup(release_resources=True) @@ -125,14 +125,14 @@ def make_simple( checksum: bool = True, bin_dir: typing.Optional[str] = None ) -> PostgresNode: - assert type(base_dir) == str # noqa: E721 - assert port is None or type(port) == int # noqa: E721 - assert type(set_replication) == bool # noqa: E721 - assert type(ptrack_enable) == bool # noqa: E721 - assert initdb_params is None or type(initdb_params) == list # noqa: E721 - assert pg_options is None or type(pg_options) == dict # noqa: E721 - assert type(checksum) == bool # noqa: E721 - assert bin_dir is None or type(bin_dir) == str # noqa: E721 + assert type(base_dir) is str + assert port is None or type(port) is int + assert type(set_replication) is bool + assert type(ptrack_enable) is bool + assert initdb_params is None or type(initdb_params) is list + assert pg_options is None or type(pg_options) is dict + assert type(checksum) is bool + assert bin_dir is None or type(bin_dir) is str node = self.make_empty( base_dir, @@ -194,12 +194,12 @@ def make_simple( # Apply given parameters if pg_options is not None: - assert type(pg_options) == dict # noqa: E721 + assert type(pg_options) is dict for option_name, option_value in pg_options.items(): options[option_name] = option_value # Define delayed propertyes - if not ("unix_socket_directories" in options.keys()): + if "unix_socket_directories" not in options.keys(): options["unix_socket_directories"] = __class__._gettempdir_for_socket() # Set config values @@ -218,17 +218,14 @@ def _paramlist_has_param( params: typing.Optional[T_LIST_STR], param: str ) -> bool: - assert type(param) == str # noqa: E721 + assert type(param) is str if params is None: return False - assert type(params) == list # noqa: E721 + assert type(params) is list - if param in params: - return True - - return False + return param in params @staticmethod def _paramlist_append( @@ -236,9 +233,9 @@ def _paramlist_append( updated_params: typing.Optional[T_LIST_STR], param: str, ) -> T_LIST_STR: - assert user_params is None or type(user_params) == list # noqa: E721 - assert updated_params is None or type(updated_params) == list # noqa: E721 - assert type(param) == str # noqa: E721 + assert user_params is None or type(user_params) is list + assert updated_params is None or type(updated_params) is list + assert type(param) is str if updated_params is None: if user_params is None: @@ -298,7 +295,7 @@ def _gettempdir() -> str: # # Paranoid checks # - if type(v) != str: # noqa: E721 + if type(v) is str: __class__._raise_bugcheck("tempfile.gettempdir returned a value with type {0}.".format(type(v).__name__)) if v == "": @@ -312,6 +309,6 @@ def _gettempdir() -> str: @staticmethod def _raise_bugcheck(msg): - assert type(msg) == str # noqa: E721 + assert type(msg) is str assert msg != "" raise Exception("[BUG CHECK] " + msg) diff --git a/src/port_manager.py b/src/port_manager.py index 1ae696c8..c003a038 100644 --- a/src/port_manager.py +++ b/src/port_manager.py @@ -6,5 +6,5 @@ def reserve_port(self) -> int: raise NotImplementedError("PortManager::reserve_port is not implemented.") def release_port(self, number: int) -> None: - assert type(number) == int # noqa: E721 + assert type(number) is int raise NotImplementedError("PortManager::release_port is not implemented.") diff --git a/src/raise_error.py b/src/raise_error.py index 919cd353..61c5e43a 100644 --- a/src/raise_error.py +++ b/src/raise_error.py @@ -34,7 +34,7 @@ def pg_ctl_returns_a_zero_pid(out, _params): def node_err__cant_enumerate_child_processes( node_status: NodeStatus ): - assert type(node_status) == NodeStatus # noqa: E721 + assert type(node_status) is NodeStatus msg = "Can't enumerate node child processes. {}.".format( __class__._map_node_status_to_reason( @@ -49,7 +49,7 @@ def node_err__cant_enumerate_child_processes( def node_err__cant_kill( node_status: NodeStatus ): - assert type(node_status) == NodeStatus # noqa: E721 + assert type(node_status) is NodeStatus msg = "Can't kill server process. {}.".format( __class__._map_node_status_to_reason( @@ -65,8 +65,8 @@ def _map_node_status_to_reason( node_status: NodeStatus, node_pid: typing.Optional[int], ) -> str: - assert type(node_status) == NodeStatus # noqa: E721 - assert node_pid is None or type(node_pid) == int # noqa: E721 + assert type(node_status) is NodeStatus + assert node_pid is None or type(node_pid) is int if node_status == NodeStatus.Uninitialized: return "Node is not initialized" diff --git a/src/utils.py b/src/utils.py index dd9268de..6ff43770 100644 --- a/src/utils.py +++ b/src/utils.py @@ -65,7 +65,7 @@ def internal__release_port(port): Free port provided by reserve_port(). """ - assert type(port) == int # noqa: E721 + assert type(port) is int return _old_port_manager.release_port(port) @@ -97,9 +97,9 @@ def execute_utility2( ): assert os_ops is not None assert isinstance(os_ops, OsOperations) - assert type(verbose) == bool # noqa: E721 - assert type(ignore_errors) == bool # noqa: E721 - assert exec_env is None or type(exec_env) == dict # noqa: E721 + assert type(verbose) is bool + assert type(ignore_errors) is bool + assert exec_env is None or type(exec_env) is dict exit_status, out, error = os_ops.exec_command( args, @@ -243,7 +243,7 @@ def get_pg_version2(os_ops: OsOperations, bin_dir=None): postgres_path = get_bin_path2(os_ops, C_POSTGRES_BINARY) else: # [2025-06-25] OK ? - assert type(bin_dir) == str # noqa: E721 + assert type(bin_dir) is str assert bin_dir != "" postgres_path = os_ops.build_path(bin_dir, 'postgres') @@ -335,8 +335,8 @@ def __init__( node_status: NodeStatus, pid: typing.Optional[int] ): - assert type(node_status) == NodeStatus # noqa: E721 - assert pid is None or type(pid) == int # noqa: E721 + assert type(node_status) is NodeStatus + assert pid is None or type(pid) is int self.node_status = node_status self.pid = pid @@ -350,9 +350,9 @@ def get_pg_node_state( utils_log_file: typing.Optional[str], ) -> PostgresNodeState: assert isinstance(os_ops, OsOperations) - assert type(bin_dir) == str # noqa: E721 - assert type(data_dir) == str # noqa: E721 - assert utils_log_file is None or type(utils_log_file) == str # noqa: E721 + assert type(bin_dir) is str + assert type(data_dir) is str + assert utils_log_file is None or type(utils_log_file) is str C_MAX_ATTEMPTS = 3 C_SLEEP_TIME1 = 1 @@ -371,7 +371,7 @@ def get_pg_node_state( platform_utils: typing.Optional[internal_platform_utils_factory.InternalPlatformUtils] = None while True: - assert type(attempt) == int # noqa: E721 + assert type(attempt) is int assert attempt >= 0 assert attempt < C_MAX_ATTEMPTS @@ -393,9 +393,9 @@ def get_pg_node_state( ignore_errors=True, ) - assert type(status_code) == int # noqa: E721 - assert type(out) == str # noqa: E721 - assert type(error) == str # noqa: E721 + assert type(status_code) is int + assert type(out) is str + assert type(error) is str # ----------------- if status_code == PG_CTL__STATUS__NODE_IS_STOPPED: @@ -516,7 +516,7 @@ def get_pg_node_state( e2.__cause__ = e1 raise e2 - assert type(find_postmaster_r) == internal_platform_utils_factory.InternalPlatformUtils.FindPostmasterResult # noqa: E721 + assert type(find_postmaster_r) is internal_platform_utils_factory.InternalPlatformUtils.FindPostmasterResult if find_postmaster_r.code == internal_platform_utils_factory.InternalPlatformUtils.FindPostmasterResultCode.ok: # Postmaster is alive. Let's wait a few seconds and check its status again. diff --git a/tests/conftest.py b/tests/conftest.py index 19300579..22841a41 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -103,14 +103,14 @@ def CalcRootLogDir() -> str: rootDir = __class__.CalcRootDir() resultPath = os.path.join(rootDir, "logs") - assert type(resultPath) == str # noqa: E721 + assert type(resultPath) is str return resultPath # -------------------------------------------------------------------- @staticmethod def CalcCurrentTestWorkerSignature() -> str: currentPID = os.getpid() - assert type(currentPID) == int # noqa: E721 + assert type(currentPID) is int startTS = __class__.sm_StartTS assert type(startTS) == datetime.datetime # noqa: E721 @@ -148,19 +148,19 @@ class TestStartupData: # -------------------------------------------------------------------- @staticmethod def GetRootDir() -> str: - assert type(__class__.sm_RootDir) == str # noqa: E721 + assert type(__class__.sm_RootDir) is str return __class__.sm_RootDir # -------------------------------------------------------------------- @staticmethod def GetRootLogDir() -> str: - assert type(__class__.sm_RootLogDir) == str # noqa: E721 + assert type(__class__.sm_RootLogDir) is str return __class__.sm_RootLogDir # -------------------------------------------------------------------- @staticmethod def GetCurrentTestWorkerSignature() -> str: - assert type(__class__.sm_CurrentTestWorkerSignature) == str # noqa: E721 + assert type(__class__.sm_CurrentTestWorkerSignature) is str return __class__.sm_CurrentTestWorkerSignature @@ -195,7 +195,7 @@ class TEST_PROCESS_STATS: # -------------------------------------------------------------------- @staticmethod def incrementTotalTestCount() -> None: - assert type(__class__.cTotalTests) == int # noqa: E721 + assert type(__class__.cTotalTests) is int assert __class__.cTotalTests >= 0 __class__.cTotalTests += 1 @@ -205,7 +205,7 @@ def incrementTotalTestCount() -> None: # -------------------------------------------------------------------- @staticmethod def incrementNotExecutedTestCount() -> None: - assert type(__class__.cNotExecutedTests) == int # noqa: E721 + assert type(__class__.cNotExecutedTests) is int assert __class__.cNotExecutedTests >= 0 __class__.cNotExecutedTests += 1 @@ -215,7 +215,7 @@ def incrementNotExecutedTestCount() -> None: # -------------------------------------------------------------------- @staticmethod def incrementExecutedTestCount() -> int: - assert type(__class__.cExecutedTests) == int # noqa: E721 + assert type(__class__.cExecutedTests) is int assert __class__.cExecutedTests >= 0 __class__.cExecutedTests += 1 @@ -226,7 +226,7 @@ def incrementExecutedTestCount() -> int: # -------------------------------------------------------------------- @staticmethod def incrementPassedTestCount() -> None: - assert type(__class__.cPassedTests) == int # noqa: E721 + assert type(__class__.cPassedTests) is int assert __class__.cPassedTests >= 0 __class__.cPassedTests += 1 @@ -236,11 +236,11 @@ def incrementPassedTestCount() -> None: # -------------------------------------------------------------------- @staticmethod def incrementFailedTestCount(testID: str, errCount: int) -> None: - assert type(testID) == str # noqa: E721 - assert type(errCount) == int # noqa: E721 + assert type(testID) is str + assert type(errCount) is int assert errCount > 0 - assert type(__class__.FailedTests) == list # noqa: E721 - assert type(__class__.cFailedTests) == int # noqa: E721 + assert type(__class__.FailedTests) is list + assert type(__class__.cFailedTests) is int assert __class__.cFailedTests >= 0 __class__.FailedTests.append((testID, errCount)) # raise? @@ -251,7 +251,7 @@ def incrementFailedTestCount(testID: str, errCount: int) -> None: assert len(__class__.FailedTests) == __class__.cFailedTests # -------- - assert type(__class__.cTotalErrors) == int # noqa: E721 + assert type(__class__.cTotalErrors) is int assert __class__.cTotalErrors >= 0 __class__.cTotalErrors += errCount @@ -261,11 +261,11 @@ def incrementFailedTestCount(testID: str, errCount: int) -> None: # -------------------------------------------------------------------- @staticmethod def incrementXFailedTestCount(testID: str, errCount: int) -> None: - assert type(testID) == str # noqa: E721 - assert type(errCount) == int # noqa: E721 + assert type(testID) is str + assert type(errCount) is int assert errCount >= 0 - assert type(__class__.XFailedTests) == list # noqa: E721 - assert type(__class__.cXFailedTests) == int # noqa: E721 + assert type(__class__.XFailedTests) is list + assert type(__class__.cXFailedTests) is int assert __class__.cXFailedTests >= 0 __class__.XFailedTests.append((testID, errCount)) # raise? @@ -278,7 +278,7 @@ def incrementXFailedTestCount(testID: str, errCount: int) -> None: # -------------------------------------------------------------------- @staticmethod def incrementSkippedTestCount() -> None: - assert type(__class__.cSkippedTests) == int # noqa: E721 + assert type(__class__.cSkippedTests) is int assert __class__.cSkippedTests >= 0 __class__.cSkippedTests += 1 @@ -288,9 +288,9 @@ def incrementSkippedTestCount() -> None: # -------------------------------------------------------------------- @staticmethod def incrementNotXFailedTests(testID: str) -> None: - assert type(testID) == str # noqa: E721 - assert type(__class__.NotXFailedTests) == list # noqa: E721 - assert type(__class__.cNotXFailedTests) == int # noqa: E721 + assert type(testID) is str + assert type(__class__.NotXFailedTests) is list + assert type(__class__.cNotXFailedTests) is int assert __class__.cNotXFailedTests >= 0 __class__.NotXFailedTests.append(testID) # raise? @@ -303,12 +303,12 @@ def incrementNotXFailedTests(testID: str) -> None: # -------------------------------------------------------------------- @staticmethod def incrementWarningTestCount(testID: str, warningCount: int) -> None: - assert type(testID) == str # noqa: E721 - assert type(warningCount) == int # noqa: E721 + assert type(testID) is str + assert type(warningCount) is int assert testID != "" assert warningCount > 0 - assert type(__class__.WarningTests) == list # noqa: E721 - assert type(__class__.cWarningTests) == int # noqa: E721 + assert type(__class__.WarningTests) is list + assert type(__class__.cWarningTests) is int assert __class__.cWarningTests >= 0 __class__.WarningTests.append((testID, warningCount)) # raise? @@ -319,7 +319,7 @@ def incrementWarningTestCount(testID: str, warningCount: int) -> None: assert len(__class__.WarningTests) == __class__.cWarningTests # -------- - assert type(__class__.cTotalWarnings) == int # noqa: E721 + assert type(__class__.cTotalWarnings) is int assert __class__.cTotalWarnings >= 0 __class__.cTotalWarnings += warningCount @@ -329,7 +329,7 @@ def incrementWarningTestCount(testID: str, warningCount: int) -> None: # -------------------------------------------------------------------- @staticmethod def incrementUnexpectedTests() -> None: - assert type(__class__.cUnexpectedTests) == int # noqa: E721 + assert type(__class__.cUnexpectedTests) is int assert __class__.cUnexpectedTests >= 0 __class__.cUnexpectedTests += 1 @@ -339,9 +339,9 @@ def incrementUnexpectedTests() -> None: # -------------------------------------------------------------------- @staticmethod def incrementAchtungTestCount(testID: str) -> None: - assert type(testID) == str # noqa: E721 - assert type(__class__.AchtungTests) == list # noqa: E721 - assert type(__class__.cAchtungTests) == int # noqa: E721 + assert type(testID) is str + assert type(__class__.AchtungTests) is list + assert type(__class__.cAchtungTests) is int assert __class__.cAchtungTests >= 0 __class__.AchtungTests.append(testID) # raise? @@ -479,18 +479,18 @@ def helper__makereport__call( # -------- item_error_msg_count1 = item.stash.get(g_error_msg_count_key, 0) - assert type(item_error_msg_count1) == int # noqa: E721 + assert type(item_error_msg_count1) is int assert item_error_msg_count1 >= 0 item_error_msg_count2 = item.stash.get(g_critical_msg_count_key, 0) - assert type(item_error_msg_count2) == int # noqa: E721 + assert type(item_error_msg_count2) is int assert item_error_msg_count2 >= 0 item_error_msg_count = item_error_msg_count1 + item_error_msg_count2 # -------- item_warning_msg_count = item.stash.get(g_warning_msg_count_key, 0) - assert type(item_warning_msg_count) == int # noqa: E721 + assert type(item_warning_msg_count) is int assert item_warning_msg_count >= 0 # -------- @@ -539,7 +539,7 @@ def helper__makereport__call( exitStatus = ExitStatusNames.XFAILED assert hasattr(rep, "wasxfail") assert rep.wasxfail is not None - assert type(rep.wasxfail) == str # noqa: E721 + assert type(rep.wasxfail) is str reasonText = rep.wasxfail reasonMsgTempl = "XFAIL REASON: {0}" @@ -552,10 +552,10 @@ def helper__makereport__call( TEST_PROCESS_STATS.incrementXFailedTestCount(testID, item_error_msg_count) - assert type(reasonText) == str # noqa: E721 + assert type(reasonText) is str if reasonText != "": - assert type(reasonMsgTempl) == str # noqa: E721 + assert type(reasonMsgTempl) is str logging.info("*") logging.info("* " + reasonMsgTempl.format(reasonText)) @@ -578,7 +578,7 @@ def helper__makereport__call( assert call.excinfo is None if hasattr(rep, "wasxfail"): - assert type(rep.wasxfail) == str # noqa: E721 + assert type(rep.wasxfail) is str TEST_PROCESS_STATS.incrementNotXFailedTests(testID) @@ -607,7 +607,7 @@ def helper__makereport__call( # -------- assert exitStatus is not None - assert type(exitStatus) == str # noqa: E721 + assert type(exitStatus) is str if exitStatus == ExitStatusNames.FAILED: assert item_error_msg_count > 0 @@ -662,7 +662,7 @@ def pytest_runtest_makereport(item: pytest.Function, call: pytest.CallInfo): assert outcome is not None assert type(outcome) == T_PLUGGY_RESULT # noqa: E721 - assert type(call.when) == str # noqa: E721 + assert type(call.when) is str if call.when == "collect": return @@ -751,11 +751,11 @@ def __call__(self, record: logging.LogRecord): assert self._warn_counter is not None assert self._critical_counter is not None - assert type(self._err_counter) == int # noqa: E721 + assert type(self._err_counter) is int assert self._err_counter >= 0 - assert type(self._warn_counter) == int # noqa: E721 + assert type(self._warn_counter) is int assert self._warn_counter >= 0 - assert type(self._critical_counter) == int # noqa: E721 + assert type(self._critical_counter) is int assert self._critical_counter >= 0 r = self._old_method(record) @@ -810,11 +810,11 @@ def pytest_pyfunc_call(pyfuncitem: pytest.Function): with LogWrapper2() as logWrapper: assert type(logWrapper) == LogWrapper2 # noqa: E721 assert logWrapper._old_method is not None - assert type(logWrapper._err_counter) == int # noqa: E721 + assert type(logWrapper._err_counter) is int assert logWrapper._err_counter == 0 - assert type(logWrapper._warn_counter) == int # noqa: E721 + assert type(logWrapper._warn_counter) is int assert logWrapper._warn_counter == 0 - assert type(logWrapper._critical_counter) == int # noqa: E721 + assert type(logWrapper._critical_counter) is int assert logWrapper._critical_counter == 0 assert logging.root.handle is logWrapper @@ -824,11 +824,11 @@ def pytest_pyfunc_call(pyfuncitem: pytest.Function): assert type(r) == T_PLUGGY_RESULT # noqa: E721 assert logWrapper._old_method is not None - assert type(logWrapper._err_counter) == int # noqa: E721 + assert type(logWrapper._err_counter) is int assert logWrapper._err_counter >= 0 - assert type(logWrapper._warn_counter) == int # noqa: E721 + assert type(logWrapper._warn_counter) is int assert logWrapper._warn_counter >= 0 - assert type(logWrapper._critical_counter) == int # noqa: E721 + assert type(logWrapper._critical_counter) is int assert logWrapper._critical_counter >= 0 assert logging.root.handle is logWrapper @@ -864,7 +864,7 @@ def helper__calc_W(n: int) -> int: assert n > 0 x = int(math.log10(n)) - assert type(x) == int # noqa: E721 + assert type(x) is int assert x >= 0 x += 1 return x @@ -872,7 +872,7 @@ def helper__calc_W(n: int) -> int: # ------------------------------------------------------------------------ def helper__print_test_list(tests: typing.List[str]) -> None: - assert type(tests) == list # noqa: E721 + assert type(tests) is list assert helper__calc_W(9) == 1 assert helper__calc_W(10) == 2 @@ -891,7 +891,7 @@ def helper__print_test_list(tests: typing.List[str]) -> None: nTest = 0 for t in tests: - assert type(t) == str # noqa: E721 + assert type(t) is str assert t != "" nTest += 1 logging.info(templateLine.format(nTest, t)) @@ -899,7 +899,7 @@ def helper__print_test_list(tests: typing.List[str]) -> None: # ------------------------------------------------------------------------ def helper__print_test_list2(tests: typing.List[T_TUPLE__str_int]) -> None: - assert type(tests) == list # noqa: E721 + assert type(tests) is list assert helper__calc_W(9) == 1 assert helper__calc_W(10) == 2 @@ -920,8 +920,8 @@ def helper__print_test_list2(tests: typing.List[T_TUPLE__str_int]) -> None: for t in tests: assert type(t) == tuple # noqa: E721 assert len(t) == 2 - assert type(t[0]) == str # noqa: E721 - assert type(t[1]) == int # noqa: E721 + assert type(t[0]) is str + assert type(t[1]) is int assert t[0] != "" assert t[1] >= 0 nTest += 1 @@ -958,23 +958,23 @@ def pytest_sessionfinish(): assert g_test_process_mode == T_TEST_PROCESS_MODE.ExecTests - assert type(g_worker_log_is_created) == bool # noqa: E721 + assert type(g_worker_log_is_created) is bool assert g_worker_log_is_created C_LINE1 = "---------------------------" def LOCAL__print_line1_with_header(header: str): - assert type(C_LINE1) == str # noqa: E721 - assert type(header) == str # noqa: E721 + assert type(C_LINE1) is str + assert type(header) is str assert header != "" logging.info(C_LINE1 + " [" + header + "]") def LOCAL__print_test_list( header: str, test_count: int, test_list: typing.List[str] ): - assert type(header) == str # noqa: E721 - assert type(test_count) == int # noqa: E721 - assert type(test_list) == list # noqa: E721 + assert type(header) is str + assert type(test_count) is int + assert type(test_list) is list assert header != "" assert test_count >= 0 assert len(test_list) == test_count @@ -988,9 +988,9 @@ def LOCAL__print_test_list( def LOCAL__print_test_list2( header: str, test_count: int, test_list: typing.List[T_TUPLE__str_int] ): - assert type(header) == str # noqa: E721 - assert type(test_count) == int # noqa: E721 - assert type(test_list) == list # noqa: E721 + assert type(header) is str + assert type(test_count) is int + assert type(test_list) is list assert header != "" assert test_count >= 0 assert len(test_list) == test_count @@ -1114,7 +1114,7 @@ def helper__pytest_configure__logging(config: pytest.Config) -> None: log_file_path = os.path.join(log_dir, log_name) assert log_file_path is not None - assert type(log_file_path) == str # noqa: E721 + assert type(log_file_path) is str logging_plugin.set_log_path(log_file_path) return diff --git a/tests/helpers/global_data.py b/tests/helpers/global_data.py index 13c61e36..fa49b24d 100644 --- a/tests/helpers/global_data.py +++ b/tests/helpers/global_data.py @@ -15,7 +15,7 @@ class OsOpsDescr: os_ops: OsOperations def __init__(self, sign: str, os_ops: OsOperations): - assert type(sign) == str # noqa: E721 + assert type(sign) is str assert isinstance(os_ops, OsOperations) self.sign = sign self.os_ops = os_ops @@ -50,7 +50,7 @@ class PostgresNodeService: port_manager: PortManager def __init__(self, sign: str, os_ops: OsOperations, port_manager: PortManager): - assert type(sign) == str # noqa: E721 + assert type(sign) is str assert isinstance(os_ops, OsOperations) assert isinstance(port_manager, PortManager) self.sign = sign diff --git a/tests/helpers/pg_node_utils.py b/tests/helpers/pg_node_utils.py index b9395e57..7459595e 100644 --- a/tests/helpers/pg_node_utils.py +++ b/tests/helpers/pg_node_utils.py @@ -21,8 +21,8 @@ class PortConflictNodeException(PostgresNodeUtilsException): _port: int def __init__(self, data_dir: str, port: int): - assert type(data_dir) == str # noqa: E721 - assert type(port) == int # noqa: E721 + assert type(data_dir) is str + assert type(port) is int super().__init__() @@ -32,29 +32,29 @@ def __init__(self, data_dir: str, port: int): @property def data_dir(self) -> str: - assert type(self._data_dir) == str # noqa: E721 + assert type(self._data_dir) is str return self._data_dir @property def port(self) -> int: - assert type(self._port) == int # noqa: E721 + assert type(self._port) is int return self._port @property def message(self) -> str: - assert type(self._data_dir) == str # noqa: E721 - assert type(self._port) == int # noqa: E721 + assert type(self._data_dir) is str + assert type(self._port) is int r = "PostgresNode [data:{}][port: {}] conflicts with port of another instance.".format( self._data_dir, self._port, ) - assert type(r) == str # noqa: E721 + assert type(r) is str return r def __str__(self) -> str: r = self.message - assert type(r) == str # noqa: E721 + assert type(r) is str return r def __repr__(self) -> str: @@ -65,7 +65,7 @@ def __repr__(self) -> str: repr(self._data_dir), repr(self._port), ) - assert type(r) == str # noqa: E721 + assert type(r) is str return r # -------------------------------------------------------------------- @@ -78,7 +78,7 @@ def __init__( data_dir: str, files: typing.Optional[typing.Iterable] = None ): - assert type(data_dir) == str # noqa: E721 + assert type(data_dir) is str assert files is None or isinstance(files, typing.Iterable) super().__init__() @@ -89,7 +89,7 @@ def __init__( @property def message(self) -> str: - assert self._data_dir is None or type(self._data_dir) == str # noqa: E721 + assert self._data_dir is None or type(self._data_dir) is str assert self._files is None or isinstance(self._files, typing.Iterable) msg_parts = [] @@ -99,7 +99,7 @@ def message(self) -> str: )) for f, lines in self._files or []: - assert type(f) == str # noqa: E721 + assert type(f) is str assert type(lines) in [str, bytes] # noqa: E721 msg_parts.append(u'{}\n----\n{}\n'.format(f, lines)) @@ -107,7 +107,7 @@ def message(self) -> str: @property def data_dir(self) -> typing.Optional[str]: - assert type(self._data_dir) == str # noqa: E721 + assert type(self._data_dir) is str return self._data_dir @property @@ -116,7 +116,7 @@ def files(self) -> typing.Optional[typing.Iterable]: return self._files def __repr__(self) -> str: - assert type(self._data_dir) == str # noqa: E721 + assert type(self._data_dir) is str assert self._files is None or isinstance(self._files, typing.Iterable) r = "{}({}, {})".format( @@ -124,7 +124,7 @@ def __repr__(self) -> str: repr(self._data_dir), repr(self._files), ) - assert type(r) == str # noqa: E721 + assert type(r) is str return r # -------------------------------------------------------------------- @@ -156,7 +156,7 @@ def wait_for_running_state( node_log_reader: PostgresNodeLogReader, timeout: T_WAIT_TIME, ): - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode assert type(node_log_reader) == PostgresNodeLogReader # noqa: E721 assert type(timeout) in [int, float] assert node_log_reader._node is node @@ -173,7 +173,7 @@ def wait_for_running_state( assert s == NodeStatus.Stopped blocks = node_log_reader.read() - assert type(blocks) == list # noqa: E721 + assert type(blocks) is list for block in blocks: assert type(block) == PostgresNodeLogReader.LogDataBlock # noqa: E721 diff --git a/tests/test_os_ops_common.py b/tests/test_os_ops_common.py index 6897a96e..5e8ea6e2 100644 --- a/tests/test_os_ops_common.py +++ b/tests/test_os_ops_common.py @@ -46,14 +46,14 @@ def test_get_platform(self, os_ops: OsOperations): assert isinstance(os_ops, OsOperations) p = os_ops.get_platform() assert p is not None - assert type(p) == str # noqa: E721 + assert type(p) is str assert p == sys.platform def test_get_platform__is_known(self, os_ops: OsOperations): assert isinstance(os_ops, OsOperations) p = os_ops.get_platform() assert p is not None - assert type(p) == str # noqa: E721 + assert type(p) is str assert p in {"win32", "linux"} def test_create_clone(self, os_ops: OsOperations): @@ -91,11 +91,11 @@ def test_exec_command_failure(self, os_ops: OsOperations): try: os_ops.exec_command(cmd) except ExecUtilException as e: - assert type(e.exit_code) == int # noqa: E721 + assert type(e.exit_code) is int assert e.exit_code == 127 - assert type(e.message) == str # noqa: E721 - assert type(e.error) == bytes # noqa: E721 + assert type(e.message) is str + assert type(e.error) is bytes assert e.message.startswith("Utility exited with non-zero code (127). Error:") assert "nonexistent_command" in e.message @@ -119,7 +119,7 @@ def test_exec_command_failure__expect_error(self, os_ops: OsOperations): assert exit_status == 127 assert result == b'' - assert type(error) == bytes # noqa: E721 + assert type(error) is bytes assert b"nonexistent_command" in error assert b"not found" in error @@ -136,12 +136,12 @@ def test_exec_command_with_exec_env(self, os_ops: OsOperations): response = os_ops.exec_command(cmd, exec_env=exec_env) assert response is not None - assert type(response) == bytes # noqa: E721 + assert type(response) is bytes assert response == b'Hello!\n' response = os_ops.exec_command(cmd) assert response is not None - assert type(response) == bytes # noqa: E721 + assert type(response) is bytes assert response == b'\n' def test_exec_command_with_exec_env__2(self, os_ops: OsOperations): @@ -156,7 +156,7 @@ def test_exec_command_with_exec_env__2(self, os_ops: OsOperations): logging.info("content is [{}]".format(tmp_file_content)) tmp_file = os_ops.mkstemp() - assert type(tmp_file) == str # noqa: E721 + assert type(tmp_file) is str assert tmp_file != "" logging.info("file is [{}]".format(tmp_file)) @@ -170,12 +170,12 @@ def test_exec_command_with_exec_env__2(self, os_ops: OsOperations): response = os_ops.exec_command(cmd, exec_env=exec_env) assert response is not None - assert type(response) == bytes # noqa: E721 + assert type(response) is bytes assert response == b'Hello!\n' response = os_ops.exec_command(cmd) assert response is not None - assert type(response) == bytes # noqa: E721 + assert type(response) is bytes assert response == b'\n' os_ops.remove_file(tmp_file) @@ -191,12 +191,12 @@ def test_exec_command_with_cwd(self, os_ops: OsOperations): response = os_ops.exec_command(cmd, cwd="/tmp") assert response is not None - assert type(response) == bytes # noqa: E721 + assert type(response) is bytes assert response == b'/tmp\n' response = os_ops.exec_command(cmd) assert response is not None - assert type(response) == bytes # noqa: E721 + assert type(response) is bytes assert response != b'/tmp\n' def test_exec_command__test_unset(self, os_ops: OsOperations): @@ -210,7 +210,7 @@ def test_exec_command__test_unset(self, os_ops: OsOperations): response1 = os_ops.exec_command(cmd) assert response1 is not None - assert type(response1) == bytes # noqa: E721 + assert type(response1) is bytes if response1 == b'\n': logging.warning("Environment variable {} is not defined.".format(C_ENV_NAME)) @@ -219,12 +219,12 @@ def test_exec_command__test_unset(self, os_ops: OsOperations): exec_env = {C_ENV_NAME: None} response2 = os_ops.exec_command(cmd, exec_env=exec_env) assert response2 is not None - assert type(response2) == bytes # noqa: E721 + assert type(response2) is bytes assert response2 == b'\n' response3 = os_ops.exec_command(cmd) assert response3 is not None - assert type(response3) == bytes # noqa: E721 + assert type(response3) is bytes assert response3 == response1 def test_exec_command__test_unset_dummy_var(self, os_ops: OsOperations): @@ -239,7 +239,7 @@ def test_exec_command__test_unset_dummy_var(self, os_ops: OsOperations): exec_env = {C_ENV_NAME: None} response2 = os_ops.exec_command(cmd, exec_env=exec_env) assert response2 is not None - assert type(response2) == bytes # noqa: E721 + assert type(response2) is bytes assert response2 == b'\n' def test_is_executable_true(self, os_ops: OsOperations): @@ -315,7 +315,7 @@ def test_listdir(self, os_ops: OsOperations): assert isinstance(files, list) for f in files: assert f is not None - assert type(f) == str # noqa: E721 + assert type(f) is str def test_path_exists_true__directory(self, os_ops: OsOperations): """ @@ -520,22 +520,22 @@ def test_read__text(self, os_ops: OsOperations): with open(filename, 'r') as file: # open in a text mode response0 = file.read() - assert type(response0) == str # noqa: E721 + assert type(response0) is str response1 = os_ops.read(filename) - assert type(response1) == str # noqa: E721 + assert type(response1) is str assert response1 == response0 response2 = os_ops.read(filename, encoding=None, binary=False) - assert type(response2) == str # noqa: E721 + assert type(response2) is str assert response2 == response0 response3 = os_ops.read(filename, encoding="") - assert type(response3) == str # noqa: E721 + assert type(response3) is str assert response3 == response0 response4 = os_ops.read(filename, encoding="UTF-8") - assert type(response4) == str # noqa: E721 + assert type(response4) is str assert response4 == response0 def test_read__binary(self, os_ops: OsOperations): @@ -547,10 +547,10 @@ def test_read__binary(self, os_ops: OsOperations): with open(filename, 'rb') as file: # open in a binary mode response0 = file.read() - assert type(response0) == bytes # noqa: E721 + assert type(response0) is bytes response1 = os_ops.read(filename, binary=True) - assert type(response1) == bytes # noqa: E721 + assert type(response1) is bytes assert response1 == response0 def test_read__binary_and_encoding(self, os_ops: OsOperations): @@ -577,29 +577,29 @@ def test_read_binary__spec(self, os_ops: OsOperations): with open(filename, 'rb') as file: # open in a binary mode response0 = file.read() - assert type(response0) == bytes # noqa: E721 + assert type(response0) is bytes response1 = os_ops.read_binary(filename, 0) - assert type(response1) == bytes # noqa: E721 + assert type(response1) is bytes assert response1 == response0 response2 = os_ops.read_binary(filename, 1) - assert type(response2) == bytes # noqa: E721 + assert type(response2) is bytes assert len(response2) < len(response1) assert len(response2) + 1 == len(response1) assert response2 == response1[1:] response3 = os_ops.read_binary(filename, len(response1)) - assert type(response3) == bytes # noqa: E721 + assert type(response3) is bytes assert len(response3) == 0 response4 = os_ops.read_binary(filename, len(response2)) - assert type(response4) == bytes # noqa: E721 + assert type(response4) is bytes assert len(response4) == 1 assert response4[0] == response1[len(response1) - 1] response5 = os_ops.read_binary(filename, len(response1) + 1) - assert type(response5) == bytes # noqa: E721 + assert type(response5) is bytes assert len(response5) == 0 def test_read_binary__spec__negative_offset(self, os_ops: OsOperations): @@ -622,10 +622,10 @@ def test_get_file_size(self, os_ops: OsOperations): filename = __file__ # current file sz0 = os.path.getsize(filename) - assert type(sz0) == int # noqa: E721 + assert type(sz0) is int sz1 = os_ops.get_file_size(filename) - assert type(sz1) == int # noqa: E721 + assert type(sz1) is int assert sz1 == sz0 def test_isfile_true(self, os_ops: OsOperations): @@ -713,7 +713,7 @@ def test_cwd(self, os_ops: OsOperations): v = os_ops.cwd() assert v is not None - assert type(v) == str # noqa: E721 + assert type(v) is str assert v != "" class tagWriteData001: @@ -807,7 +807,7 @@ def test_is_port_free__true(self, os_ops: OsOperations): C_LIMIT = 128 ports = set(range(1024, 65535)) - assert type(ports) == set # noqa: E721 + assert type(ports) is set ok_count = 0 no_count = 0 @@ -843,7 +843,7 @@ def test_is_port_free__false(self, os_ops: OsOperations): C_LIMIT = 10 ports = set(range(1024, 65535)) - assert type(ports) == set # noqa: E721 + assert type(ports) is set def LOCAL_server(s: socket.socket): assert s is not None @@ -902,7 +902,7 @@ def test_get_tmpdir(self, os_ops: OsOperations): assert isinstance(os_ops, OsOperations) dir = os_ops.get_tempdir() - assert type(dir) == str # noqa: E721 + assert type(dir) is str assert os_ops.path_exists(dir) assert os.path.exists(dir) @@ -927,15 +927,15 @@ def test_get_tmpdir__compare_with_py_info(self, os_ops: OsOperations): actual_dir = os_ops.get_tempdir() assert actual_dir is not None - assert type(actual_dir) == str # noqa: E721 + assert type(actual_dir) is str # -------- cmd = [sys.executable, "-c", "import tempfile;print(tempfile.gettempdir());"] expected_dir_b = os_ops.exec_command(cmd) - assert type(expected_dir_b) == bytes # noqa: E721 + assert type(expected_dir_b) is bytes expected_dir = expected_dir_b.decode() - assert type(expected_dir) == str # noqa: E721 + assert type(expected_dir) is str assert actual_dir + "\n" == expected_dir return @@ -945,7 +945,7 @@ class tagData_OS_OPS__NUMS: def __init__(self, os_ops_descr: OsOpsDescr, nums: int): assert isinstance(os_ops_descr, OsOpsDescr) - assert type(nums) == int # noqa: E721 + assert type(nums) is int self.os_ops_descr = os_ops_descr self.nums = nums @@ -968,7 +968,7 @@ def test_mkdir__mt(self, data001: tagData_OS_OPS__NUMS): N_WORKERS = 4 N_NUMBERS = data001.nums - assert type(N_NUMBERS) == int # noqa: E721 + assert type(N_NUMBERS) is int os_ops = data001.os_ops_descr.os_ops assert isinstance(os_ops, OsOperations) @@ -982,8 +982,8 @@ def test_mkdir__mt(self, data001: tagData_OS_OPS__NUMS): assert os.path.exists(lock_dir) def MAKE_PATH(lock_dir: str, num: int) -> str: - assert type(lock_dir) == str # noqa: E721 - assert type(num) == int # noqa: E721 + assert type(lock_dir) is str + assert type(num) is int return os.path.join(lock_dir, str(num) + ".lock") def LOCAL_WORKER(os_ops: OsOperations, @@ -992,21 +992,21 @@ def LOCAL_WORKER(os_ops: OsOperations, cNumbers: int, reservedNumbers: typing.Set[int]) -> None: assert isinstance(os_ops, OsOperations) - assert type(workerID) == int # noqa: E721 - assert type(lock_dir) == str # noqa: E721 - assert type(cNumbers) == int # noqa: E721 - assert type(reservedNumbers) == set # noqa: E721 + assert type(workerID) is int + assert type(lock_dir) is str + assert type(cNumbers) is int + assert type(reservedNumbers) is set assert cNumbers > 0 assert len(reservedNumbers) == 0 assert os.path.exists(lock_dir) def LOG_INFO(template: str, *args) -> None: - assert type(template) == str # noqa: E721 + assert type(template) is str assert type(args) == tuple # noqa: E721 msg = template.format(*args) - assert type(msg) == str # noqa: E721 + assert type(msg) is str logging.info("[Worker #{}] {}".format(workerID, msg)) return @@ -1014,7 +1014,7 @@ def LOG_INFO(template: str, *args) -> None: LOG_INFO("HELLO! I am here!") for num in range(cNumbers): - assert not (num in reservedNumbers) + assert num not in reservedNumbers file_path = MAKE_PATH(lock_dir, num) @@ -1085,7 +1085,7 @@ class tadWorkerData: nWorkers = 0 - assert type(workerDatas) == list # noqa: E721 + assert type(workerDatas) is list for i in range(len(workerDatas)): worker = workerDatas[i].future @@ -1122,7 +1122,7 @@ class tadWorkerData: logging.info("Worker #{} is checked ...".format(i)) workerNumbers = workerDatas[i].reservedNumbers - assert type(workerNumbers) == set # noqa: E721 + assert type(workerNumbers) is set for n in workerNumbers: if n < 0 or n >= N_NUMBERS: @@ -1150,7 +1150,7 @@ class tadWorkerData: logging.info("OK. Let's check reservedNumbers!") for n in range(N_NUMBERS): - if not (n in reservedNumbers.keys()): + if n not in reservedNumbers.keys(): nErrors += 1 logging.error("Number {} is not reserved!".format(n)) continue @@ -1263,7 +1263,7 @@ def test_kill( assert proc is not None assert type(proc) == subprocess.Popen # noqa: E721 proc_pid = proc.pid - assert type(proc_pid) == int # noqa: E721 + assert type(proc_pid) is int logging.info("Test process pid is {}".format(proc_pid)) logging.info("Get this test process ...") @@ -1334,18 +1334,18 @@ def test_kill__unk_pid( assert proc is not None assert type(proc) == subprocess.Popen # noqa: E721 proc_pid = proc.pid - assert type(proc_pid) == int # noqa: E721 + assert type(proc_pid) is int logging.info("Test process pid is {}".format(proc_pid)) logging.info("Wait for finish ...") pout, perr = proc.communicate() logging.info("STDOUT: {}".format(pout)) logging.info("STDERR: {}".format(pout)) - assert type(pout) == str # noqa: E721 - assert type(perr) == str # noqa: E721 + assert type(pout) is str + assert type(perr) is str assert pout == "a\n" assert perr == "b\n" - assert type(proc.returncode) == int # noqa: E721 + assert type(proc.returncode) is int assert proc.returncode == 0 logging.info("Try to get this test process ...") diff --git a/tests/test_os_ops_local.py b/tests/test_os_ops_local.py index f60c3fc9..2a13082f 100644 --- a/tests/test_os_ops_local.py +++ b/tests/test_os_ops_local.py @@ -49,11 +49,11 @@ def test_cwd(self, os_ops: OsOperations): v = os_ops.cwd() assert v is not None - assert type(v) == str # noqa: E721 + assert type(v) is str expectedValue = os.getcwd() assert expectedValue is not None - assert type(expectedValue) == str # noqa: E721 + assert type(expectedValue) is str assert expectedValue != "" # research # Comp result diff --git a/tests/test_os_ops_remote.py b/tests/test_os_ops_remote.py index 6365ffcb..0aa3386f 100755 --- a/tests/test_os_ops_remote.py +++ b/tests/test_os_ops_remote.py @@ -25,7 +25,7 @@ def test_rmdirs__try_to_delete_file(self, os_ops: OsOperations): assert isinstance(os_ops, OsOperations) path = os_ops.mkstemp() - assert type(path) == str # noqa: E721 + assert type(path) is str assert os.path.exists(path) with pytest.raises(ExecUtilException) as x: @@ -36,9 +36,9 @@ def test_rmdirs__try_to_delete_file(self, os_ops: OsOperations): assert type(x.value.description) == str # noqa: E721 assert x.value.description == "Utility exited with non-zero code (20). Error: `cannot remove '" + path + "': it is not a directory`" assert x.value.message.startswith(x.value.description) - assert type(x.value.error) == str # noqa: E721 + assert type(x.value.error) is str assert x.value.error.strip() == "cannot remove '" + path + "': it is not a directory" - assert type(x.value.exit_code) == int # noqa: E721 + assert type(x.value.exit_code) is int assert x.value.exit_code == 20 def test_read__unknown_file(self, os_ops: OsOperations): diff --git a/tests/test_raise_error.py b/tests/test_raise_error.py index 55481995..bfc10344 100644 --- a/tests/test_raise_error.py +++ b/tests/test_raise_error.py @@ -17,7 +17,7 @@ def __init__( expected_msg: str, ): assert type(node_status) == NodeStatus # noqa: E721 - assert type(expected_msg) == str # noqa: E721 + assert type(expected_msg) is str self.node_status = node_status self.expected_msg = expected_msg return diff --git a/tests/test_testgres_common.py b/tests/test_testgres_common.py index a823d718..aed15dfc 100644 --- a/tests/test_testgres_common.py +++ b/tests/test_testgres_common.py @@ -223,8 +223,8 @@ def test_double_start(self, node_svc: PostgresNodeService): assert x is not None assert type(x.value) == StartNodeException # noqa: E721 - assert type(x.value.description) == str # noqa: E721 - assert type(x.value.message) == str # noqa: E721 + assert type(x.value.description) is str + assert type(x.value.message) is str assert x.value.description == "Cannot start node" assert x.value.message.startswith(x.value.description) @@ -302,8 +302,8 @@ def test_start2(self, node_svc: PostgresNodeService): assert x is not None assert type(x.value) == StartNodeException # noqa: E721 - assert type(x.value.description) == str # noqa: E721 - assert type(x.value.message) == str # noqa: E721 + assert type(x.value.description) is str + assert type(x.value.message) is str assert x.value.description == "Cannot start node" assert x.value.message.startswith(x.value.description) @@ -598,15 +598,15 @@ def test_kill_backgroud_writer__ok( node.slow_start() assert node.is_started node_pid = node.pid - assert type(node_pid) == int # noqa: E721 + assert type(node_pid) is int aux_pids = node.auxiliary_pids - assert type(aux_pids) == dict # noqa: E721 + assert type(aux_pids) is dict assert ProcessType.BackgroundWriter in aux_pids bw_pids = aux_pids[ProcessType.BackgroundWriter] - assert type(bw_pids) == list # noqa: E721 + assert type(bw_pids) is list assert len(bw_pids) == 1 bw_pid = bw_pids[0] - assert type(bw_pid) == int # noqa: E721 + assert type(bw_pid) is int node.kill(ProcessType.BackgroundWriter) assert node.is_started @@ -699,7 +699,7 @@ def test_child_processes__ok( children = node.child_processes assert children is not None - assert type(children) == list # noqa: E721 + assert type(children) is list logging.info("Children count is {}".format(len(children))) logging.info("") @@ -728,8 +728,8 @@ def LOCAL__safe_call_cmdline(p: ProcessProxy) -> str: assert child.process is not None assert child.ptype is not None assert child.pid is not None - assert type(child.ptype) == ProcessType # noqa: E721 - assert type(child.pid) == int # noqa: E721 + assert type(child.ptype) is ProcessType + assert type(child.pid) is int assert type(child.cmdline) == types.MethodType # noqa: E721 logging.info("ptype is {}".format(child.ptype)) @@ -782,17 +782,17 @@ def LOCAL__test_auxiliary_pids( ) -> typing.List[ProcessType]: # returns list of the absence processes assert node is not None - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode assert expectedTypes is not None - assert type(expectedTypes) == list # noqa: E721 + assert type(expectedTypes) is list pids = node.auxiliary_pids - assert pids is not None # noqa: E721 - assert type(pids) == dict # noqa: E721 + assert pids is not None + assert type(pids) is dict result: typing.List[ProcessType] = list() for ptype in expectedTypes: - if not (ptype in pids): + if ptype not in pids: result.append(ptype) return result @@ -801,9 +801,9 @@ def LOCAL__check_auxiliary_pids__multiple_attempts( expectedTypes: typing.List[ProcessType], ): assert node is not None - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode assert expectedTypes is not None - assert type(expectedTypes) == list # noqa: E721 + assert type(expectedTypes) is list nAttempt = 0 @@ -820,7 +820,7 @@ def LOCAL__check_auxiliary_pids__multiple_attempts( absenceList = LOCAL__test_auxiliary_pids(node, expectedTypes) assert absenceList is not None - assert type(absenceList) == list # noqa: E721 + assert type(absenceList) is list if len(absenceList) == 0: logging.info("Bingo!") break @@ -845,7 +845,7 @@ def LOCAL__check_auxiliary_pids__multiple_attempts( assert (con.pid > 0) with master.replicate().start() as replica: - assert type(replica) == PostgresNode # noqa: E721 + assert type(replica) is PostgresNode # test __str__ method str(master.child_processes[0]) @@ -1061,12 +1061,12 @@ def test_logging(self, node_svc: PostgresNodeService): lines = log.readlines() assert lines is not None - assert type(lines) == list # noqa: E721 + assert type(lines) is list def LOCAL__test_lines(lines: typing.Iterable[str]) -> bool: assert isinstance(lines, typing.Iterable) for s in lines: - assert type(s) == str # noqa: E721 + assert type(s) is str if C_NODE_NAME in s: logging.info("OK. We found the node_name in a line \"{0}\"".format(s)) return True @@ -1092,8 +1092,8 @@ def LOCAL__test_lines(lines: typing.Iterable[str]) -> bool: 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 not (C_NODE_NAME in logging.Logger.manager.loggerDict.keys()) - assert not (handler in logging._handlers.values()) + assert C_NODE_NAME not in logging.Logger.manager.loggerDict.keys() + assert handler not in logging._handlers.values() # GO HOME! return @@ -1369,7 +1369,7 @@ def test_pg_ctl_wait_option(self, node_svc: PostgresNodeService): time.sleep(3) port = node_svc.port_manager.reserve_port() - assert type(port) == int # noqa: E721 + assert type(port) is int ok = False try: with __class__.helper__get_node(node_svc, port=port) as node: @@ -1786,7 +1786,7 @@ def test_unix_sockets(self, node_svc: PostgresNodeService): assert (res_psql == b'1\n') with node.replicate() as r: - assert type(r) == PostgresNode # noqa: E721 + assert type(r) is PostgresNode r.start() res_exec = r.execute('select 1') assert (res_exec == [(1,)]) @@ -1837,8 +1837,8 @@ class tagPortManagerProxy(PortManager): def __init__(self, prevPortManager: PortManager, dummyPortNumber: int, dummyPortMaxUsage: int): assert isinstance(prevPortManager, PortManager) - assert type(dummyPortNumber) == int # noqa: E721 - assert type(dummyPortMaxUsage) == int # noqa: E721 + assert type(dummyPortNumber) is int + assert type(dummyPortMaxUsage) is int assert dummyPortNumber >= 0 assert dummyPortMaxUsage >= 0 @@ -1861,9 +1861,9 @@ def __exit__(self, type, value, traceback): assert self.m_PrevPortManager is not None def reserve_port(self) -> int: - assert type(self.m_DummyPortMaxUsage) == int # noqa: E721 - assert type(self.m_DummyPortTotalUsage) == int # noqa: E721 - assert type(self.m_DummyPortCurrentUsage) == int # noqa: E721 + assert type(self.m_DummyPortMaxUsage) is int + assert type(self.m_DummyPortTotalUsage) is int + assert type(self.m_DummyPortCurrentUsage) is int assert self.m_DummyPortTotalUsage >= 0 assert self.m_DummyPortCurrentUsage >= 0 @@ -1881,11 +1881,11 @@ def reserve_port(self) -> int: return self.m_DummyPortNumber def release_port(self, number: int) -> None: - assert type(number) == int # noqa: E721 + assert type(number) is int - assert type(self.m_DummyPortMaxUsage) == int # noqa: E721 - assert type(self.m_DummyPortTotalUsage) == int # noqa: E721 - assert type(self.m_DummyPortCurrentUsage) == int # noqa: E721 + assert type(self.m_DummyPortMaxUsage) is int + assert type(self.m_DummyPortTotalUsage) is int + assert type(self.m_DummyPortCurrentUsage) is int assert self.m_DummyPortTotalUsage >= 0 assert self.m_DummyPortCurrentUsage >= 0 @@ -1911,7 +1911,7 @@ def test_port_rereserve_during_node_start(self, node_svc: PostgresNodeService): with __class__.helper__get_node(node_svc) as node1: node1.init().start() assert node1._should_free_port - assert type(node1.port) == int # noqa: E721 + assert type(node1.port) is int node1_port_copy = node1.port assert __class__.helper__rm_carriage_returns(node1.safe_psql("SELECT 1;")) == b'1\n' @@ -1946,7 +1946,7 @@ def test_port_conflict(self, node_svc: PostgresNodeService): with __class__.helper__get_node(node_svc) as node1: node1.init().start() assert node1._should_free_port - assert type(node1.port) == int # noqa: E721 + assert type(node1.port) is int node1_port_copy = node1.port assert __class__.helper__rm_carriage_returns(node1.safe_psql("SELECT 1;")) == b'1\n' @@ -1989,15 +1989,15 @@ def test_try_to_get_port_after_free_manual_port(self, node_svc: PostgresNodeServ with __class__.helper__get_node(node_svc) as node1: assert node1 is not None - assert type(node1) == PostgresNode # noqa: E721 + assert type(node1) is PostgresNode assert node1.port is not None - assert type(node1.port) == int # noqa: E721 + assert type(node1.port) is int with __class__.helper__get_node(node_svc, port=node1.port, port_manager=None) as node2: assert node2 is not None - assert type(node1) == PostgresNode # noqa: E721 + assert type(node1) is PostgresNode assert node2 is not node1 assert node2.port is not None - assert type(node2.port) == int # noqa: E721 + assert type(node2.port) is int assert node2.port == node1.port logging.info("Release node2 port") @@ -2019,15 +2019,15 @@ def test_try_to_start_node_after_free_manual_port(self, node_svc: PostgresNodeSe with __class__.helper__get_node(node_svc) as node1: assert node1 is not None - assert type(node1) == PostgresNode # noqa: E721 + assert type(node1) is PostgresNode assert node1.port is not None - assert type(node1.port) == int # noqa: E721 + assert type(node1.port) is int with __class__.helper__get_node(node_svc, port=node1.port, port_manager=None) as node2: assert node2 is not None - assert type(node1) == PostgresNode # noqa: E721 + assert type(node1) is PostgresNode assert node2 is not node1 assert node2.port is not None - assert type(node2.port) == int # noqa: E721 + assert type(node2.port) is int assert node2.port == node1.port logging.info("Release node2 port") @@ -2078,7 +2078,7 @@ def test_node__port_manager_and_explicit_port(self, node_svc: PostgresNodeServic assert isinstance(node_svc.port_manager, PortManager) port = node_svc.port_manager.reserve_port() - assert type(port) == int # noqa: E721 + assert type(port) is int try: with PostgresNode(name="node", port=port, os_ops=node_svc.os_ops) as node: @@ -2104,7 +2104,7 @@ def test_node__no_port_manager(self, node_svc: PostgresNodeService): assert isinstance(node_svc.port_manager, PortManager) port = node_svc.port_manager.reserve_port() - assert type(port) == int # noqa: E721 + assert type(port) is int try: with PostgresNode(name="node", port=port, os_ops=node_svc.os_ops, port_manager=None) as node: @@ -2129,7 +2129,7 @@ def __init__( self, record_count: int, ): - assert type(record_count) == int # noqa: E721 + assert type(record_count) is int self.record_count = record_count # noqa: E721 return @@ -2172,10 +2172,10 @@ def test_node__table_checksum( with __class__.helper__get_node(node_svc) as node: assert node is not None - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode assert node.port is not None - assert type(node.port) == int # noqa: E721 - assert type(table_checksum_test_data.record_count) == int # noqa: E721 + assert type(node.port) is int + assert type(table_checksum_test_data.record_count) is int assert table_checksum_test_data.record_count >= 0 node.init() @@ -2184,7 +2184,7 @@ def test_node__table_checksum( C_DB = "postgres" with node.connect(dbname=C_DB) as cn: - assert type(cn) == NodeConnection # noqa: E721 + assert type(cn) is NodeConnection cn.execute("create table t (id integer, data varchar(32));") cn.commit() @@ -2214,7 +2214,7 @@ def test_node__table_checksum( assert record_count == table_checksum_test_data.record_count checksum2 = node.table_checksum("t", C_DB) - assert type(checksum2) == int # noqa: E721 + assert type(checksum2) is int assert checksum1 == checksum2 pass @@ -2232,10 +2232,10 @@ def test_node__pgbench_table_checksums__one_table( with __class__.helper__get_node(node_svc) as node: assert node is not None - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode assert node.port is not None - assert type(node.port) == int # noqa: E721 - assert type(table_checksum_test_data.record_count) == int # noqa: E721 + assert type(node.port) is int + assert type(table_checksum_test_data.record_count) is int assert table_checksum_test_data.record_count >= 0 node.init() @@ -2244,7 +2244,7 @@ def test_node__pgbench_table_checksums__one_table( C_DB = "postgres" with node.connect(dbname=C_DB) as cn: - assert type(cn) == NodeConnection # noqa: E721 + assert type(cn) is NodeConnection cn.execute("create table t (id integer, data varchar(32));") cn.commit() @@ -2274,12 +2274,12 @@ def test_node__pgbench_table_checksums__one_table( assert record_count == table_checksum_test_data.record_count actual_result = node.pgbench_table_checksums(C_DB, ["t"]) - assert type(actual_result) == set # noqa: E721 + assert type(actual_result) is set actual1 = actual_result.pop() assert type(actual1) == tuple # noqa: E721 assert len(actual1) == 2 - assert type(actual1[0]) == str # noqa: E721 - assert type(actual1[1]) == int # noqa: E721 + assert type(actual1[0]) is str + assert type(actual1[1]) is int assert checksum1 == actual1[1] pass @@ -2293,9 +2293,9 @@ def test_node__pgbench_table_checksums__pbckp_2278(self, node_svc: PostgresNodeS with __class__.helper__get_node(node_svc) as node: assert node is not None - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode assert node.port is not None - assert type(node.port) == int # noqa: E721 + assert type(node.port) is int node.init() node.slow_start() @@ -2319,7 +2319,7 @@ def helper__call_and_check_pgbench_table_checksums( node: PostgresNode ) -> bool: assert node is not None - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode assert node.status() == NodeStatus.Running # We will check @@ -2329,7 +2329,7 @@ def helper__call_and_check_pgbench_table_checksums( logging.info("run pgbench_table_checksums") full_checksums = node.pgbench_table_checksums() assert full_checksums is not None - assert type(full_checksums) == set # noqa: E721 + assert type(full_checksums) is set assert len(full_checksums) == 4 expectedTables: typing.Dict[str, bool] = { @@ -2344,8 +2344,8 @@ def helper__call_and_check_pgbench_table_checksums( for tcs in full_checksums: assert type(tcs) == tuple # noqa: E721 assert len(tcs) == 2 - assert type(tcs[0]) == str # noqa: E721 - assert type(tcs[1]) == int # noqa: E721 + assert type(tcs[0]) is str + assert type(tcs[1]) is int tableName = tcs[0] if tableName not in expectedTables: @@ -2370,13 +2370,13 @@ def helper__call_and_check_pgbench_table_checksums( where c.relname=%s;""" cn = node.connect(dbname="postgres") - assert type(cn) == NodeConnection # noqa: E721 + assert type(cn) is NodeConnection try: for tcs in full_checksums: tableName = tcs[0] recs = cn.execute(C_SQL, tableName) - assert type(recs) == list # noqa: E721 + assert type(recs) is list if len(recs) == 0: logging.info("Table [{}] does not have a lock. It is ok.".format( tableName, @@ -2436,7 +2436,7 @@ def test_node_app__make_empty__base_dir_is_None(self, node_svc: PostgresNodeServ tmp_dir = node_svc.os_ops.mkdtemp() assert tmp_dir is not None - assert type(tmp_dir) == str # noqa: E721 + assert type(tmp_dir) is str logging.info("temp directory is [{}]".format(tmp_dir)) # ----------- @@ -2470,7 +2470,7 @@ def test_node_app__make_empty__base_dir_is_Empty(self, node_svc: PostgresNodeSer tmp_dir = node_svc.os_ops.mkdtemp() assert tmp_dir is not None - assert type(tmp_dir) == str # noqa: E721 + assert type(tmp_dir) is str logging.info("temp directory is [{}]".format(tmp_dir)) # ----------- @@ -2500,7 +2500,7 @@ def test_node_app__make_empty(self, node_svc: PostgresNodeService): tmp_dir = node_svc.os_ops.mkdtemp() assert tmp_dir is not None - assert type(tmp_dir) == str # noqa: E721 + assert type(tmp_dir) is str logging.info("temp directory is [{}]".format(tmp_dir)) # ----------- @@ -2512,7 +2512,7 @@ def test_node_app__make_empty(self, node_svc: PostgresNodeService): assert node_app.os_ops is node_svc.os_ops assert node_app.port_manager is node_svc.port_manager - assert type(node_app.nodes_to_cleanup) == list # noqa: E721 + assert type(node_app.nodes_to_cleanup) is list assert len(node_app.nodes_to_cleanup) == 0 node: typing.Optional[PostgresNode] = None @@ -2523,7 +2523,7 @@ def test_node_app__make_empty(self, node_svc: PostgresNodeService): assert node.os_ops is node_svc.os_ops assert node.port_manager is node_svc.port_manager - assert type(node_app.nodes_to_cleanup) == list # noqa: E721 + assert type(node_app.nodes_to_cleanup) is list assert len(node_app.nodes_to_cleanup) == 1 assert node_app.nodes_to_cleanup[0] is node @@ -2549,7 +2549,7 @@ def test_node_app__make_simple__checksum(self, node_svc: PostgresNodeService): tmp_dir = node_svc.os_ops.mkdtemp() assert tmp_dir is not None - assert type(tmp_dir) == str # noqa: E721 + assert type(tmp_dir) is str logging.info("temp directory is [{}]".format(tmp_dir)) node_app = NodeApp(test_path=tmp_dir, os_ops=node_svc.os_ops) @@ -2604,7 +2604,7 @@ def test_node_app__make_empty_with_explicit_port(self, node_svc: PostgresNodeSer tmp_dir = node_svc.os_ops.mkdtemp() assert tmp_dir is not None - assert type(tmp_dir) == str # noqa: E721 + assert type(tmp_dir) is str logging.info("temp directory is [{}]".format(tmp_dir)) # ----------- @@ -2616,7 +2616,7 @@ def test_node_app__make_empty_with_explicit_port(self, node_svc: PostgresNodeSer assert node_app.os_ops is node_svc.os_ops assert node_app.port_manager is node_svc.port_manager - assert type(node_app.nodes_to_cleanup) == list # noqa: E721 + assert type(node_app.nodes_to_cleanup) is list assert len(node_app.nodes_to_cleanup) == 0 attempt = 0 @@ -2633,7 +2633,7 @@ def test_node_app__make_empty_with_explicit_port(self, node_svc: PostgresNodeSer )) port = node_app.port_manager.reserve_port() - assert type(port) == int # noqa: E721 + assert type(port) is int assert port is not ports try: @@ -2654,7 +2654,7 @@ def test_node_app__make_empty_with_explicit_port(self, node_svc: PostgresNodeSer assert node.port == port assert node._should_free_port == False # noqa: E712 - assert type(node_app.nodes_to_cleanup) == list # noqa: E721 + assert type(node_app.nodes_to_cleanup) is list assert len(node_app.nodes_to_cleanup) == attempt assert node_app.nodes_to_cleanup[-1] is node @@ -2719,22 +2719,22 @@ def helper__get_node( @staticmethod def helper__skip_test_if_pg_version_is_not_ge(ver1: str, ver2: str): - assert type(ver1) == str # noqa: E721 - assert type(ver2) == str # noqa: E721 + assert type(ver1) is str + assert type(ver2) is str if not __class__.helper__pg_version_ge(ver1, ver2): pytest.skip('requires {0}+'.format(ver2)) @staticmethod def helper__skip_test_if_pg_version_is_ge(ver1: str, ver2: str): - assert type(ver1) == str # noqa: E721 - assert type(ver2) == str # noqa: E721 + assert type(ver1) is str + assert type(ver2) is str if __class__.helper__pg_version_ge(ver1, ver2): pytest.skip('requires <{0}'.format(ver2)) @staticmethod def helper__pg_version_ge(ver1: str, ver2: str) -> bool: - assert type(ver1) == str # noqa: E721 - assert type(ver2) == str # noqa: E721 + assert type(ver1) is str + assert type(ver2) is str v1 = PgVer(ver1) v2 = PgVer(ver2) return v1 >= v2 @@ -2754,13 +2754,13 @@ def helper__rm_carriage_returns(out): if isinstance(out, bytes): return out.replace(b'\r', b'') - assert type(out) == str # noqa: E721 + assert type(out) is str return out.replace('\r', '') @staticmethod def helper__skip_test_if_util_not_exist(os_ops: OsOperations, name: str): assert isinstance(os_ops, OsOperations) - assert type(name) == str # noqa: E721 + assert type(name) is str if not __class__.helper__util_exists(os_ops, name): pytest.skip('might be missing') diff --git a/tests/test_testgres_local.py b/tests/test_testgres_local.py index 49faceef..3df93122 100644 --- a/tests/test_testgres_local.py +++ b/tests/test_testgres_local.py @@ -93,7 +93,7 @@ def test_pg_config(self): def test_ports_management(self): assert bound_ports is not None - assert type(bound_ports) == set # noqa: E721 + assert type(bound_ports) is set if len(bound_ports) != 0: logging.warning("bound_ports is not empty: {0}".format(bound_ports)) @@ -102,10 +102,10 @@ def test_ports_management(self): with get_new_node() as node: assert bound_ports is not None - assert type(bound_ports) == set # noqa: E721 + assert type(bound_ports) is set assert node.port is not None - assert type(node.port) == int # noqa: E721 + assert type(node.port) is int logging.info("node port is {0}".format(node.port)) @@ -122,7 +122,7 @@ def test_ports_management(self): # check that port has been freed successfully assert bound_ports is not None - assert type(bound_ports) == set # noqa: E721 + assert type(bound_ports) is set assert bound_ports == stage0__bound_ports def test_child_process_dies(self): @@ -180,8 +180,8 @@ class tagPortManagerProxy: sm_DummyPortTotalUsage = None def __init__(self, dummyPortNumber, dummyPortMaxUsage): - assert type(dummyPortNumber) == int # noqa: E721 - assert type(dummyPortMaxUsage) == int # noqa: E721 + assert type(dummyPortNumber) is int + assert type(dummyPortMaxUsage) is int assert dummyPortNumber >= 0 assert dummyPortMaxUsage >= 0 @@ -225,9 +225,9 @@ def __exit__(self, type, value, traceback): @staticmethod def _proxy__reserve_port(): - assert type(__class__.sm_DummyPortMaxUsage) == int # noqa: E721 - assert type(__class__.sm_DummyPortTotalUsage) == int # noqa: E721 - assert type(__class__.sm_DummyPortCurrentUsage) == int # noqa: E721 + assert type(__class__.sm_DummyPortMaxUsage) is int + assert type(__class__.sm_DummyPortTotalUsage) is int + assert type(__class__.sm_DummyPortCurrentUsage) is int assert __class__.sm_DummyPortTotalUsage >= 0 assert __class__.sm_DummyPortCurrentUsage >= 0 @@ -245,11 +245,11 @@ def _proxy__reserve_port(): @staticmethod def _proxy__release_port(dummyPortNumber): - assert type(dummyPortNumber) == int # noqa: E721 + assert type(dummyPortNumber) is int - assert type(__class__.sm_DummyPortMaxUsage) == int # noqa: E721 - assert type(__class__.sm_DummyPortTotalUsage) == int # noqa: E721 - assert type(__class__.sm_DummyPortCurrentUsage) == int # noqa: E721 + assert type(__class__.sm_DummyPortMaxUsage) is int + assert type(__class__.sm_DummyPortTotalUsage) is int + assert type(__class__.sm_DummyPortCurrentUsage) is int assert __class__.sm_DummyPortTotalUsage >= 0 assert __class__.sm_DummyPortCurrentUsage >= 0 @@ -408,7 +408,7 @@ def test_set_auto_conf(self): @staticmethod def helper__skip_test_if_util_not_exist(name: str): - assert type(name) == str # noqa: E721 + assert type(name) is str if platform.system().lower() == "windows": name2 = name + ".exe" diff --git a/tests/test_testgres_remote.py b/tests/test_testgres_remote.py index bb361ed7..33372cc4 100755 --- a/tests/test_testgres_remote.py +++ b/tests/test_testgres_remote.py @@ -97,9 +97,9 @@ def test_init__unk_LANG_and_LC_CTYPE(self): os.environ.pop("LC_COLLATE", None) assert os.environ.get("LANG") == unkData[0] - assert not ("LANGUAGE" in os.environ.keys()) + assert "LANGUAGE" not in os.environ.keys() assert os.environ.get("LC_CTYPE") == unkData[1] - assert not ("LC_COLLATE" in os.environ.keys()) + assert "LC_COLLATE" not in os.environ.keys() assert os.getenv('LANG') == unkData[0] assert os.getenv('LANGUAGE') is None @@ -186,6 +186,6 @@ def helper__restore_envvar(name, prev_value): @staticmethod def helper__skip_test_if_util_not_exist(name: str): - assert type(name) == str # noqa: E721 + assert type(name) is str if not util_exists(name): pytest.skip('might be missing') diff --git a/tests/units/node/PostgresNode/test_setM001__start.py b/tests/units/node/PostgresNode/test_setM001__start.py index 09dc7ab8..f68b63b1 100644 --- a/tests/units/node/PostgresNode/test_setM001__start.py +++ b/tests/units/node/PostgresNode/test_setM001__start.py @@ -34,7 +34,7 @@ class tagData001: wait: typing.Optional[bool] def __init__(self, wait: typing.Optional[bool]): - assert wait is None or type(wait) == bool # noqa: E721 + assert wait is None or type(wait) is bool self.wait = wait return @@ -59,10 +59,10 @@ def test_001__wait_true( ): assert isinstance(node_svc, PostgresNodeService) assert type(data001) == __class__.tagData001 # noqa: E721 - assert data001.wait is None or type(data001.wait) == bool # noqa: E721 + assert data001.wait is None or type(data001.wait) is bool with PostgresNodeTestUtils.get_node(node_svc) as node: - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode node.init() assert not node.is_started assert node.status() == NodeStatus.Stopped @@ -78,7 +78,7 @@ def test_001__wait_true( assert node.status() == NodeStatus.Running # Internals - assert type(node._manually_started_pm_pid) == int # noqa: E721 + assert type(node._manually_started_pm_pid) is int assert node._manually_started_pm_pid != 0 assert node._manually_started_pm_pid != node._C_PM_PID__IS_NOT_DETECTED assert node._manually_started_pm_pid == node.pid @@ -92,7 +92,7 @@ def test_002__wait_false(self, node_svc: PostgresNodeService): attempt = 0 while True: - assert type(attempt) == int # noqa: E721 + assert type(attempt) is int assert attempt >= 0 assert attempt <= C_MAX_ATTEMPTS @@ -107,7 +107,7 @@ def test_002__wait_false(self, node_svc: PostgresNodeService): HelperUtils.PrintAndSleep(5) with PostgresNodeTestUtils.get_node(node_svc) as node: - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode node.init() assert not node.is_started assert node.status() == NodeStatus.Stopped @@ -118,7 +118,7 @@ def test_002__wait_false(self, node_svc: PostgresNodeService): assert node.status() in [NodeStatus.Stopped, NodeStatus.Running] # Internals - assert type(node._manually_started_pm_pid) == int # noqa: E721 + assert type(node._manually_started_pm_pid) is int assert node._manually_started_pm_pid == node._C_PM_PID__IS_NOT_DETECTED logging.info("Wait for running state ...") @@ -147,7 +147,7 @@ def test_003__exec_env( assert isinstance(node_svc, PostgresNodeService) with PostgresNodeTestUtils.get_node(node_svc) as node: - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode node.init() assert not node.is_started assert node.status() == NodeStatus.Stopped @@ -164,7 +164,7 @@ def test_003__exec_env( assert node.status() == NodeStatus.Running with node.connect(dbname="postgres") as cn: - assert type(cn) == NodeConnection # noqa: E721 + assert type(cn) is NodeConnection cn.execute("CREATE TEMP TABLE cmd_out(content text);") cn.commit() @@ -173,7 +173,7 @@ def test_003__exec_env( )) cn.commit() recs = cn.execute("select content from cmd_out;") - assert type(recs) == list # noqa: E721 + assert type(recs) is list assert len(recs) == 1 assert type(recs[0]) == tuple # noqa: E721 rec = recs[0] @@ -189,7 +189,7 @@ def test_004__params_is_None( assert isinstance(node_svc, PostgresNodeService) with PostgresNodeTestUtils.get_node(node_svc) as node: - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode node.init() assert not node.is_started assert node.status() == NodeStatus.Stopped @@ -206,7 +206,7 @@ def test_005__params_is_empty( assert isinstance(node_svc, PostgresNodeService) with PostgresNodeTestUtils.get_node(node_svc) as node: - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode node.init() assert not node.is_started assert node.status() == NodeStatus.Stopped diff --git a/tests/units/node/PostgresNode/test_setM002__start2.py b/tests/units/node/PostgresNode/test_setM002__start2.py index fe50944c..1cd71e27 100644 --- a/tests/units/node/PostgresNode/test_setM002__start2.py +++ b/tests/units/node/PostgresNode/test_setM002__start2.py @@ -34,7 +34,7 @@ class tagData001: wait: typing.Optional[bool] def __init__(self, wait: typing.Optional[bool]): - assert wait is None or type(wait) == bool # noqa: E721 + assert wait is None or type(wait) is bool self.wait = wait return @@ -59,10 +59,10 @@ def test_001__wait_true( ): assert isinstance(node_svc, PostgresNodeService) assert type(data001) == __class__.tagData001 # noqa: E721 - assert data001.wait is None or type(data001.wait) == bool # noqa: E721 + assert data001.wait is None or type(data001.wait) is bool with PostgresNodeTestUtils.get_node(node_svc) as node: - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode node.init() assert not node.is_started assert node.status() == NodeStatus.Stopped @@ -89,7 +89,7 @@ def test_002__wait_false(self, node_svc: PostgresNodeService): attempt = 0 while True: - assert type(attempt) == int # noqa: E721 + assert type(attempt) is int assert attempt >= 0 assert attempt <= C_MAX_ATTEMPTS @@ -102,7 +102,7 @@ def test_002__wait_false(self, node_svc: PostgresNodeService): HelperUtils.PrintAndSleep(5) with PostgresNodeTestUtils.get_node(node_svc) as node: - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode node.init() assert not node.is_started assert node.status() == NodeStatus.Stopped @@ -141,7 +141,7 @@ def test_003__exec_env( assert isinstance(node_svc, PostgresNodeService) with PostgresNodeTestUtils.get_node(node_svc) as node: - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode node.init() assert not node.is_started assert node.status() == NodeStatus.Stopped @@ -158,7 +158,7 @@ def test_003__exec_env( assert node.status() == NodeStatus.Running with node.connect(dbname="postgres") as cn: - assert type(cn) == NodeConnection # noqa: E721 + assert type(cn) is NodeConnection cn.execute("CREATE TEMP TABLE cmd_out(content text);") cn.commit() @@ -167,7 +167,7 @@ def test_003__exec_env( )) cn.commit() recs = cn.execute("select content from cmd_out;") - assert type(recs) == list # noqa: E721 + assert type(recs) is list assert len(recs) == 1 assert type(recs[0]) == tuple # noqa: E721 rec = recs[0] @@ -183,7 +183,7 @@ def test_004__params_is_None( assert isinstance(node_svc, PostgresNodeService) with PostgresNodeTestUtils.get_node(node_svc) as node: - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode node.init() assert not node.is_started assert node.status() == NodeStatus.Stopped @@ -200,7 +200,7 @@ def test_005__params_is_empty( assert isinstance(node_svc, PostgresNodeService) with PostgresNodeTestUtils.get_node(node_svc) as node: - assert type(node) == PostgresNode # noqa: E721 + assert type(node) is PostgresNode node.init() assert not node.is_started assert node.status() == NodeStatus.Stopped