Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 089ab9b

Browse files
author
v.shepard
committed
PBCKP-588 fixes after review - remove f-strings
1 parent 0528541 commit 089ab9b

File tree

6 files changed

+37
-38
lines changed

6 files changed

+37
-38
lines changed

testgres/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def execute(self, query, *args):
111111

112112
return res
113113
except Exception as e:
114-
print(f"Error executing query: {e}")
114+
print("Error executing query: {}".format(e))
115115
return None
116116

117117
def close(self):

testgres/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ def safe_psql(self, query=None, expect_error=False, **kwargs):
10061006
else:
10071007
raise QueryException(err or b'', query)
10081008
elif expect_error:
1009-
assert False, f"Exception was expected, but query finished successfully: `{query}` "
1009+
assert False, "Exception was expected, but query finished successfully: `{}` ".format(query)
10101010

10111011
return out
10121012

testgres/operations/local_ops.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def exec_command(self, cmd, wait_exit=False, verbose=False,
8484
if exit_status != 0 or found_error:
8585
if exit_status == 0:
8686
exit_status = 1
87-
raise ExecUtilException(message=f'Utility exited with non-zero code. Error `{error}`',
87+
raise ExecUtilException(message='Utility exited with non-zero code. Error `{}`'.format(error),
8888
command=cmd,
8989
exit_code=exit_status,
9090
out=result)
@@ -138,7 +138,7 @@ def pathsep(self):
138138
elif os_name == "nt":
139139
pathsep = ";"
140140
else:
141-
raise Exception(f"Unsupported operating system: {os_name}")
141+
raise Exception("Unsupported operating system: {}".format(os_name))
142142
return pathsep
143143

144144
def mkdtemp(self, prefix=None):
@@ -242,7 +242,7 @@ def remove_file(self, filename):
242242
# Processes control
243243
def kill(self, pid, signal):
244244
# Kill the process
245-
cmd = f"kill -{signal} {pid}"
245+
cmd = "kill -{} {}".format(signal, pid)
246246
return self.exec_command(cmd)
247247

248248
def get_pid(self):

testgres/operations/remote_ops.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def __init__(self, ssh, pid):
2626
self.pid = pid
2727

2828
def kill(self):
29-
command = f"kill {self.pid}"
29+
command = "kill {}".format(self.pid)
3030
self.ssh.exec_command(command)
3131

3232
def cmdline(self):
33-
command = f"ps -p {self.pid} -o cmd --no-headers"
33+
command = "ps -p {} -o cmd --no-headers".format(self.pid)
3434
stdin, stdout, stderr = self.ssh.exec_command(command)
3535
cmdline = stdout.read().decode('utf-8').strip()
3636
return cmdline.split()
@@ -84,9 +84,9 @@ def _read_ssh_key(self):
8484
key = paramiko.RSAKey.from_private_key_file(self.ssh_key)
8585
return key
8686
except FileNotFoundError:
87-
raise ExecUtilException(message=f"No such file or directory: '{self.ssh_key}'")
87+
raise ExecUtilException(message="No such file or directory: '{}'".format(self.ssh_key))
8888
except Exception as e:
89-
ExecUtilException(message=f"An error occurred while reading the ssh key: {e}")
89+
ExecUtilException(message="An error occurred while reading the ssh key: {}".format(e))
9090

9191
def exec_command(self, cmd: str, wait_exit=False, verbose=False, expect_error=False,
9292
encoding=None, shell=True, text=False, input=None, stdout=None,
@@ -131,7 +131,7 @@ def exec_command(self, cmd: str, wait_exit=False, verbose=False, expect_error=Fa
131131
if error_found:
132132
if exit_status == 0:
133133
exit_status = 1
134-
raise ExecUtilException(message=f"Utility exited with non-zero code. Error: {error.decode(encoding or 'utf-8')}",
134+
raise ExecUtilException(message="Utility exited with non-zero code. Error: {}".format(error.decode(encoding or 'utf-8')),
135135
command=cmd,
136136
exit_code=exit_status,
137137
out=result)
@@ -148,7 +148,7 @@ def environ(self, var_name: str) -> str:
148148
Args:
149149
- var_name (str): The name of the environment variable.
150150
"""
151-
cmd = f"echo ${var_name}"
151+
cmd = "echo ${}".format(var_name)
152152
return self.exec_command(cmd, encoding='utf-8').strip()
153153

154154
def find_executable(self, executable):
@@ -166,7 +166,7 @@ def find_executable(self, executable):
166166

167167
def is_executable(self, file):
168168
# Check if the file is executable
169-
is_exec = self.exec_command(f"test -x {file} && echo OK")
169+
is_exec = self.exec_command("test -x {} && echo OK".format(file))
170170
return is_exec == b"OK\n"
171171

172172
def set_env(self, var_name: str, var_val: str):
@@ -176,7 +176,7 @@ def set_env(self, var_name: str, var_val: str):
176176
- var_name (str): The name of the environment variable.
177177
- var_val (str): The value to be set for the environment variable.
178178
"""
179-
return self.exec_command(f"export {var_name}={var_val}")
179+
return self.exec_command("export {}={}".format(var_name, var_val))
180180

181181
# Get environment variables
182182
def get_user(self):
@@ -195,12 +195,12 @@ def makedirs(self, path, remove_existing=False):
195195
- remove_existing (bool): If True, the existing directory at the path will be removed.
196196
"""
197197
if remove_existing:
198-
cmd = f"rm -rf {path} && mkdir -p {path}"
198+
cmd = "rm -rf {} && mkdir -p {}".format(path, path)
199199
else:
200-
cmd = f"mkdir -p {path}"
200+
cmd = "mkdir -p {}".format(path)
201201
exit_status, result, error = self.exec_command(cmd, verbose=True)
202202
if exit_status != 0:
203-
raise Exception(f"Couldn't create dir {path} because of error {error}")
203+
raise Exception("Couldn't create dir {} because of error {}".format(path, error))
204204
return result
205205

206206
def rmdirs(self, path, verbose=False, ignore_errors=True):
@@ -211,7 +211,7 @@ def rmdirs(self, path, verbose=False, ignore_errors=True):
211211
- verbose (bool): If True, return exit status, result, and error.
212212
- ignore_errors (bool): If True, do not raise error if directory does not exist.
213213
"""
214-
cmd = f"rm -rf {path}"
214+
cmd = "rm -rf {}".format(path)
215215
exit_status, result, error = self.exec_command(cmd, verbose=True)
216216
if verbose:
217217
return exit_status, result, error
@@ -224,11 +224,11 @@ def listdir(self, path):
224224
Args:
225225
path (str): The path to the directory.
226226
"""
227-
result = self.exec_command(f"ls {path}")
227+
result = self.exec_command("ls {}".format(path))
228228
return result.splitlines()
229229

230230
def path_exists(self, path):
231-
result = self.exec_command(f"test -e {path}; echo $?", encoding='utf-8')
231+
result = self.exec_command("test -e {}; echo $?".format(path), encoding='utf-8')
232232
return int(result.strip()) == 0
233233

234234
@property
@@ -239,7 +239,7 @@ def pathsep(self):
239239
elif os_name == "nt":
240240
pathsep = ";"
241241
else:
242-
raise Exception(f"Unsupported operating system: {os_name}")
242+
raise Exception("Unsupported operating system: {}".format(os_name))
243243
return pathsep
244244

245245
def mkdtemp(self, prefix=None):
@@ -249,7 +249,7 @@ def mkdtemp(self, prefix=None):
249249
- prefix (str): The prefix of the temporary directory name.
250250
"""
251251
if prefix:
252-
temp_dir = self.exec_command(f"mktemp -d {prefix}XXXXX", encoding='utf-8')
252+
temp_dir = self.exec_command("mktemp -d {}XXXXX".format(prefix), encoding='utf-8')
253253
else:
254254
temp_dir = self.exec_command("mktemp -d", encoding='utf-8')
255255

@@ -262,7 +262,7 @@ def mkdtemp(self, prefix=None):
262262

263263
def mkstemp(self, prefix=None):
264264
if prefix:
265-
temp_dir = self.exec_command(f"mktemp {prefix}XXXXX", encoding='utf-8')
265+
temp_dir = self.exec_command("mktemp {}XXXXX".format(prefix), encoding='utf-8')
266266
else:
267267
temp_dir = self.exec_command("mktemp", encoding='utf-8')
268268

@@ -277,8 +277,8 @@ def copytree(self, src, dst):
277277
if not os.path.isabs(dst):
278278
dst = os.path.join('~', dst)
279279
if self.isdir(dst):
280-
raise FileExistsError(f"Directory {dst} already exists.")
281-
return self.exec_command(f"cp -r {src} {dst}")
280+
raise FileExistsError("Directory {} already exists.".format(dst))
281+
return self.exec_command("cp -r {} {}".format(src, dst))
282282

283283
# Work with files
284284
def write(self, filename, data, truncate=False, binary=False, read_and_write=False, encoding='utf-8'):
@@ -344,10 +344,10 @@ def touch(self, filename):
344344
345345
This method behaves as the 'touch' command in Unix. It's equivalent to calling 'touch filename' in the shell.
346346
"""
347-
self.exec_command(f"touch {filename}")
347+
self.exec_command("touch {}".format(filename))
348348

349349
def read(self, filename, binary=False, encoding=None):
350-
cmd = f"cat {filename}"
350+
cmd = "cat {}".format(filename)
351351
result = self.exec_command(cmd, encoding=encoding)
352352

353353
if not binary and result:
@@ -357,9 +357,9 @@ def read(self, filename, binary=False, encoding=None):
357357

358358
def readlines(self, filename, num_lines=0, binary=False, encoding=None):
359359
if num_lines > 0:
360-
cmd = f"tail -n {num_lines} {filename}"
360+
cmd = "tail -n {} {}".format(num_lines, filename)
361361
else:
362-
cmd = f"cat {filename}"
362+
cmd = "cat {}".format(filename)
363363

364364
result = self.exec_command(cmd, encoding=encoding)
365365

@@ -371,31 +371,31 @@ def readlines(self, filename, num_lines=0, binary=False, encoding=None):
371371
return lines
372372

373373
def isfile(self, remote_file):
374-
stdout = self.exec_command(f"test -f {remote_file}; echo $?")
374+
stdout = self.exec_command("test -f {}; echo $?".format(remote_file))
375375
result = int(stdout.strip())
376376
return result == 0
377377

378378
def isdir(self, dirname):
379-
cmd = f"if [ -d {dirname} ]; then echo True; else echo False; fi"
379+
cmd = "if [ -d {} ]; then echo True; else echo False; fi".format(dirname)
380380
response = self.exec_command(cmd)
381381
return response.strip() == b"True"
382382

383383
def remove_file(self, filename):
384-
cmd = f"rm {filename}"
384+
cmd = "rm {}".format(filename)
385385
return self.exec_command(cmd)
386386

387387
# Processes control
388388
def kill(self, pid, signal):
389389
# Kill the process
390-
cmd = f"kill -{signal} {pid}"
390+
cmd = "kill -{} {}".format(signal, pid)
391391
return self.exec_command(cmd)
392392

393393
def get_pid(self):
394394
# Get current process id
395395
return int(self.exec_command("echo $$", encoding='utf-8'))
396396

397397
def get_process_children(self, pid):
398-
command = f"pgrep -P {pid}"
398+
command = "pgrep -P {}".format(pid)
399399
stdin, stdout, stderr = self.ssh.exec_command(command)
400400
children = stdout.readlines()
401401
return [PsUtilProcessProxy(self.ssh, int(child_pid.strip())) for child_pid in children]
@@ -437,4 +437,4 @@ def db_connect(self, dbname, user, password=None, host="127.0.0.1", port=5432, s
437437
return conn
438438
except Exception as e:
439439
self.tunnel.stop()
440-
raise ExecUtilException("Could not create db tunnel.")
440+
raise ExecUtilException("Could not create db tunnel. {}".format(e))

testgres/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def execute_utility(args, logfile=None, verbose=False):
7272
lines = [u'\n'] + ['# ' + line for line in out.splitlines()] + [u'\n']
7373
tconf.os_ops.write(filename=logfile, data=lines)
7474
except IOError:
75-
raise ExecUtilException(f"Problem with writing to logfile `{logfile}` during run command `{args}`")
75+
raise ExecUtilException("Problem with writing to logfile `{}` during run command `{}`".format(logfile, args))
7676
if verbose:
7777
return exit_status, out, error
7878
else:

tests/test_simple_remote.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,8 @@ def test_pgbench(self):
750750

751751
# run TPC-B benchmark
752752
out = node.pgbench(stdout=subprocess.PIPE,
753-
stderr=subprocess.STDOUT,
754-
options=['-T3'])
755-
753+
stderr=subprocess.STDOUT,
754+
options=['-T3'])
756755
self.assertTrue(b'tps = ' in out)
757756

758757
def test_pg_config(self):

0 commit comments

Comments
 (0)