[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [guardfraction/master] Fix tests that broke from adding more lines to the output file.



commit 47dad84c9e0ca6a77462d1effb5d013572883068
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Wed Feb 4 13:37:42 2015 +0000

    Fix tests that broke from adding more lines to the output file.
---
 guardiness/guard_ds.py     |    4 +++-
 test/test_guardfraction.py |   18 +++++++++++-------
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/guardiness/guard_ds.py b/guardiness/guard_ds.py
index 19e8077..61907b0 100644
--- a/guardiness/guard_ds.py
+++ b/guardiness/guard_ds.py
@@ -60,10 +60,12 @@ class Guards(object):
 
         Might raise IOError.
         """
+        now = datetime.datetime.now() # get the current date
+        now = now.replace(microsecond=0) # leave out the microsecond part
+
         with open(output_fname, 'w+') as f:
             f_str = ""
 
-            now = datetime.datetime.now()
             f_str += "guardfraction-file-version 1\n"
             f_str += "written-at %s\n" % now.isoformat(sep=" ") # separate year from time with space
             f_str += "n-inputs %d %d %d\n" % (consensuses_read_n, max_days, max_days*24)
diff --git a/test/test_guardfraction.py b/test/test_guardfraction.py
index 59024e2..0062b23 100644
--- a/test/test_guardfraction.py
+++ b/test/test_guardfraction.py
@@ -143,17 +143,21 @@ class testGuardFraction(unittest.TestCase):
         with open(temp_path) as test_fd:
             lines = test_fd.readlines()
 
-            # One line for the header, one line for n-inputs and 4 guards
-            self.assertEquals(len(lines), 6)
+            # One line for the file version, one line for date, one
+            # line for n-inputs and 4 guards.
+            self.assertEquals(len(lines), 7)
+
+            self.assertEquals(lines[0][:26], "guardfraction-file-version")
+            self.assertEquals(lines[1][:10], "written-at")
 
             # Test the n-inputs line
-            self.assertEquals(lines[1], "n-inputs 3 999 23976\n")
+            self.assertEquals(lines[2], "n-inputs 3 999 23976\n")
 
             # Test guard lines
-            self.assertIn("guard-seen AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 100 3\n", lines[2:])
-            self.assertIn("guard-seen BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB 67 2\n", lines[2:])
-            self.assertIn("guard-seen CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 33 1\n", lines[2:])
-            self.assertIn("guard-seen DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD 33 1\n", lines[2:])
+            self.assertIn("guard-seen AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 100 3\n", lines[3:])
+            self.assertIn("guard-seen BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB 67 2\n", lines[3:])
+            self.assertIn("guard-seen CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 33 1\n", lines[3:])
+            self.assertIn("guard-seen DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD 33 1\n", lines[3:])
 
         db_conn.close()
 

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits