Catch situations where currentframe() returns None. See SF patch #1447410, this is...
[python.git] / Lib / test / test_netrc.py
blobb536255aba3d36126159c06ffe94f0b64324bbfb
2 import netrc, os, unittest, sys
3 from test import test_support
5 TEST_NETRC = """
6 machine foo login log1 password pass1 account acct1
8 macdef macro1
9 line1
10 line2
12 macdef macro2
13 line3
14 line4
16 default login log2 password pass2
18 """
20 temp_filename = test_support.TESTFN
22 class NetrcTestCase(unittest.TestCase):
24 def setUp (self):
25 mode = 'w'
26 if sys.platform not in ['cygwin']:
27 mode += 't'
28 fp = open(temp_filename, mode)
29 fp.write(TEST_NETRC)
30 fp.close()
31 self.netrc = netrc.netrc(temp_filename)
33 def tearDown (self):
34 del self.netrc
35 os.unlink(temp_filename)
37 def test_case_1(self):
38 self.assert_(self.netrc.macros == {'macro1':['line1\n', 'line2\n'],
39 'macro2':['line3\n', 'line4\n']}
41 self.assert_(self.netrc.hosts['foo'] == ('log1', 'acct1', 'pass1'))
42 self.assert_(self.netrc.hosts['default'] == ('log2', None, 'pass2'))
44 def test_main():
45 test_support.run_unittest(NetrcTestCase)
47 if __name__ == "__main__":
48 test_main()