[tor-commits] [sbws/maint-1.1] chg: v3bwfile: Convert datetime to str

juga at torproject.org juga at torproject.org
Tue Apr 14 13:53:19 UTC 2020


commit 65589118cd18500722acee1fd26e9b2a76083033
Author: juga0 <juga at riseup.net>
Date:   Sun Mar 22 08:04:48 2020 +0000

    chg: v3bwfile: Convert datetime to str
---
 sbws/lib/v3bwfile.py            |  6 ++++--
 tests/unit/lib/test_v3bwfile.py | 13 +++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index 2fd7ce4..80f1e34 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -18,7 +18,8 @@ from sbws.globals import (SPEC_VERSION, BW_LINE_SIZE, SBWS_SCALE_CONSTANT,
 from sbws.lib.resultdump import ResultSuccess, _ResultType
 from sbws.util.filelock import DirectoryLock
 from sbws.util.timestamp import (now_isodt_str, unixts_to_isodt_str,
-                                 now_unixts, isostr_to_dt_obj)
+                                 now_unixts, isostr_to_dt_obj,
+                                 dt_obj_to_isodt_str)
 from sbws.util.state import State
 
 log = logging.getLogger(__name__)
@@ -448,7 +449,8 @@ class V3BWHeader(object):
         '''
         state = State(state_fpath)
         if 'scanner_started' in state:
-            return state['scanner_started']
+            # From v1.1.0-dev `state` is capable of converting strs to datetime
+            return dt_obj_to_isodt_str(state['scanner_started'])
         else:
             return None
 
diff --git a/tests/unit/lib/test_v3bwfile.py b/tests/unit/lib/test_v3bwfile.py
index 566cc8d..8fe2dab 100644
--- a/tests/unit/lib/test_v3bwfile.py
+++ b/tests/unit/lib/test_v3bwfile.py
@@ -516,3 +516,16 @@ def test_set_under_min_report(mock_consensus, conf, datadir):
     assert bwl.vote == 0
     assert bwl.under_min_report == 1
     assert bwl.bw != 1
+
+
+def test_generator_started(root_data_path, datadir):
+    state_fpath = os.path.join(root_data_path, '.sbws/state.dat')
+    # The method is correct
+    assert "2019-03-25T13:03:06" == V3BWHeader.generator_started_from_file(
+        state_fpath
+    )
+    # `results` does not matter here, using them to not have an empty list.
+    results = load_result_file(str(datadir.join("results.txt")))
+    header = V3BWHeader.from_results(results, '', '', state_fpath)
+    # And the header is correct
+    assert "2019-03-25T13:03:06" == header.generator_started





More information about the tor-commits mailing list