Skip to content

Usage of @staticmethod #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions testgres/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def get_remote_node(name=None, conn_params=None):
Simply a wrapper around :class:`.PostgresNode` constructor for remote node.
See :meth:`.PostgresNode.__init__` for details.
For remote connection you can add the next parameter:
conn_params = ConnectionParams(host='127.0.0.1',
ssh_key=None,
username=default_username())
conn_params = ConnectionParams(host='127.0.0.1', ssh_key=None, username=default_username())
"""
return get_new_node(name=name, conn_params=conn_params)
3 changes: 3 additions & 0 deletions testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,7 @@ def make_simple(

return node

@staticmethod
def _gettempdir_for_socket():
platform_system_name = platform.system().lower()

Expand Down Expand Up @@ -1966,6 +1967,7 @@ def _gettempdir_for_socket():

return "/tmp"

@staticmethod
def _gettempdir():
v = tempfile.gettempdir()

Expand All @@ -1984,6 +1986,7 @@ def _gettempdir():
# OK
return v

@staticmethod
def _raise_bugcheck(msg):
assert type(msg) == str # noqa: E721
assert msg != ""
Expand Down
3 changes: 3 additions & 0 deletions testgres/operations/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


class Helpers:
@staticmethod
def _make_get_default_encoding_func():
# locale.getencoding is added in Python 3.11
if hasattr(locale, 'getencoding'):
Expand All @@ -13,6 +14,7 @@ def _make_get_default_encoding_func():
# Prepared pointer on function to get a name of system codepage
_get_default_encoding_func = _make_get_default_encoding_func()

@staticmethod
def GetDefaultEncoding():
#
# Original idea/source was:
Expand All @@ -36,6 +38,7 @@ def GetDefaultEncoding():
# Is it an unexpected situation?
return 'UTF-8'

@staticmethod
def PrepareProcessInput(input, encoding):
if not input:
return None
Expand Down
2 changes: 2 additions & 0 deletions testgres/operations/local_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
data2 = __class__._prepare_data_to_write(data, binary)
file.write(data2)

@staticmethod
def _prepare_line_to_write(data, binary):
data = __class__._prepare_data_to_write(data, binary)

Expand All @@ -275,6 +276,7 @@ def _prepare_line_to_write(data, binary):
assert type(data) == str # noqa: E721
return data.rstrip('\n') + '\n'

@staticmethod
def _prepare_data_to_write(data, binary):
if isinstance(data, bytes):
return data if binary else data.decode()
Expand Down
4 changes: 4 additions & 0 deletions testgres/operations/raise_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


class RaiseError:
@staticmethod
def UtilityExitedWithNonZeroCode(cmd, exit_code, msg_arg, error, out):
assert type(exit_code) == int # noqa: E721

Expand All @@ -20,12 +21,14 @@ def UtilityExitedWithNonZeroCode(cmd, exit_code, msg_arg, error, out):
out=out,
error=error)

@staticmethod
def _TranslateDataIntoString(data):
if type(data) == bytes: # noqa: E721
return __class__._TranslateDataIntoString__FromBinary(data)

return str(data)

@staticmethod
def _TranslateDataIntoString__FromBinary(data):
assert type(data) == bytes # noqa: E721

Expand All @@ -36,6 +39,7 @@ def _TranslateDataIntoString__FromBinary(data):

return "#cannot_decode_text"

@staticmethod
def _BinaryIsASCII(data):
assert type(data) == bytes # noqa: E721

Expand Down
2 changes: 2 additions & 0 deletions testgres/operations/remote_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal

os.remove(tmp_file.name)

@staticmethod
def _prepare_line_to_write(data, binary, encoding):
data = __class__._prepare_data_to_write(data, binary, encoding)

Expand All @@ -323,6 +324,7 @@ def _prepare_line_to_write(data, binary, encoding):
assert type(data) == str # noqa: E721
return data.rstrip('\n') + '\n'

@staticmethod
def _prepare_data_to_write(data, binary, encoding):
if isinstance(data, bytes):
return data if binary else data.decode(encoding)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,7 @@ def __exit__(self, type, value, traceback):
__class__.sm_prev_testgres_reserve_port = None
__class__.sm_prev_testgres_release_port = None

@staticmethod
def _proxy__reserve_port():
assert type(__class__.sm_DummyPortMaxUsage) == int # noqa: E721
assert type(__class__.sm_DummyPortTotalUsage) == int # noqa: E721
Expand All @@ -1144,6 +1145,7 @@ def _proxy__reserve_port():
__class__.sm_DummyPortCurrentUsage += 1
return __class__.sm_DummyPortNumber

@staticmethod
def _proxy__release_port(dummyPortNumber):
assert type(dummyPortNumber) == int # noqa: E721

Expand Down