blob: 034b10550f4306fdc961ff023b27cb0d1e131c20 [file] [log] [blame]
Andrew M. Kuchling76fffd82002-03-22 02:48:57 +00001
Barry Warsaw04f357c2002-07-23 19:04:11 +00002import netrc, os, tempfile, unittest
3from test import test_support
Andrew M. Kuchling76fffd82002-03-22 02:48:57 +00004
5TEST_NETRC = """
6machine foo login log1 password pass1 account acct1
7
8macdef macro1
9line1
10line2
11
12macdef macro2
13line3
14line4
15
Tim Peters863ac442002-04-16 01:38:40 +000016default login log2 password pass2
Andrew M. Kuchling76fffd82002-03-22 02:48:57 +000017
18"""
19
20temp_filename = tempfile.mktemp()
21
22class NetrcTestCase(unittest.TestCase):
23
24 def setUp (self):
25 fp = open(temp_filename, 'wt')
26 fp.write(TEST_NETRC)
27 fp.close()
28 self.netrc = netrc.netrc(temp_filename)
Tim Peters863ac442002-04-16 01:38:40 +000029
Andrew M. Kuchling76fffd82002-03-22 02:48:57 +000030 def tearDown (self):
31 del self.netrc
32 os.unlink(temp_filename)
33
34 def test_case_1(self):
35 self.assert_(self.netrc.macros == {'macro1':['line1\n', 'line2\n'],
36 'macro2':['line3\n', 'line4\n']}
37 )
38 self.assert_(self.netrc.hosts['foo'] == ('log1', 'acct1', 'pass1'))
39 self.assert_(self.netrc.hosts['default'] == ('log2', None, 'pass2'))
Tim Peters863ac442002-04-16 01:38:40 +000040
41
Andrew M. Kuchling76fffd82002-03-22 02:48:57 +000042if __name__ == "__main__":
43 test_support.run_unittest(NetrcTestCase)