def test_lazycache_already_cached(self):
     linecache.clearcache()
     lines = linecache.getlines(NONEXISTENT_FILENAME, globals())
     self.assertEqual(
         False,
         linecache.lazycache(NONEXISTENT_FILENAME, globals()))
     self.assertEqual(4, len(linecache.cache[NONEXISTENT_FILENAME]))
 def test_lazycache_provide_after_failed_lookup(self):
     linecache.clearcache()
     lines = linecache.getlines(NONEXISTENT_FILENAME, globals())
     linecache.clearcache()
     linecache.getlines(NONEXISTENT_FILENAME)
     linecache.lazycache(NONEXISTENT_FILENAME, globals())
     self.assertEqual(lines, linecache.updatecache(NONEXISTENT_FILENAME))
示例#3
0
 def test_lazycache_provide_after_failed_lookup(self):
     linecache.clearcache()
     lines = linecache.getlines(NONEXISTENT_FILENAME, globals())
     linecache.clearcache()
     linecache.getlines(NONEXISTENT_FILENAME)
     linecache.lazycache(NONEXISTENT_FILENAME, globals())
     self.assertEqual(lines, linecache.updatecache(NONEXISTENT_FILENAME))
示例#4
0
 def test_lazy_lines(self):
     linecache.clearcache()
     f = traceback.FrameSummary("f", 1, "dummy", lookup_line=False)
     self.assertEqual(None, f._line)
     linecache.lazycache("f", fake_module)
     self.assertEqual(
         '"""Test cases for traceback module"""',
         f.line)
示例#5
0
 def test_basics(self):
     linecache.clearcache()
     linecache.lazycache("f", fake_module)
     f = traceback.FrameSummary("f", 1, "dummy")
     self.assertEqual(
         ("f", 1, "dummy", '"""Test cases for traceback module"""'),
         tuple(f))
     self.assertEqual(None, f.locals)
示例#6
0
 def test_extract_stackup_deferred_lookup_lines(self):
     linecache.clearcache()
     c = test_code('/foo.py', 'method')
     f = test_frame(c, None, None)
     s = traceback.StackSummary.extract(iter([(f, 8)]), lookup_lines=False)
     self.assertEqual({}, linecache.cache)
     linecache.updatecache('/foo.py', fake_module)
     self.assertEqual(s[0].line, "import sys")
 def test_extract_stackup_deferred_lookup_lines(self):
     linecache.clearcache()
     c = test_code('/foo.py', 'method')
     f = test_frame(c, None, None)
     s = traceback.StackSummary.extract(iter([(f, 8)]), lookup_lines=False)
     self.assertEqual({}, linecache.cache)
     linecache.updatecache('/foo.py', fake_module)
     self.assertEqual(s[0].line, "import sys")
 def test_basics(self):
     linecache.clearcache()
     linecache.lazycache("f", fake_module)
     f = traceback.FrameSummary("f", 1, "dummy")
     self.assertEqual(
         ("f", 1, "dummy", '"""Test cases for traceback module"""'),
         tuple(f))
     self.assertEqual(None, f.locals)
 def test_lazycache_smoke(self):
     lines = linecache.getlines(NONEXISTENT_FILENAME, globals())
     linecache.clearcache()
     self.assertEqual(
         True, linecache.lazycache(NONEXISTENT_FILENAME, globals()))
     self.assertEqual(1, len(linecache.cache[NONEXISTENT_FILENAME]))
     # Note here that we're looking up a non existant filename with no
     # globals: this would error if the lazy value wasn't resolved.
     self.assertEqual(lines, linecache.getlines(NONEXISTENT_FILENAME))
示例#10
0
 def test_lazycache_smoke(self):
     lines = linecache.getlines(NONEXISTENT_FILENAME, globals())
     linecache.clearcache()
     self.assertEqual(True,
                      linecache.lazycache(NONEXISTENT_FILENAME, globals()))
     self.assertEqual(1, len(linecache.cache[NONEXISTENT_FILENAME]))
     # Note here that we're looking up a non existant filename with no
     # globals: this would error if the lazy value wasn't resolved.
     self.assertEqual(lines, linecache.getlines(NONEXISTENT_FILENAME))
