Andrew M. Kuchling | 76fffd8 | 2002-03-22 02:48:57 +0000 | [diff] [blame^] | 1 | |
| 2 | import netrc, os, tempfile, test_support, unittest |
| 3 | |
| 4 | TEST_NETRC = """ |
| 5 | machine foo login log1 password pass1 account acct1 |
| 6 | |
| 7 | macdef macro1 |
| 8 | line1 |
| 9 | line2 |
| 10 | |
| 11 | macdef macro2 |
| 12 | line3 |
| 13 | line4 |
| 14 | |
| 15 | default login log2 password pass2 |
| 16 | |
| 17 | """ |
| 18 | |
| 19 | temp_filename = tempfile.mktemp() |
| 20 | |
| 21 | class NetrcTestCase(unittest.TestCase): |
| 22 | |
| 23 | def setUp (self): |
| 24 | fp = open(temp_filename, 'wt') |
| 25 | fp.write(TEST_NETRC) |
| 26 | fp.close() |
| 27 | self.netrc = netrc.netrc(temp_filename) |
| 28 | |
| 29 | def tearDown (self): |
| 30 | del self.netrc |
| 31 | os.unlink(temp_filename) |
| 32 | |
| 33 | def test_case_1(self): |
| 34 | self.assert_(self.netrc.macros == {'macro1':['line1\n', 'line2\n'], |
| 35 | 'macro2':['line3\n', 'line4\n']} |
| 36 | ) |
| 37 | self.assert_(self.netrc.hosts['foo'] == ('log1', 'acct1', 'pass1')) |
| 38 | self.assert_(self.netrc.hosts['default'] == ('log2', None, 'pass2')) |
| 39 | |
| 40 | |
| 41 | if __name__ == "__main__": |
| 42 | test_support.run_unittest(NetrcTestCase) |
| 43 | |