Skip to content

Commit f48ef31

Browse files
committed
src, config_tc: replace deprecated failUnlessRaises
1 parent 794187f commit f48ef31

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

Diff for: git/test/test_config.py

+25-13
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def test_read_write(self):
6060
self.assertEqual(file_obj.getvalue(), self._to_memcache(fixture_path(filename)).getvalue())
6161

6262
# creating an additional config writer must fail due to exclusive access
63-
self.failUnlessRaises(IOError, GitConfigParser, file_obj, read_only=False)
63+
with self.assertRaises(IOError):
64+
GitConfigParser(file_obj, read_only=False)
6465

6566
# should still have a lock and be able to make changes
6667
assert w_config._lock._has_lock()
@@ -91,18 +92,21 @@ def test_read_write(self):
9192
@with_rw_directory
9293
def test_lock_reentry(self, rw_dir):
9394
fpl = os.path.join(rw_dir, 'l')
94-
with GitConfigParser(fpl, read_only=False) as gcp:
95-
gcp.set_value('include', 'some_value', 'a')
95+
gcp = GitConfigParser(fpl, read_only=False)
96+
with gcp as cw:
97+
cw.set_value('include', 'some_value', 'a')
9698
# entering again locks the file again...
9799
with gcp as cw:
98100
cw.set_value('include', 'some_other_value', 'b')
99101
# ...so creating an additional config writer must fail due to exclusive access
100-
self.failUnlessRaises(IOError, GitConfigParser, fpl, read_only=False)
102+
with self.assertRaises(IOError):
103+
GitConfigParser(fpl, read_only=False)
101104
# but work when the lock is removed
102105
with GitConfigParser(fpl, read_only=False):
103106
assert os.path.exists(fpl)
104107
# reentering with an existing lock must fail due to exclusive access
105-
self.failUnlessRaises(IOError, gcp.__enter__)
108+
with self.assertRaises(IOError):
109+
gcp.__enter__()
106110

107111
def test_multi_line_config(self):
108112
file_obj = self._to_memcache(fixture_path("git_config_with_comments"))
@@ -144,10 +148,13 @@ def test_base(self):
144148
assert "\n" not in val
145149

146150
# writing must fail
147-
self.failUnlessRaises(IOError, r_config.set, section, option, None)
148-
self.failUnlessRaises(IOError, r_config.remove_option, section, option)
151+
with self.assertRaises(IOError):
152+
r_config.set(section, option, None)
153+
with self.assertRaises(IOError):
154+
r_config.remove_option(section, option)
149155
# END for each option
150-
self.failUnlessRaises(IOError, r_config.remove_section, section)
156+
with self.assertRaises(IOError):
157+
r_config.remove_section(section)
151158
# END for each section
152159
assert num_sections and num_options
153160
assert r_config._is_initialized is True
@@ -157,7 +164,8 @@ def test_base(self):
157164
assert r_config.get_value("doesnt", "exist", default) == default
158165

159166
# it raises if there is no default though
160-
self.failUnlessRaises(cp.NoSectionError, r_config.get_value, "doesnt", "exist")
167+
with self.assertRaises(cp.NoSectionError):
168+
r_config.get_value("doesnt", "exist")
161169

162170
@with_rw_directory
163171
def test_config_include(self, rw_dir):
@@ -206,7 +214,8 @@ def check_test_value(cr, value):
206214
write_test_value(cw, tv)
207215

208216
with GitConfigParser(fpa, read_only=True) as cr:
209-
self.failUnlessRaises(cp.NoSectionError, check_test_value, cr, tv)
217+
with self.assertRaises(cp.NoSectionError):
218+
check_test_value(cr, tv)
210219

211220
# But can make it skip includes alltogether, and thus allow write-backs
212221
with GitConfigParser(fpa, read_only=False, merge_includes=False) as cw:
@@ -218,8 +227,10 @@ def check_test_value(cr, value):
218227
def test_rename(self):
219228
file_obj = self._to_memcache(fixture_path('git_config'))
220229
with GitConfigParser(file_obj, read_only=False, merge_includes=False) as cw:
221-
self.failUnlessRaises(ValueError, cw.rename_section, "doesntexist", "foo")
222-
self.failUnlessRaises(ValueError, cw.rename_section, "core", "include")
230+
with self.assertRaises(ValueError):
231+
cw.rename_section("doesntexist", "foo")
232+
with self.assertRaises(ValueError):
233+
cw.rename_section("core", "include")
223234

224235
nn = "bee"
225236
assert cw.rename_section('core', nn) is cw
@@ -237,4 +248,5 @@ def test_empty_config_value(self):
237248

238249
assert cr.get_value('core', 'filemode'), "Should read keys with values"
239250

240-
self.failUnlessRaises(cp.NoOptionError, cr.get_value, 'color', 'ui')
251+
with self.assertRaises(cp.NoOptionError):
252+
cr.get_value('color', 'ui')

0 commit comments

Comments
 (0)