Skip to content

Commit cd0b5f8

Browse files
Code normalization
- New debug checks - Normalization
1 parent 7b70e9e commit cd0b5f8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

testgres/operations/local_ops.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,32 @@ def _run_command__generic(self, cmd, shell, input, stdin, stdout, stderr, get_pr
8686
if not get_process:
8787
input_prepared = Helpers.PrepareProcessInput(input, encoding) # throw
8888

89+
assert input_prepared is None or (type(input_prepared) == bytes) # noqa: E721
90+
8991
process = subprocess.Popen(
9092
cmd,
9193
shell=shell,
9294
stdin=stdin or subprocess.PIPE if input is not None else None,
9395
stdout=stdout or subprocess.PIPE,
9496
stderr=stderr or subprocess.PIPE,
9597
)
98+
assert not (process is None)
9699
if get_process:
97100
return process, None, None
98101
try:
99102
output, error = process.communicate(input=input_prepared, timeout=timeout)
100-
if encoding:
101-
output = output.decode(encoding)
102-
error = error.decode(encoding)
103-
return process, output, error
104103
except subprocess.TimeoutExpired:
105104
process.kill()
106105
raise ExecUtilException("Command timed out after {} seconds.".format(timeout))
107106

107+
assert type(output) == bytes # noqa: E721
108+
assert type(error) == bytes # noqa: E721
109+
110+
if encoding:
111+
output = output.decode(encoding)
112+
error = error.decode(encoding)
113+
return process, output, error
114+
108115
def _run_command(self, cmd, shell, input, stdin, stdout, stderr, get_process, timeout, encoding):
109116
"""Execute a command and return the process and its output."""
110117
if os.name == 'nt' and stdout is None: # Windows

testgres/operations/remote_ops.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,15 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
7575
if not get_process:
7676
input_prepared = Helpers.PrepareProcessInput(input, encoding) # throw
7777

78+
assert input_prepared is None or (type(input_prepared) == bytes) # noqa: E721
79+
7880
ssh_cmd = []
7981
if isinstance(cmd, str):
8082
ssh_cmd = ['ssh', self.ssh_dest] + self.ssh_args + [cmd]
8183
elif isinstance(cmd, list):
8284
ssh_cmd = ['ssh', self.ssh_dest] + self.ssh_args + cmd
8385
process = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
86+
assert not (process is None)
8487
if get_process:
8588
return process
8689

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