Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_pipes.py

    r2 r391  
    33import string
    44import unittest
    5 from test.test_support import TESTFN, run_unittest, unlink, TestSkipped
     5from test.test_support import TESTFN, run_unittest, unlink, reap_children
    66
    77if os.name != 'posix':
    8     raise TestSkipped('pipes module only works on posix')
     8    raise unittest.SkipTest('pipes module only works on posix')
    99
    1010TESTFN2 = TESTFN + "2"
     
    2424        f.write('hello world #1')
    2525        f.close()
    26         self.assertEqual(open(TESTFN).read(), 'HELLO WORLD #1')
     26        with open(TESTFN) as f:
     27            self.assertEqual(f.read(), 'HELLO WORLD #1')
    2728
    2829    def testSimplePipe2(self):
    29         file(TESTFN, 'w').write('hello world #2')
     30        with open(TESTFN, 'w') as f:
     31            f.write('hello world #2')
    3032        t = pipes.Template()
    3133        t.append(s_command + ' < $IN > $OUT', pipes.FILEIN_FILEOUT)
    3234        t.copy(TESTFN, TESTFN2)
    33         self.assertEqual(open(TESTFN2).read(), 'HELLO WORLD #2')
     35        with open(TESTFN2) as f:
     36            self.assertEqual(f.read(), 'HELLO WORLD #2')
    3437
    3538    def testSimplePipe3(self):
    36         file(TESTFN, 'w').write('hello world #2')
     39        with open(TESTFN, 'w') as f:
     40            f.write('hello world #2')
    3741        t = pipes.Template()
    3842        t.append(s_command + ' < $IN', pipes.FILEIN_STDOUT)
    39         self.assertEqual(t.open(TESTFN, 'r').read(), 'HELLO WORLD #2')
     43        with t.open(TESTFN, 'r') as f:
     44            self.assertEqual(f.read(), 'HELLO WORLD #2')
    4045
    4146    def testEmptyPipeline1(self):
    4247        # copy through empty pipe
    4348        d = 'empty pipeline test COPY'
    44         file(TESTFN, 'w').write(d)
    45         file(TESTFN2, 'w').write('')
     49        with open(TESTFN, 'w') as f:
     50            f.write(d)
     51        with open(TESTFN2, 'w') as f:
     52            f.write('')
    4653        t=pipes.Template()
    4754        t.copy(TESTFN, TESTFN2)
    48         self.assertEqual(open(TESTFN2).read(), d)
     55        with open(TESTFN2) as f:
     56            self.assertEqual(f.read(), d)
    4957
    5058    def testEmptyPipeline2(self):
    5159        # read through empty pipe
    5260        d = 'empty pipeline test READ'
    53         file(TESTFN, 'w').write(d)
     61        with open(TESTFN, 'w') as f:
     62            f.write(d)
    5463        t=pipes.Template()
    55         self.assertEqual(t.open(TESTFN, 'r').read(), d)
     64        with t.open(TESTFN, 'r') as f:
     65            self.assertEqual(f.read(), d)
    5666
    5767    def testEmptyPipeline3(self):
     
    5969        d = 'empty pipeline test WRITE'
    6070        t = pipes.Template()
    61         t.open(TESTFN, 'w').write(d)
    62         self.assertEqual(open(TESTFN).read(), d)
     71        with t.open(TESTFN, 'w') as f:
     72            f.write(d)
     73        with open(TESTFN) as f:
     74            self.assertEqual(f.read(), d)
    6375
    6476    def testQuoting(self):
    65         safeunquoted = string.ascii_letters + string.digits + '!@%_-+=:,./'
    66         unsafe = '"`$\\'
    67 
     77        safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./'
     78        unsafe = '"`$\\!'
     79
     80        self.assertEqual(pipes.quote(''), "''")
    6881        self.assertEqual(pipes.quote(safeunquoted), safeunquoted)
    6982        self.assertEqual(pipes.quote('test file name'), "'test file name'")
     
    7386        for u in unsafe:
    7487            self.assertEqual(pipes.quote("test%s'name'" % u),
    75                               '"test\\%s\'name\'"' % u)
    76 
    77         self.assertEqual(pipes.quote(''), "''")
     88                             "'test%s'\"'\"'name'\"'\"''" % u)
    7889
    7990    def testRepr(self):
     
    188199def test_main():
    189200    run_unittest(SimplePipeTests)
     201    reap_children()
    190202
    191203if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.