<s> import netrc , os , unittest , sys , textwrap <EOL> from test import test_support <EOL> temp_filename = test_support . TESTFN <EOL> class NetrcTestCase ( unittest . TestCase ) : <EOL> def tearDown ( self ) : <EOL> os . unlink ( temp_filename ) <EOL> def make_nrc ( self , test_data ) : <EOL> test_data = textwrap . dedent ( test_data ) <EOL> mode = '<STR_LIT:w>' <EOL> if sys . platform != '<STR_LIT>' : <EOL> mode += '<STR_LIT:t>' <EOL> with open ( temp_filename , mode ) as fp : <EOL> fp . write ( test_data ) <EOL> return netrc . netrc ( temp_filename ) <EOL> def test_default ( self ) : <EOL> nrc = self . make_nrc ( """<STR_LIT>""" ) <EOL> self . assertEqual ( nrc . hosts [ '<STR_LIT>' ] , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( nrc . hosts [ '<STR_LIT:default>' ] , ( '<STR_LIT>' , None , '<STR_LIT>' ) ) <EOL> def test_macros ( self ) : <EOL> nrc = self . make_nrc ( """<STR_LIT>""" ) <EOL> self . assertEqual ( nrc . macros , { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] } ) <EOL> def _test_passwords ( self , nrc , passwd ) : <EOL> nrc = self . make_nrc ( nrc ) <EOL> self . assertEqual ( nrc . hosts [ '<STR_LIT>' ] , ( '<STR_LIT>' , '<STR_LIT>' , passwd ) ) <EOL> def test_password_with_leading_hash ( self ) : <EOL> self . _test_passwords ( """<STR_LIT>""" , '<STR_LIT>' ) <EOL> def test_password_with_trailing_hash ( self ) : <EOL> self . _test_passwords ( """<STR_LIT>""" , '<STR_LIT>' ) <EOL> def test_password_with_internal_hash ( self ) : <EOL> self . _test_passwords ( """<STR_LIT>""" , '<STR_LIT>' ) <EOL> def _test_comment ( self , nrc , passwd = '<STR_LIT>' ) : <EOL> nrc = self . make_nrc ( nrc ) <EOL> self . assertEqual ( nrc . hosts [ '<STR_LIT>' ] , ( '<STR_LIT:bar>' , None , passwd ) ) <EOL> self . assertEqual ( nrc . hosts [ '<STR_LIT>' ] , ( '<STR_LIT:foo>' , None , '<STR_LIT>' ) ) <EOL> def test_comment_before_machine_line ( self ) : <EOL> self . _test_comment ( """<STR_LIT>""" ) <EOL> @ unittest . skipIf ( test_support . is_jython , "<STR_LIT>" ) <EOL> def test_comment_before_machine_line_no_space ( self ) : <EOL> self . _test_comment ( """<STR_LIT>""" ) <EOL> @ unittest . skipIf ( test_support . is_jython , "<STR_LIT>" ) <EOL> def test_comment_before_machine_line_hash_only ( self ) : <EOL> self . _test_comment ( """<STR_LIT>""" ) <EOL> @ unittest . skipIf ( test_support . is_jython , "<STR_LIT>" ) <EOL> def test_comment_at_end_of_machine_line ( self ) : <EOL> self . _test_comment ( """<STR_LIT>""" ) <EOL> @ unittest . skipIf ( test_support . is_jython , "<STR_LIT>" ) <EOL> def test_comment_at_end_of_machine_line_no_space ( self ) : <EOL> self . _test_comment ( """<STR_LIT>""" ) <EOL> @ unittest . skipIf ( test_support . is_jython , "<STR_LIT>" ) <EOL> def test_comment_at_end_of_machine_line_pass_has_hash ( self ) : <EOL> self . _test_comment ( """<STR_LIT>""" , '<STR_LIT>' ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( NetrcTestCase ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