示例#11
0
 def test_lookup_lines(self):
     linecache.clearcache()
     e = Exception("uh oh")
     c = test_code('/foo.py', 'method')
     f = test_frame(c, None, None)
     tb = test_tb(f, 8, None)
     exc = traceback.TracebackException(Exception, e, tb, lookup_lines=False)
     self.assertEqual({}, linecache.cache)
     linecache.updatecache('/foo.py', fake_module)
     self.assertEqual(exc.stack[0].line, "import sys")
    def test_clearcache(self):
        cached = []
        for entry in TESTS:
            filename = os.path.join(TEST_PATH, entry) + '.py'
            cached.append(filename)
            linecache.getline(filename, 1)

        # Are all files cached?
        cached_empty = [fn for fn in cached if fn not in linecache.cache]
        self.assertEqual(cached_empty, [])

        # Can we clear the cache?
        linecache.clearcache()
        cached_empty = [fn for fn in cached if fn in linecache.cache]
        self.assertEqual(cached_empty, [])
示例#13
0
    def test_clearcache(self):
        cached = []
        for entry in TESTS:
            filename = os.path.join(TEST_PATH, entry) + '.py'
            cached.append(filename)
            linecache.getline(filename, 1)

        # Are all files cached?
        cached_empty = [fn for fn in cached if fn not in linecache.cache]
        self.assertEqual(cached_empty, [])

        # Can we clear the cache?
        linecache.clearcache()
        cached_empty = [fn for fn in cached if fn in linecache.cache]
        self.assertEqual(cached_empty, [])
示例#14
0
#using examples
#worksheet.write('A1', 'trigger times')                           # write somethong into A1
#count = linecache.getline(filename,linenum)                      #extract something of a certain line 
#str = linecache.getlines(filename)                               #get the log information by a list style,str is a list
#linenumbers=len(filename)                                        #probably to judge how many lines the log file has


#loops to read information from the log file into excel

str_asr_result = linecache.getlines('asr_result.log')                    #calculating that how many lines the log has
worksheet.write('A1','ASR_Result')
for i in range(len(str_asr_result)+1):
    worksheet.write('A%s'%(i+1),'%s'%linecache.getline('asr_result.log',i))  #Write the lines into the corresponding cell of a certain sheet in sequence                       

linecache.clearcache()                                                  #other operation about using linecache, somethong like clearing cache 


str_songName = linecache.getlines('songName.log')                    #calculating that how many lines the log has
worksheet.write('B1','songName')
for i in range(len(str_songName)+1):
    worksheet.write('B%s'%(i+1),'%s'%linecache.getline('songName.log',i))  #Write the lines into the corresponding cell of a certain sheet in sequence                       

linecache.clearcache()


str_songId = linecache.getlines('songId.log')                    #calculating that how many lines the log has
worksheet.write('C1','songId')
for i in range(len(str_songId)+1):
    worksheet.write('C%s'%(i+1),'%s'%linecache.getline('songId.log',i))  #Write the lines into the corresponding cell of a certain sheet in sequence                       
 def test_lazycache_no_globals(self):
     lines = linecache.getlines(FILENAME)
     linecache.clearcache()
     self.assertEqual(False, linecache.lazycache(FILENAME, None))
     self.assertEqual(lines, linecache.getlines(FILENAME))
 def test_lazycache_check(self):
     linecache.clearcache()
     linecache.lazycache(NONEXISTENT_FILENAME, globals())
     linecache.checkcache()
示例#17
0
 def test_lazycache_already_cached(self):
     linecache.clearcache()
     lines = linecache.getlines(NONEXISTENT_FILENAME, globals())
     self.assertEqual(False,
                      linecache.lazycache(NONEXISTENT_FILENAME, globals()))
     self.assertEqual(4, len(linecache.cache[NONEXISTENT_FILENAME]))
示例#18
0
 def test_lazycache_bad_filename(self):
     linecache.clearcache()
     self.assertEqual(False, linecache.lazycache('', globals()))
     self.assertEqual(False, linecache.lazycache('<foo>', globals()))
示例#19
0
 def test_lazycache_check(self):
     linecache.clearcache()
     linecache.lazycache(NONEXISTENT_FILENAME, globals())
     linecache.checkcache()
 def test_lazycache_bad_filename(self):
     linecache.clearcache()
     self.assertEqual(False, linecache.lazycache('', globals()))
     self.assertEqual(False, linecache.lazycache('<foo>', globals()))
示例#21
0
 def test_lazycache_no_globals(self):
     lines = linecache.getlines(FILENAME)
     linecache.clearcache()
     self.assertEqual(False, linecache.lazycache(FILENAME, None))
     self.assertEqual(lines, linecache.getlines(FILENAME))