Skip to content

Commit 40eaf7d

Browse files
Usage of @staticmethod (#189)
* Usage of @staticmethod All the known static methods are marked with @staticmethod decorators. * Fix for "ERROR: Unexpected indentation. [docutils]" This commit should fix an unstable error in CI: /pg/testgres/testgres/api.py:docstring of testgres.api.get_remote_node:5: ERROR: Unexpected indentation. [docutils]
1 parent 44b99f0 commit 40eaf7d

File tree

7 files changed

+17
-3
lines changed

7 files changed

+17
-3
lines changed

testgres/api.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ def get_remote_node(name=None, conn_params=None):
4747
Simply a wrapper around :class:`.PostgresNode` constructor for remote node.
4848
See :meth:`.PostgresNode.__init__` for details.
4949
For remote connection you can add the next parameter:
50-
conn_params = ConnectionParams(host='127.0.0.1',
51-
ssh_key=None,
52-
username=default_username())
50+
conn_params = ConnectionParams(host='127.0.0.1', ssh_key=None, username=default_username())
5351
"""
5452
return get_new_node(name=name, conn_params=conn_params)

testgres/node.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,7 @@ def make_simple(
19391939

19401940
return node
19411941

1942+
@staticmethod
19421943
def _gettempdir_for_socket():
19431944
platform_system_name = platform.system().lower()
19441945

@@ -1966,6 +1967,7 @@ def _gettempdir_for_socket():
19661967

19671968
return "/tmp"
19681969

1970+
@staticmethod
19691971
def _gettempdir():
19701972
v = tempfile.gettempdir()
19711973

@@ -1984,6 +1986,7 @@ def _gettempdir():
19841986
# OK
19851987
return v
19861988

1989+
@staticmethod
19871990
def _raise_bugcheck(msg):
19881991
assert type(msg) == str # noqa: E721
19891992
assert msg != ""

testgres/operations/helpers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

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

17+
@staticmethod
1618
def GetDefaultEncoding():
1719
#
1820
# Original idea/source was:
@@ -36,6 +38,7 @@ def GetDefaultEncoding():
3638
# Is it an unexpected situation?
3739
return 'UTF-8'
3840

41+
@staticmethod
3942
def PrepareProcessInput(input, encoding):
4043
if not input:
4144
return None

testgres/operations/local_ops.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
265265
data2 = __class__._prepare_data_to_write(data, binary)
266266
file.write(data2)
267267

268+
@staticmethod
268269
def _prepare_line_to_write(data, binary):
269270
data = __class__._prepare_data_to_write(data, binary)
270271

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

279+
@staticmethod
278280
def _prepare_data_to_write(data, binary):
279281
if isinstance(data, bytes):
280282
return data if binary else data.decode()

testgres/operations/raise_error.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
class RaiseError:
6+
@staticmethod
67
def UtilityExitedWithNonZeroCode(cmd, exit_code, msg_arg, error, out):
78
assert type(exit_code) == int # noqa: E721
89

@@ -20,12 +21,14 @@ def UtilityExitedWithNonZeroCode(cmd, exit_code, msg_arg, error, out):
2021
out=out,
2122
error=error)
2223

24+
@staticmethod
2325
def _TranslateDataIntoString(data):
2426
if type(data) == bytes: # noqa: E721
2527
return __class__._TranslateDataIntoString__FromBinary(data)
2628

2729
return str(data)
2830

31+
@staticmethod
2932
def _TranslateDataIntoString__FromBinary(data):
3033
assert type(data) == bytes # noqa: E721
3134

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

3740
return "#cannot_decode_text"
3841

42+
@staticmethod
3943
def _BinaryIsASCII(data):
4044
assert type(data) == bytes # noqa: E721
4145

testgres/operations/remote_ops.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
313313

314314
os.remove(tmp_file.name)
315315

316+
@staticmethod
316317
def _prepare_line_to_write(data, binary, encoding):
317318
data = __class__._prepare_data_to_write(data, binary, encoding)
318319

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

327+
@staticmethod
326328
def _prepare_data_to_write(data, binary, encoding):
327329
if isinstance(data, bytes):
328330
return data if binary else data.decode(encoding)

tests/test_simple.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ def __exit__(self, type, value, traceback):
11251125
__class__.sm_prev_testgres_reserve_port = None
11261126
__class__.sm_prev_testgres_release_port = None
11271127

1128+
@staticmethod
11281129
def _proxy__reserve_port():
11291130
assert type(__class__.sm_DummyPortMaxUsage) == int # noqa: E721
11301131
assert type(__class__.sm_DummyPortTotalUsage) == int # noqa: E721
@@ -1144,6 +1145,7 @@ def _proxy__reserve_port():
11441145
__class__.sm_DummyPortCurrentUsage += 1
11451146
return __class__.sm_DummyPortNumber
11461147

1148+
@staticmethod
11471149
def _proxy__release_port(dummyPortNumber):
11481150
assert type(dummyPortNumber) == int # noqa: E721
11491151

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy