[tor-commits] [sbws/master] Add test for update_progress
juga at torproject.org
juga at torproject.org
Wed Oct 24 09:40:24 UTC 2018
commit 65c5095a44138ea87b159c88d391d56da9800237
Author: juga0 <juga at riseup.net>
Date: Tue Oct 23 14:33:25 2018 +0000
Add test for update_progress
---
tests/unit/lib/test_v3bwfile.py | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/tests/unit/lib/test_v3bwfile.py b/tests/unit/lib/test_v3bwfile.py
index 0618167..3ced812 100644
--- a/tests/unit/lib/test_v3bwfile.py
+++ b/tests/unit/lib/test_v3bwfile.py
@@ -9,7 +9,7 @@ from sbws.lib.resultdump import Result, load_result_file, ResultSuccess
from sbws.lib.v3bwfile import (V3BWHeader, V3BWLine, TERMINATOR, LINE_SEP,
KEYVALUE_SEP_V110, num_results_of_type,
V3BWFile)
-from sbws.util.timestamp import now_fname
+from sbws.util.timestamp import now_fname, now_isodt_str, now_unixts
timestamp = 1523974147
timestamp_l = str(timestamp)
@@ -200,15 +200,37 @@ def test_measured_progress_stats(datadir):
assert len(bw_lines_raw) == 3
bw_lines = V3BWFile.bw_torflow_scale(bw_lines_raw)
assert len(bw_lines) == 3
- statsd, success = V3BWFile.measured_progress_stats(bw_lines,
- num_net_relays, min_perc_reached_before)
+ statsd, success = V3BWFile.measured_progress_stats(
+ bw_lines, num_net_relays, min_perc_reached_before)
assert success
assert statsd == statsd_exp
num_net_relays = 6
- statsd, success = V3BWFile.measured_progress_stats(bw_lines,
- num_net_relays, min_perc_reached_before)
+ statsd, success = V3BWFile.measured_progress_stats(
+ bw_lines, num_net_relays, min_perc_reached_before)
assert not success
statsd_exp = {'perc_measured_relays': 50, 'perc_measured_targed': 60,
'num_net_relays': 6, 'num_target_relays': 4,
'num_measured_relays': 3}
assert statsd_exp == statsd
+
+
+def test_update_progress(datadir, tmpdir):
+ bw_lines_raw = []
+ num_net_relays = 6
+ state = {}
+ header = V3BWHeader(str(now_unixts()))
+ results = load_result_file(str(datadir.join("results_away.txt")))
+ for fp, values in results.items():
+ # log.debug("Relay fp %s", fp)
+ line = V3BWLine.from_results(values)
+ if line is not None:
+ bw_lines_raw.append(line)
+ bwfile = V3BWFile(header, [])
+ bwfile.update_progress(bw_lines_raw, header, num_net_relays, state)
+ assert header.perc_measured_relays == '50'
+ assert state.get('min_perc_reached') is None
+ num_net_relays = 3
+ header = V3BWHeader(str(now_unixts()))
+ bwfile.update_progress(bw_lines_raw, header, num_net_relays, state)
+ assert state.get('min_perc_reached') == now_isodt_str()
+ assert not hasattr(header, 'perc_measured_relays')
More information about the tor-commits
mailing list