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_linecache.py

    r2 r391  
    1010INVALID_NAME = '!@$)(!@#_1'
    1111EMPTY = ''
    12 TESTS = 'cjkencodings_test inspect_fodder inspect_fodder2 mapping_tests'
     12TESTS = 'inspect_fodder inspect_fodder2 mapping_tests'
    1313TESTS = TESTS.split()
    1414TEST_PATH = os.path.dirname(support.__file__)
    15 MODULES = "linecache unittest".split()
     15MODULES = "linecache abc".split()
    1616MODULE_PATH = os.path.dirname(FILENAME)
    1717
     
    3232'''
    3333
     34SOURCE_3 = '''
     35def f():
     36    return 3''' # No ending newline
     37
     38
    3439class LineCacheTests(unittest.TestCase):
    3540
     
    3843
    3944        # Bad values for line number should return an empty string
    40         self.assertEquals(getline(FILENAME, 2**15), EMPTY)
    41         self.assertEquals(getline(FILENAME, -1), EMPTY)
     45        self.assertEqual(getline(FILENAME, 2**15), EMPTY)
     46        self.assertEqual(getline(FILENAME, -1), EMPTY)
    4247
    4348        # Float values currently raise TypeError, should it?
     
    4550
    4651        # Bad filenames should return an empty string
    47         self.assertEquals(getline(EMPTY, 1), EMPTY)
    48         self.assertEquals(getline(INVALID_NAME, 1), EMPTY)
     52        self.assertEqual(getline(EMPTY, 1), EMPTY)
     53        self.assertEqual(getline(INVALID_NAME, 1), EMPTY)
    4954
    5055        # Check whether lines correspond to those from file iteration
     
    5257            filename = os.path.join(TEST_PATH, entry) + '.py'
    5358            for index, line in enumerate(open(filename)):
    54                 self.assertEquals(line, getline(filename, index + 1))
     59                self.assertEqual(line, getline(filename, index + 1))
    5560
    5661        # Check module loading
     
    5863            filename = os.path.join(MODULE_PATH, entry) + '.py'
    5964            for index, line in enumerate(open(filename)):
    60                 self.assertEquals(line, getline(filename, index + 1))
     65                self.assertEqual(line, getline(filename, index + 1))
    6166
    6267        # Check that bogus data isn't returned (issue #1309567)
    6368        empty = linecache.getlines('a/b/c/__init__.py')
    64         self.assertEquals(empty, [])
     69        self.assertEqual(empty, [])
     70
     71    def test_no_ending_newline(self):
     72        self.addCleanup(support.unlink, support.TESTFN)
     73        with open(support.TESTFN, "w") as fp:
     74            fp.write(SOURCE_3)
     75        lines = linecache.getlines(support.TESTFN)
     76        self.assertEqual(lines, ["\n", "def f():\n", "    return 3\n"])
    6577
    6678    def test_clearcache(self):
     
    7385        # Are all files cached?
    7486        cached_empty = [fn for fn in cached if fn not in linecache.cache]
    75         self.assertEquals(cached_empty, [])
     87        self.assertEqual(cached_empty, [])
    7688
    7789        # Can we clear the cache?
    7890        linecache.clearcache()
    7991        cached_empty = [fn for fn in cached if fn in linecache.cache]
    80         self.assertEquals(cached_empty, [])
     92        self.assertEqual(cached_empty, [])
    8193
    8294    def test_checkcache(self):
    8395        getline = linecache.getline
    84         try:
    85             # Create a source file and cache its contents
    86             source_name = support.TESTFN + '.py'
    87             with open(source_name, 'w') as source:
    88                 source.write(SOURCE_1)
    89                 source.close()
    90                 getline(source_name, 1)
     96        # Create a source file and cache its contents
     97        source_name = support.TESTFN + '.py'
     98        self.addCleanup(support.unlink, source_name)
     99        with open(source_name, 'w') as source:
     100            source.write(SOURCE_1)
     101        getline(source_name, 1)
    91102
    92                 # Keep a copy of the old contents
    93                 source_list = []
    94                 source = open(source_name)
    95                 for index, line in enumerate(source):
    96                     self.assertEquals(line, getline(source_name, index + 1))
    97                     source_list.append(line)
    98                 source.close()
     103        # Keep a copy of the old contents
     104        source_list = []
     105        with open(source_name) as source:
     106            for index, line in enumerate(source):
     107                self.assertEqual(line, getline(source_name, index + 1))
     108                source_list.append(line)
    99109
    100                 source = open(source_name, 'w')
    101                 source.write(SOURCE_2)
    102                 source.close()
     110        with open(source_name, 'w') as source:
     111            source.write(SOURCE_2)
    103112
    104                 # Try to update a bogus cache entry
    105                 linecache.checkcache('dummy')
     113        # Try to update a bogus cache entry
     114        linecache.checkcache('dummy')
    106115
    107                 # Check that the cache matches the old contents
    108                 for index, line in enumerate(source_list):
    109                     self.assertEquals(line, getline(source_name, index + 1))
     116        # Check that the cache matches the old contents
     117        for index, line in enumerate(source_list):
     118            self.assertEqual(line, getline(source_name, index + 1))
    110119
    111                 # Update the cache and check whether it matches the new source file
    112                 linecache.checkcache(source_name)
    113                 source = open(source_name)
    114                 for index, line in enumerate(source):
    115                     self.assertEquals(line, getline(source_name, index + 1))
    116                     source_list.append(line)
    117 
    118         finally:
    119             support.unlink(source_name)
     120        # Update the cache and check whether it matches the new source file
     121        linecache.checkcache(source_name)
     122        with open(source_name) as source:
     123            for index, line in enumerate(source):
     124                self.assertEqual(line, getline(source_name, index + 1))
     125                source_list.append(line)
    120126
    121127def test_main():
Note: See TracChangeset for help on using the changeset viewer.