<s> from twisted . trial import unittest <EOL> from tensor . logs import follower , parsers <EOL> import datetime <EOL> import os <EOL> class TestLogs ( unittest . TestCase ) : <EOL> def test_logfollow ( self ) : <EOL> try : <EOL> os . unlink ( '<STR_LIT>' ) <EOL> os . unlink ( '<STR_LIT>' ) <EOL> except : <EOL> pass <EOL> log = open ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> log . write ( '<STR_LIT>' ) <EOL> log . flush ( ) <EOL> f = follower . LogFollower ( '<STR_LIT>' , tmp_path = "<STR_LIT:.>" , history = True ) <EOL> r = f . get ( ) <EOL> log . write ( '<STR_LIT:test>' ) <EOL> log . flush ( ) <EOL> r2 = f . get ( ) <EOL> log . write ( '<STR_LIT>' ) <EOL> log . flush ( ) <EOL> r3 = f . get ( ) <EOL> self . assertEqual ( r [ <NUM_LIT:0> ] , '<STR_LIT:foo>' ) <EOL> self . assertEqual ( r [ <NUM_LIT:1> ] , '<STR_LIT:bar>' ) <EOL> self . assertEqual ( r2 , [ ] ) <EOL> self . assertEqual ( r3 [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> log . close ( ) <EOL> os . rename ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> log = open ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> log . write ( '<STR_LIT>' ) <EOL> log . close ( ) <EOL> r = f . get ( ) <EOL> self . assertEqual ( r [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( r [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> log = open ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> log . write ( '<STR_LIT>' ) <EOL> log . close ( ) <EOL> r = f . get ( ) <EOL> self . assertEqual ( r [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> os . unlink ( '<STR_LIT>' ) <EOL> os . unlink ( '<STR_LIT>' ) <EOL> def test_apache_parser ( self ) : <EOL> log = parsers . ApacheLogParser ( '<STR_LIT>' ) <EOL> line = '<STR_LIT>' <EOL> want = { <EOL> '<STR_LIT:status>' : <NUM_LIT:200> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:time>' : datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:16> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT:user>' : None , <EOL> } <EOL> p = log . parse ( line ) <EOL> for k , v in want . items ( ) : <EOL> self . assertEquals ( p [ k ] , v ) </s>
