def test_v3bwheader_from_text(): header_obj = V3BWHeader(timestamp_l, file_created=file_created, generator_started=generator_started, earliest_bandwidth=earliest_bandwidth) header, _ = V3BWHeader.from_text_v1(header_extra_str) assert str(header_obj) == str(header)
def test_update_progress(datadir, tmpdir): bw_lines_raw = [] number_consensus_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(len(bw_lines_raw), header, number_consensus_relays, state) assert header.percent_eligible_relays == '50' assert state.get('min_perc_reached') is None # Test that the headers are also included when there are enough eligible # relays number_consensus_relays = 3 header = V3BWHeader(str(now_unixts())) bwfile.update_progress(len(bw_lines_raw), header, number_consensus_relays, state) assert state.get('min_perc_reached') == now_isodt_str() assert header.minimum_number_eligible_relays == '2' assert header.minimum_percent_eligible_relays == str(MIN_REPORT) assert header.number_consensus_relays == '3' assert header.number_eligible_relays == '3' assert header.percent_eligible_relays == '100'
def test_recent_priority_relay_count(root_data_path, datadir): # This state has recent_priority_relay_count state_fpath = os.path.join(root_data_path, '.sbws/state.dat') assert 15 == V3BWHeader.recent_priority_relay_count_from_file(state_fpath) # `results` does not matter here, using them to don't have an empty list. results = load_result_file(str(datadir.join("results.txt"))) header = V3BWHeader.from_results(results, '', '', state_fpath) assert "15" == header.recent_priority_relay_count
def test_recent_measurement_attempt_count(root_data_path, datadir): state_fpath = os.path.join(root_data_path, '.sbws/state.dat') assert 15 == V3BWHeader.recent_measurement_attempt_count_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) assert "15" == header.recent_measurement_attempt_count
def test_v3bwheader_from_lines(): header_obj = V3BWHeader(timestamp_l, file_created=file_created, generator_started=generator_started, earliest_bandwidth=earliest_bandwidth, tor_version=tor_version) header, _ = V3BWHeader.from_lines_v1(header_extra_ls) assert str(header_obj) == str(header)
def test_generator_started(root_data_path, datadir): state_fpath = os.path.join(root_data_path, '.sbws/state.dat') # The method is correct assert "2020-02-29T10:00:00" == 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 "2020-02-29T10:00:00" == header.generator_started
def test_v3bwheader_str(): """Test header str""" header = V3BWHeader(timestamp_l, scanner_country=scanner_country, destinations_countries=destinations_countries, file_created=file_created) assert header_str == str(header)
def test_v3bwheader_extra_str(): """Test header str with additional headers""" header = V3BWHeader(timestamp_l, file_created=file_created, generator_started=generator_started, earliest_bandwidth=earliest_bandwidth) assert header_extra_str == str(header)
def test_time_measure_half_network(caplog): header = V3BWHeader(timestamp_l, file_created=file_created, generator_started=generator_started, earliest_bandwidth=earliest_bandwidth) header.number_consensus_relays = '6500' header.number_eligible_relays = '4000' caplog.set_level(logging.INFO) header.add_time_report_half_network() assert header.time_to_report_half_network == '70200' # 19.5h expected_log = "Estimated time to measure the network: 39 hours." # 19.5*2 assert caplog.records[-1].getMessage() == expected_log
def test_from_results_read(datadir, tmpdir, conf, args): results = load_result_file(str(datadir.join("results.txt"))) expected_header = V3BWHeader(timestamp_l, earliest_bandwidth=earliest_bandwidth, latest_bandwidth=latest_bandwidth) expected_bwls = [V3BWLine.from_results(results[fp]) for fp in results] # bw store now B, not KB expected_bwls[0].bw = round(expected_bwls[0].bw / 1000) expected_f = V3BWFile(expected_header, expected_bwls) # This way is going to convert bw to KB v3bwfile = V3BWFile.from_results(results) assert str(expected_f)[1:] == str(v3bwfile)[1:] output = os.path.join(args.output, now_fname()) v3bwfile.write(output)
def test_from_results_read(datadir, tmpdir, conf, args): results = load_result_file(str(datadir.join("results.txt"))) expected_header = V3BWHeader(timestamp_l, earliest_bandwidth=earliest_bandwidth, latest_bandwidth=latest_bandwidth) exclusion_dict = dict([ (k, 0) for k in BW_HEADER_KEYVALUES_RECENT_MEASUREMENTS_EXCLUDED ]) expected_header.add_relays_excluded_counters(exclusion_dict) raw_bwls = [V3BWLine.from_results(results[fp])[0] for fp in results] # Scale BWLines using torflow method, since it's the default and BWLines # bandwidth is the raw bandwidth. expected_bwls = V3BWFile.bw_torflow_scale(raw_bwls) expected_f = V3BWFile(expected_header, expected_bwls) # This way is going to convert bw to KB v3bwfile = V3BWFile.from_results(results) assert str(expected_f)[1:] == str(v3bwfile)[1:] output = os.path.join(args.output, now_fname()) v3bwfile.write(output)
def test_v3bwheader_str(): """Test header str""" header = V3BWHeader(timestamp_l, file_created=file_created) assert header_str == str(header)