0001 0002 import netrc, os, unittest, sys 0003 from test import test_support 0004 0005 TEST_NETRC = """ 0006 machine foo login log1 password pass1 account acct1 0007 0008 macdef macro1 0009 line1 0010 line2 0011 0012 macdef macro2 0013 line3 0014 line4 0015 0016 default login log2 password pass2 0017 0018 """ 0019 0020 temp_filename = test_support.TESTFN 0021 0022 class NetrcTestCase(unittest.TestCase): 0023 0024 def setUp (self): 0025 mode = 'w' 0026 if sys.platform not in ['cygwin']: 0027 mode += 't' 0028 fp = open(temp_filename, mode) 0029 fp.write(TEST_NETRC) 0030 fp.close() 0031 self.netrc = netrc.netrc(temp_filename) 0032 0033 def tearDown (self): 0034 del self.netrc 0035 os.unlink(temp_filename) 0036 0037 def test_case_1(self): 0038 self.assert_(self.netrc.macros == {'macro1':['line1\n', 'line2\n'], 0039 'macro2':['line3\n', 'line4\n']} 0040 ) 0041 self.assert_(self.netrc.hosts['foo'] == ('log1', 'acct1', 'pass1')) 0042 self.assert_(self.netrc.hosts['default'] == ('log2', None, 'pass2')) 0043 0044 def test_main(): 0045 test_support.run_unittest(NetrcTestCase) 0046 0047 if __name__ == "__main__": 0048 test_main() 0049
Generated by PyXR 0.9.4