Skip to content

Commit

Permalink
Merge pull request #1185 from whirm/kill_is_unit_testing
Browse files Browse the repository at this point in the history
Remove is_unit_testing and fix the tests using it.
  • Loading branch information
LipuFei committed Feb 2, 2015
2 parents 7cc3dfc + c036f98 commit bd22fb5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
20 changes: 11 additions & 9 deletions Tribler/Main/tribler_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
DEBUG_DOWNLOADS = False
ALLOW_MULTIPLE = os.environ.get("TRIBLER_ALLOW_MULTIPLE", "False").lower() == "true"

SKIP_TUNNEL_DIALOG = os.environ.get("TRIBLER_SKIP_OPTIN_DLG", "False") == "True"
# used by the anon tunnel tests as there's no way to mess with the Session before running the test ATM.
FORCE_ENABLE_TUNNEL_COMMUNITY = False

#
#
# Class : ABCApp
Expand All @@ -138,13 +142,12 @@

class ABCApp(object):

def __init__(self, params, installdir, is_unit_testing=False, autoload_discovery=True):
def __init__(self, params, installdir, autoload_discovery=True):
assert not isInIOThread(), "isInIOThread() seems to not be working correctly"
self._logger = logging.getLogger(self.__class__.__name__)

self.params = params
self.installdir = installdir
self.is_unit_testing = is_unit_testing

self.state_dir = None
self.error = None
Expand Down Expand Up @@ -402,11 +405,10 @@ def InitStage1(self, installdir, autoload_discovery=True):
if not self.sconfig.get_torrent_collecting_dir():
self.sconfig.set_torrent_collecting_dir(os.path.join(defaultDLConfig.get_dest_dir(), STATEDIR_TORRENTCOLL_DIR))


#TODO(emilon): Quick hack to get 6.4.1 out the door, (re tunnel_community tests disabling is_unit_testing flag)
if os.environ.get("TRIBLER_SKIP_OPTIN_DLG", "False") == "True":
if FORCE_ENABLE_TUNNEL_COMMUNITY:
self.sconfig.set_tunnel_community_enabled(True)
elif not self.sconfig.get_tunnel_community_optin_dialog_shown() and not self.is_unit_testing:

if not self.sconfig.get_tunnel_community_optin_dialog_shown() and not SKIP_TUNNEL_DIALOG:
optin_dialog = wx.MessageDialog(None,
'If you are not familiar with proxy technology, please opt-out.\n\n'
'This experimental anonymity feature using Tor-inspired onion routing '
Expand Down Expand Up @@ -518,7 +520,7 @@ def define_communities(*args):
dispersy.define_auto_load(ChannelCommunity, session.dispersy_member, load=True, kargs=default_kwargs)
dispersy.define_auto_load(PreviewChannelCommunity, session.dispersy_member, kargs=default_kwargs)

if self.sconfig.get_tunnel_community_enabled() and not self.is_unit_testing:
if self.sconfig.get_tunnel_community_enabled():
keypair = dispersy.crypto.generate_key(u"NID_secp160k1")
dispersy_member = dispersy.get_member(private_key=dispersy.crypto.key_to_bin(keypair),)
settings = TunnelSettings(session.get_install_dir())
Expand Down Expand Up @@ -1096,7 +1098,7 @@ def start_asked_download():
#
#
@attach_profiler
def run(params=None, is_unit_testing=False, autoload_discovery=True):
def run(params=None, autoload_discovery=True):
if params is None:
params = [""]

Expand Down Expand Up @@ -1134,7 +1136,7 @@ def run(params=None, is_unit_testing=False, autoload_discovery=True):
app = wx.GetApp()
if not app:
app = wx.PySimpleApp(redirect=False)
abc = ABCApp(params, installdir, is_unit_testing, autoload_discovery=autoload_discovery)
abc = ABCApp(params, installdir, autoload_discovery=autoload_discovery)
if abc.frame:
app.SetTopWindow(abc.frame)
abc.frame.set_wxapp(app)
Expand Down
7 changes: 5 additions & 2 deletions Tribler/Test/test_as_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def setUp(self):
def setUpPreSession(self):
""" Should set self.config_path and self.config """
self.config = SessionStartupConfig()
self.config.set_tunnel_community_enabled(False)
self.config.set_tunnel_community_optin_dialog_shown(True)
self.config.set_state_dir(self.getStateDir())
self.config.set_torrent_checking(False)
self.config.set_multicast_local_peer_discovery(False)
Expand Down Expand Up @@ -263,10 +265,11 @@ def assert_(self, boolean, reason, do_assert=True):
if do_assert:
assert boolean, reason

def startTest(self, callback, min_timeout=5, force_is_unit_testing=True, autoload_discovery=True):
def startTest(self, callback, min_timeout=5, autoload_discovery=True):
from Tribler.Main.vwxGUI.GuiUtility import GUIUtility
from Tribler.Main import tribler_main
tribler_main.ALLOW_MULTIPLE = True
tribler_main.SKIP_TUNNEL_DIALOG = True

self.hadSession = False
starttime = time.time()
Expand Down Expand Up @@ -305,7 +308,7 @@ def wait_for_instance():

# modify argv to let tribler think its running from a different directory
sys.argv = [os.path.abspath('./.exe')]
tribler_main.run(is_unit_testing=force_is_unit_testing, autoload_discovery=autoload_discovery)
tribler_main.run(autoload_discovery=autoload_discovery)

assert self.hadSession, 'Did not even create a session'

Expand Down
8 changes: 4 additions & 4 deletions Tribler/Test/test_tunnel_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
from Tribler.dispersy.util import blockingCallFromThread


#TODO(emilon): Quick hack to get 6.4.1 out the door, (re tunnel_community tests disabling is_unit_testing flag)
environ["TRIBLER_SKIP_OPTIN_DLG"] = "True"

class TestTunnelCommunity(TestGuiAsServer):

def test_anon_download(self):
Expand Down Expand Up @@ -204,6 +201,9 @@ def cb_dht(info_hash, peers, source):
self.startTest(setup_seeder)

def startTest(self, callback, min_timeout=5):
from Tribler.Main import tribler_main
tribler_main.FORCE_ENABLE_TUNNEL_COMMUNITY = True

self.getStateDir() # getStateDir copies the bootstrap file into the statedir

def setup_proxies():
Expand Down Expand Up @@ -261,7 +261,7 @@ def load_community(session):

return blockingCallFromThread(reactor, load_community, session)

TestGuiAsServer.startTest(self, setup_proxies, force_is_unit_testing=False, autoload_discovery=False)
TestGuiAsServer.startTest(self, setup_proxies, autoload_discovery=False)

def setupSeeder(self):
from Tribler.Core.Session import Session
Expand Down
1 change: 0 additions & 1 deletion Tribler/community/channel/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ def _disp_on_torrent(self, messages):

torrentlist.append((self._channel_id, dispersy_id, peer_id, message.payload.infohash, message.payload.timestamp, message.payload.name, message.payload.files, message.payload.trackers))

# TODO: schedule a request for roothashes
self._channelcast_db.on_torrents_from_dispersy(torrentlist)
else:
for message in messages:
Expand Down

0 comments on commit bd22fb5

Please sign in to comment.