Skip to content

Commit d216577

Browse files
committed
Merge remote-tracking branch 'origin/master' into edge
2 parents 46d8bf6 + 260d13f commit d216577

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/support.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,20 @@ class FakeLogger:
9696

9797
def __init__(self):
9898
self.channels_dict = defaultdict(list)
99+
self.forgive_by_channel = defaultdict(lambda: False)
99100
self.unclosed_by_file = defaultdict(list)
100101

101102
def _append_as(self, channel, line):
102103
self.channels_dict[channel].append(line)
103104

104105
def check_empty_and_reset(self):
106+
channels_dict = self.channels_dict
107+
forgive_by_channel = self.forgive_by_channel
105108
unclosed_by_file = self.unclosed_by_file
106109

107110
# reset the record of any logged messages
108111
self.channels_dict = defaultdict(list)
112+
self.forgive_by_channel = defaultdict(lambda: False)
109113
self.unclosed_by_file = defaultdict(list)
110114

111115
# complain loudly (and in detail) in the case of unclosed files
@@ -114,6 +118,15 @@ def check_empty_and_reset(self):
114118
for fname, (lineno, outname) in unclosed_by_file.items()})
115119
raise RuntimeError('unclosed files encountered:\n%s' % (messages,))
116120

121+
if channels_dict['error'] and not forgive_by_channel['error']:
122+
raise RuntimeError('errors reported to logger:\n%s' % '\n'.join(channels_dict['error']))
123+
124+
125+
def forgive_errors(self):
126+
self.forgive_by_channel['error'] = True
127+
128+
# logger interface
129+
117130
def debug(self, line):
118131
self._append_as('debug', line)
119132

@@ -194,6 +207,8 @@ def setUp(self):
194207
self.before_each()
195208

196209
def tearDown(self):
210+
self.after_each()
211+
197212
if not self._skip_logging:
198213
self._logger.check_empty_and_reset()
199214
if self._logger is not None:
@@ -210,6 +225,9 @@ def tearDown(self):
210225
continue
211226

212227
# hooks
228+
def after_each(self):
229+
pass
230+
213231
def before_each(self):
214232
pass
215233

tests/test_mig_shared_fileio.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,23 @@ def setUp(self):
5858
cleanpath(os.path.dirname(DUMMY_FILE_WRITECHUNK), self)
5959

6060
def test_return_false_on_invalid_data(self):
61+
self.logger.forgive_errors()
62+
6163
# NOTE: we make sure to disable any forced stringification here
6264
did_succeed = fileio.write_chunk(self.tmp_path, 1234, 0, self.logger,
6365
force_string=False)
6466
self.assertFalse(did_succeed)
6567

6668
def test_return_false_on_invalid_offset(self):
69+
self.logger.forgive_errors()
70+
6771
did_succeed = fileio.write_chunk(self.tmp_path, DUMMY_BYTES, -42,
6872
self.logger)
6973
self.assertFalse(did_succeed)
7074

7175
def test_return_false_on_invalid_dir(self):
76+
self.logger.forgive_errors()
77+
7278
os.makedirs(self.tmp_path)
7379

7480
did_succeed = fileio.write_chunk(self.tmp_path, 1234, 0, self.logger)
@@ -138,18 +144,24 @@ def setUp(self):
138144
cleanpath(os.path.dirname(DUMMY_FILE_WRITEFILE), self)
139145

140146
def test_return_false_on_invalid_data(self):
147+
self.logger.forgive_errors()
148+
141149
# NOTE: we make sure to disable any forced stringification here
142150
did_succeed = fileio.write_file(1234, self.tmp_path, self.logger,
143151
force_string=False)
144152
self.assertFalse(did_succeed)
145153

146154
def test_return_false_on_invalid_dir(self):
155+
self.logger.forgive_errors()
156+
147157
os.makedirs(self.tmp_path)
148158

149159
did_succeed = fileio.write_file(DUMMY_BYTES, self.tmp_path, self.logger)
150160
self.assertFalse(did_succeed)
151161

152162
def test_return_false_on_missing_dir(self):
163+
self.logger.forgive_errors()
164+
153165
did_succeed = fileio.write_file(DUMMY_BYTES, self.tmp_path, self.logger,
154166
make_parent=False)
155167
self.assertFalse(did_succeed)

0 commit comments

Comments
 (0)