GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 65589118 authored by juga  's avatar juga

chg: v3bwfile: Convert datetime to str

parent 8e5da39c
...@@ -18,7 +18,8 @@ from sbws.globals import (SPEC_VERSION, BW_LINE_SIZE, SBWS_SCALE_CONSTANT, ...@@ -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.lib.resultdump import ResultSuccess, _ResultType
from sbws.util.filelock import DirectoryLock from sbws.util.filelock import DirectoryLock
from sbws.util.timestamp import (now_isodt_str, unixts_to_isodt_str, 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 from sbws.util.state import State
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -448,7 +449,8 @@ class V3BWHeader(object): ...@@ -448,7 +449,8 @@ class V3BWHeader(object):
''' '''
state = State(state_fpath) state = State(state_fpath)
if 'scanner_started' in state: 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: else:
return None return None
......
...@@ -516,3 +516,16 @@ def test_set_under_min_report(mock_consensus, conf, datadir): ...@@ -516,3 +516,16 @@ def test_set_under_min_report(mock_consensus, conf, datadir):
assert bwl.vote == 0 assert bwl.vote == 0
assert bwl.under_min_report == 1 assert bwl.under_min_report == 1
assert bwl.bw != 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment