Skip to content

Commit b4cf4e6

Browse files
committed
small improvements in execute_utility()
1 parent 1975e12 commit b4cf4e6

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

testgres/exceptions.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
import six
44

55

6-
@six.python_2_unicode_compatible
76
class TestgresException(Exception):
8-
def __str__(self):
9-
s = super(TestgresException, self).__str__()
10-
return six.text_type(s)
7+
pass
118

129

10+
@six.python_2_unicode_compatible
1311
class ExecUtilException(TestgresException):
1412
def __init__(self,
1513
message=None,
@@ -30,17 +28,18 @@ def __str__(self):
3028
msg.append(self.message)
3129

3230
if self.command:
33-
msg.append('Command: {}'.format(self.command))
31+
msg.append(u'Command: {}'.format(self.command))
3432

3533
if self.exit_code:
36-
msg.append('Exit code: {}'.format(self.exit_code))
34+
msg.append(u'Exit code: {}'.format(self.exit_code))
3735

3836
if self.out:
39-
msg.append('----\n{}'.format(self.out))
37+
msg.append(u'----\n{}'.format(self.out))
4038

4139
return six.text_type('\n').join(msg)
4240

4341

42+
@six.python_2_unicode_compatible
4443
class QueryException(TestgresException):
4544
def __init__(self, message=None, query=None):
4645
super(QueryException, self).__init__(message)
@@ -55,7 +54,7 @@ def __str__(self):
5554
msg.append(self.message)
5655

5756
if self.query:
58-
msg.append('Query: {}'.format(self.query))
57+
msg.append(u'Query: {}'.format(self.query))
5958

6059
return six.text_type('\n').join(msg)
6160

@@ -68,6 +67,7 @@ class CatchUpException(QueryException):
6867
pass
6968

7069

70+
@six.python_2_unicode_compatible
7171
class StartNodeException(TestgresException):
7272
def __init__(self, message=None, files=None):
7373
super(StartNodeException, self).__init__(message)
@@ -81,8 +81,8 @@ def __str__(self):
8181
if self.message:
8282
msg.append(self.message)
8383

84-
for key, value in six.iteritems(self.files or {}):
85-
msg.append('{}\n----\n{}\n'.format(key, value))
84+
for f, lines in self.files or []:
85+
msg.append(u'{}\n----\n{}\n'.format(f, lines))
8686

8787
return six.text_type('\n').join(msg)
8888

testgres/node.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def _maybe_stop_logger(self):
217217
self._logger.stop()
218218

219219
def _collect_special_files(self):
220-
result = {}
220+
result = []
221221

222222
# list of important files + last N lines
223223
files = [
@@ -241,8 +241,8 @@ def _collect_special_files(self):
241241
# read whole file
242242
lines = _f.read().decode('utf-8')
243243

244-
# fill dict
245-
result[f] = lines
244+
# fill list
245+
result.append((f, lines))
246246

247247
return result
248248

testgres/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def execute_utility(args, logfile):
100100

101101
if out:
102102
# comment-out lines
103-
lines = ('# ' + l for l in out.splitlines())
103+
lines = ('# ' + l for l in out.splitlines(True))
104104
file_out.write(u'\n')
105105
file_out.writelines(lines)
106106

@@ -110,7 +110,7 @@ def execute_utility(args, logfile):
110110

111111
exit_code = process.returncode
112112
if exit_code:
113-
message = 'Failed to execute utility'
113+
message = 'Utility exited with non-zero code'
114114
raise ExecUtilException(message=message,
115115
command=command,
116116
exit_code=exit_code,

0 commit comments

Comments
 (0)