[issue12009] netrc module crashes if netrc file has comment lines
R. David Murray
report at bugs.python.org
Tue May 17 19:04:07 CEST 2011
R. David Murray <rdmurray at bitdance.com> added the comment:
With these new additions, the test input is getting unwieldy. If you have the time, I'd like to see the unit tests refactored to be more unit-testy. That is, instead of a single test netrc file, have multiple inputs, one for each thing being tested, and turn setUp into a factory function that each test calls:
def make_nrc (self, test_data):
mode = 'w'
if sys.platform not in ['cygwin']:
mode += 't'
fp = open(temp_filename, mode)
fp.write(test_data)
fp.close()
return netrc.netrc(temp_filename)
You can also use textwrap.dedent to embed the test_string in the call to make_nrc in the test method in a pretty fashion:
def test_default_login(self):
nrc = self.make_nrc(textwrap.dedent("""\
default login log2 password pass2
""")
self.assertEqual(self.nrc.hosts['default'], ('log2', None, 'pass2'))
If you don't have time to do this I'll do it at some point (not sure when).
I haven't looked at your fix in detail because the unit tests don't currently isolate the issues, but it looks to like it is the right approach.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12009>
_______________________________________
More information about the Python-bugs-list
mailing list