ppf/new: Fill add_*_line methods in test_parsing.py.
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sat, 27 Aug 2011 14:46:54 +0000 (17:46 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sat, 27 Aug 2011 14:46:54 +0000 (17:46 +0300)
ppf/new/tests/test_parsing.py

index f497c65..53f624c 100644 (file)
@@ -63,6 +63,12 @@ class LibtorrentLogParserTest(unittest.TestCase):
         self.pstatmsg_cnt = 0
         self.verbmsg_cnt = 0
 
+        # Initialize internal call counts.
+        self.bogus_line_num_calls = 0
+        self.status_line_num_calls = 0
+        self.peer_status_line_num_calls = 0
+        self.verbose_line_num_calls = 0
+
         # Remove no_dir in case it exists.
         try:
             shutil.rmtree(self.no_dir)
@@ -77,21 +83,43 @@ class LibtorrentLogParserTest(unittest.TestCase):
         except OSError, e:
             pass
 
+    def append_line(self, filename, line):
+        """Add (append) a line to to a file."""
+        f = open(filename, "at")
+        f.write(line + "\n")
+        f.close()
+
     def add_bogus_line(self, filename):
         """Add bogus (non-relevant) line to file."""
-        pass
+        if self.bogus_line_num_calls == 0:
+            self.append_line(filename, "Nebuchadnezzar")
+        else:
+            self.append_line(filename, "Assurbanipal")
+        self.bogus_line_num_calls = self.bogus_line_num_calls + 1
 
     def add_status_line(self, filename):
         """Add status line to file."""
-        pass
+        if self.status_line_num_calls == 0:
+            self.append_line(filename, "ps: 5, dht: 21 <> dl: 462.1kb/s, ul: 255.2kb/s <> dld: 45mb, uld: 3mb, size: 698mb <> eta: 24m 7s")
+        else:
+            self.append_line(filename, "ps: 5, dht: 21 <> dl: 469kb/s, ul: 255.66kb/s <> dld: 46mb, uld: 4mb, size: 698mb <> eta: 23m 45s")
+        self.status_line_num_calls = self.status_line_num_calls + 1
 
     def add_peer_status_line(self, filename):
         """Add peer status line to file."""
-        pass
+        if self.peer_status_line_num_calls == 0:
+            self.append_line(filename, "--Peers: (Aug 14 17:22:35) [ ip: 10.1.7.5:33289, dl: 86.63kb/s, ul: 175.07kb/s ][ ip: 10.1.9.5:55611, dl: 14.63kb/s, ul: 110.79kb/s ][ ip: 10.1.8.5:6881, dl: 2.96kb/s, ul: 92.85kb/s ][ ip: 10.1.6.5:47254, dl: 80.1kb/s, ul: 176.44kb/s ][ ip: 10.1.4.5:6881, dl: 115.16kb/s, ul: 167.83kb/s ][ ip: 10.1.5.5:45222, dl: 108.39kb/s, ul: 158.11kb/s ][ ip: 10.1.10.5:48923, dl: 66.16kb/s, ul: 121.92kb/s ][ ip: 10.1.1.5:51146, dl: 198.66kb/s, ul: 6.11kb/s ]")
+        else:
+            self.append_line(filename, "--Peers: (Aug 14 17:22:40) [ ip: 10.1.7.5:33289, dl: 23.6kb/s, ul: 94.91kb/s ][ ip: 10.1.6.5:47254, dl: 55.61kb/s, ul: 100.72kb/s ][ ip: 10.1.4.5:6881, dl: 93.99kb/s, ul: 100.11kb/s ][ ip: 10.1.10.5:48923, dl: 57.42kb/s, ul: 205.74kb/s ]")
+        self.peer_status_line_num_calls = self.peer_status_line_num_calls + 1
 
     def add_verbose_line(self, filename):
         """Add verbose line to file."""
-        pass
+        if self.verbose_line_num_calls == 0:
+            self.append_line(filename, "Jan 08 22:20:50 <== REQUEST [ piece: 8a | s: 38000 | l: 4000 ]")
+        else:
+            self.append_line(filename, "Jan 08 22:20:50 ==> PIECE   [ piece: 8a | s: 34000 | l: 4000 ]")
+        self.verbose_line_num_calls = self.verbose_line_num_calls + 1
 
     def add_message_to_count(self, msg):
         """Update message type counters according to msg."""