| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,7 +60,8 @@ def test_read_write(self): | |||
| 60 | 60 | self.assertEqual(file_obj.getvalue(), self._to_memcache(fixture_path(filename)).getvalue()) | |
| 61 | 61 | ||
| 62 | 62 | # 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) | ||
| 64 | 65 | ||
| 65 | 66 | # should still have a lock and be able to make changes | |
| 66 | 67 | assert w_config._lock._has_lock() | |
@@ -91,18 +92,21 @@ def test_read_write(self): | |||
| 91 | 92 | @with_rw_directory | |
| 92 | 93 | def test_lock_reentry(self, rw_dir): | |
| 93 | 94 | 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') | ||
| 96 | 98 | # entering again locks the file again... | |
| 97 | 99 | with gcp as cw: | |
| 98 | 100 | cw.set_value('include', 'some_other_value', 'b') | |
| 99 | 101 | # ...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) | ||
| 101 | 104 | # but work when the lock is removed | |
| 102 | 105 | with GitConfigParser(fpl, read_only=False): | |
| 103 | 106 | assert os.path.exists(fpl) | |
| 104 | 107 | # 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__() | ||
| 106 | 110 | ||
| 107 | 111 | def test_multi_line_config(self): | |
| 108 | 112 | file_obj = self._to_memcache(fixture_path("git_config_with_comments")) | |
@@ -144,10 +148,13 @@ def test_base(self): | |||
| 144 | 148 | assert "\n" not in val | |
| 145 | 149 | ||
| 146 | 150 | # 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) | ||
| 149 | 155 | # END for each option | |
| 150 | - self.failUnlessRaises(IOError, r_config.remove_section, section) | ||
| 156 | + with self.assertRaises(IOError): | ||
| 157 | + r_config.remove_section(section) | ||
| 151 | 158 | # END for each section | |
| 152 | 159 | assert num_sections and num_options | |
| 153 | 160 | assert r_config._is_initialized is True | |
@@ -157,7 +164,8 @@ def test_base(self): | |||
| 157 | 164 | assert r_config.get_value("doesnt", "exist", default) == default | |
| 158 | 165 | ||
| 159 | 166 | # 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") | ||
| 161 | 169 | ||
| 162 | 170 | @with_rw_directory | |
| 163 | 171 | def test_config_include(self, rw_dir): | |
@@ -206,7 +214,8 @@ def check_test_value(cr, value): | |||
| 206 | 214 | write_test_value(cw, tv) | |
| 207 | 215 | ||
| 208 | 216 | 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) | ||
| 210 | 219 | ||
| 211 | 220 | # But can make it skip includes alltogether, and thus allow write-backs | |
| 212 | 221 | with GitConfigParser(fpa, read_only=False, merge_includes=False) as cw: | |
@@ -218,8 +227,10 @@ def check_test_value(cr, value): | |||
| 218 | 227 | def test_rename(self): | |
| 219 | 228 | file_obj = self._to_memcache(fixture_path('git_config')) | |
| 220 | 229 | 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") | ||
| 223 | 234 | ||
| 224 | 235 | nn = "bee" | |
| 225 | 236 | assert cw.rename_section('core', nn) is cw | |
@@ -237,4 +248,5 @@ def test_empty_config_value(self): | |||
| 237 | 248 | ||
| 238 | 249 | assert cr.get_value('core', 'filemode'), "Should read keys with values" | |
| 239 | 250 | ||
| 240 | - self.failUnlessRaises(cp.NoOptionError, cr.get_value, 'color', 'ui') | ||
| 251 | + with self.assertRaises(cp.NoOptionError): | ||
| 252 | + cr.get_value('color', 'ui') | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments