[tor-bugs] #11335 [Stem]: Tests for example scripts
Tor Bug Tracker & Wiki
blackhole at torproject.org
Sun Dec 14 17:15:32 UTC 2014
#11335: Tests for example scripts
-----------------------------+--------------------------
Reporter: atagar | Owner: atagar
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: Stem | Version:
Resolution: | Keywords: testing easy
Actual Points: | Parent ID:
Points: |
-----------------------------+--------------------------
Comment (by atagar):
Looks great! Here's some suggestions that could make the code a bit
nicer...
-----
{{{
content = get_router_status_entry_v3({'r': r_line}, content = True)
entry = RouterStatusEntryV3(content)
}}}
Why not simply drop 'content = True' so the function provides you a
RouterStatusEntryV3?
-----
{{{
def side_effect_get_network_status(relay, default):
values = {
path_1[0]: _get_router_status("173.209.180.61"),
path_2[0]: _get_router_status("87.238.194.176"),
path_3[0]: _get_router_status("109.163.234.10"),
path_4[0]: _get_router_status("46.165.197.96"),
path_5[0]: _get_router_status("96.47.226.20"),
path_6[0]: _get_router_status("86.59.119.83"),
path_7[0]: _get_router_status("176.67.169.171")
}
return values[relay]
...
controller.get_network_status.side_effect = side_effect_get_network_status
}}}
A little trick I like to use for this is...
{{{
controller.get_network_status.side_effect = lambda fingerprint, *args: {
path_1[0]: _get_router_status("173.209.180.61"),
path_2[0]: _get_router_status("87.238.194.176"),
path_3[0]: _get_router_status("109.163.234.10"),
path_4[0]: _get_router_status("46.165.197.96"),
path_5[0]: _get_router_status("96.47.226.20"),
path_6[0]: _get_router_status("86.59.119.83"),
path_7[0]: _get_router_status("176.67.169.171")
}[fingerprint]
}}}
-----
{{{
circuit_4_path = PATH_CONTENT % (path_1[0], path_1[1], path_2[0],
path_2[1], path_3[0], path_3[1])
circuit_6_path = PATH_CONTENT % (path_1[0], path_1[1], path_4[0],
path_4[1], path_5[0], path_5[1])
circuit_10_path = PATH_CONTENT % (path_1[0], path_1[1], path_6[0],
path_6[1], path_7[0], path_7[1])
circuit_4_content = CIRC_CONTENT % (4, 'BUILT', circuit_4_path, 'GENERAL')
circuit_6_content = CIRC_CONTENT % (6, 'BUILT', circuit_6_path, 'GENERAL')
circuit_10_content = CIRC_CONTENT % (10, 'BUILT', circuit_10_path,
'GENERAL')
circuit_4 = _get_event(circuit_4_content)
circuit_6 = _get_event(circuit_6_content)
circuit_10 = _get_event(circuit_10_content)
}}}
It would probably make more sense for _get_event() the CIRC event
attributes. That is to say...
{{{
circuit_4 = _get_event(4, 'BUILT', hop1, hop2, hop3, 'GENERAL')
}}}
--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/11335#comment:6>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
More information about the tor-bugs
mailing list