PageRenderTime 389ms CodeModel.GetById 206ms app.highlight 4ms RepoModel.GetById 177ms app.codeStats 0ms

/Lib/test/test_netrc.py

http://unladen-swallow.googlecode.com/
Python | 48 lines | 46 code | 2 blank | 0 comment | 0 complexity | a764a02f4f18e5963fae96389ce16920 MD5 | raw file
 1
 2import netrc, os, unittest, sys
 3from test import test_support
 4
 5TEST_NETRC = """
 6machine foo login log1 password pass1 account acct1
 7
 8macdef macro1
 9line1
10line2
11
12macdef macro2
13line3
14line4
15
16default login log2 password pass2
17
18"""
19
20temp_filename = test_support.TESTFN
21
22class NetrcTestCase(unittest.TestCase):
23
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)
32
33    def tearDown (self):
34        del self.netrc
35        os.unlink(temp_filename)
36
37    def test_case_1(self):
38        self.assert_(self.netrc.macros == {'macro1':['line1\n', 'line2\n'],
39                                           'macro2':['line3\n', 'line4\n']}
40                                           )
41        self.assert_(self.netrc.hosts['foo'] == ('log1', 'acct1', 'pass1'))
42        self.assert_(self.netrc.hosts['default'] == ('log2', None, 'pass2'))
43
44def test_main():
45    test_support.run_unittest(NetrcTestCase)
46
47if __name__ == "__main__":
48    test_main()