Fix typo and add test case.
This commit is contained in:
parent
31c604d3a7
commit
42d544505f
|
@ -493,11 +493,10 @@ class RawConfigParser:
|
||||||
read_ok = []
|
read_ok = []
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
try:
|
try:
|
||||||
fp = open(filename, encoding=encoding)
|
with open(filename, encoding=encoding) as fp:
|
||||||
|
self._read(fp, filename)
|
||||||
except IOError:
|
except IOError:
|
||||||
continue
|
continue
|
||||||
self._read(fp, filename)
|
|
||||||
fp.close()
|
|
||||||
read_ok.append(filename)
|
read_ok.append(filename)
|
||||||
return read_ok
|
return read_ok
|
||||||
|
|
||||||
|
@ -511,7 +510,7 @@ class RawConfigParser:
|
||||||
"""
|
"""
|
||||||
if source is None:
|
if source is None:
|
||||||
try:
|
try:
|
||||||
srouce = f.name
|
source = f.name
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
source = '<???>'
|
source = '<???>'
|
||||||
self._read(f, source)
|
self._read(f, source)
|
||||||
|
|
|
@ -328,9 +328,24 @@ boolean {0[0]} NO
|
||||||
e = self.parse_error(cf, configparser.ParsingError,
|
e = self.parse_error(cf, configparser.ParsingError,
|
||||||
"[Foo]\n wrong-indent\n")
|
"[Foo]\n wrong-indent\n")
|
||||||
self.assertEqual(e.args, ('<???>',))
|
self.assertEqual(e.args, ('<???>',))
|
||||||
|
# read_file on a real file
|
||||||
|
tricky = support.findfile("cfgparser.3")
|
||||||
|
if self.delimiters[0] == '=':
|
||||||
|
error = configparser.ParsingError
|
||||||
|
expected = (tricky,)
|
||||||
|
else:
|
||||||
|
error = configparser.MissingSectionHeaderError
|
||||||
|
expected = (tricky, 1,
|
||||||
|
' # INI with as many tricky parts as possible\n')
|
||||||
|
with open(tricky) as f:
|
||||||
|
e = self.parse_error(cf, error, f)
|
||||||
|
self.assertEqual(e.args, expected)
|
||||||
|
|
||||||
def parse_error(self, cf, exc, src):
|
def parse_error(self, cf, exc, src):
|
||||||
sio = io.StringIO(src)
|
if hasattr(src, 'readline'):
|
||||||
|
sio = src
|
||||||
|
else:
|
||||||
|
sio = io.StringIO(src)
|
||||||
with self.assertRaises(exc) as cm:
|
with self.assertRaises(exc) as cm:
|
||||||
cf.read_file(sio)
|
cf.read_file(sio)
|
||||||
return cm.exception
|
return cm.exception
|
||||||
|
|
Loading…
Reference in New Issue