[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Fix unit tests
commit f269fc5846abc952a8d12a135ab94130814b6da9
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Feb 6 10:15:51 2016 -0800
Fix unit tests
Quite a few broken assertions due to recent changes.
---
nyx/controller.py | 2 +-
nyx/util/tor_config.py | 15 ---------------
setup.py | 2 +-
test/arguments.py | 8 ++++----
test/util/tracker/connection_tracker.py | 9 ++++++---
5 files changed, 12 insertions(+), 24 deletions(-)
diff --git a/nyx/controller.py b/nyx/controller.py
index b520aa7..aa6da8c 100644
--- a/nyx/controller.py
+++ b/nyx/controller.py
@@ -25,7 +25,7 @@ from stem.control import State
from nyx.util import panel, tor_controller, ui_tools
-from stem.util import conf, log, system
+from stem.util import conf, log
NYX_CONTROLLER = None
diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py
index 22abff7..3ffb435 100644
--- a/nyx/util/tor_config.py
+++ b/nyx/util/tor_config.py
@@ -50,24 +50,9 @@ TIME_MULT = {'sec': 1, 'min': 60, 'hour': 3600, 'day': 86400, 'week': 604800}
ValidationError = enum.Enum('DUPLICATE', 'MISMATCH', 'MISSING', 'IS_DEFAULT')
-TORRC = None # singleton torrc instance
MULTILINE_PARAM = None # cached multiline parameters (lazily loaded)
-def get_torrc():
- """
- Singleton constructor for a Controller. Be aware that this starts as being
- unloaded, needing the torrc contents to be loaded before being functional.
- """
-
- global TORRC
-
- if TORRC is None:
- TORRC = Torrc()
-
- return TORRC
-
-
def get_config_location():
"""
Provides the location of the torrc, raising an IOError with the reason if the
diff --git a/setup.py b/setup.py
index f5b1c05..13ae6af 100644
--- a/setup.py
+++ b/setup.py
@@ -102,6 +102,6 @@ setup(
packages = ['nyx', 'nyx.menu', 'nyx.util'],
keywords = 'tor onion controller',
install_requires = ['stem>=1.4.1'],
- package_data = {'nyx': ['config/*', 'resources/*']},
+ package_data = {'nyx': ['settings/*', 'resources/*']},
cmdclass = {'install': NyxInstaller},
)
diff --git a/test/arguments.py b/test/arguments.py
index 2336fdc..d27281c 100644
--- a/test/arguments.py
+++ b/test/arguments.py
@@ -67,7 +67,7 @@ class TestArgumentParsing(unittest.TestCase):
class TestExpandEvents(unittest.TestCase):
def test_examples(self):
- self.assertEqual(set(['INFO', 'NOTICE', 'UNKNOWN', 'STATUS_CLIENT']), expand_events('inUt'))
+ self.assertEqual(set(['INFO', 'NOTICE', 'UNKNOWN', 'TRANSPORT_LAUNCHED']), expand_events('inUt'))
self.assertEqual(set(['NOTICE', 'WARN', 'ERR', 'NYX_WARN', 'NYX_ERR']), expand_events('N4'))
self.assertEqual(set(), expand_events('cfX'))
@@ -89,13 +89,13 @@ class TestExpandEvents(unittest.TestCase):
# providing results even if there's other invalid options.
self.assertEqual(set(), expand_events('z*X*z'))
- self.assertEqual(28, len(expand_events('z*A*z')))
+ self.assertEqual(39, len(expand_events('z*A*z')))
def test_invalid_flags(self):
self._expect_invalid_flags('D1*', '*')
self._expect_invalid_flags('*D1', '*')
- self._expect_invalid_flags('zzD1zz', 'z')
- self._expect_invalid_flags('z*D1*z', 'z*')
+ self._expect_invalid_flags('zzD1Zz', 'Z')
+ self._expect_invalid_flags('Z*D1*z', 'Z*')
def _expect_invalid_flags(self, argument, expected):
try:
diff --git a/test/util/tracker/connection_tracker.py b/test/util/tracker/connection_tracker.py
index 0f3c93f..797c76b 100644
--- a/test/util/tracker/connection_tracker.py
+++ b/test/util/tracker/connection_tracker.py
@@ -7,9 +7,9 @@ from stem.util import connection
from mock import Mock, patch
-STEM_CONNECTION_1 = connection.Connection('127.0.0.1', 3531, '75.119.206.243', 22, 'tcp')
-STEM_CONNECTION_2 = connection.Connection('127.0.0.1', 1766, '86.59.30.40', 443, 'tcp')
-STEM_CONNECTION_3 = connection.Connection('127.0.0.1', 1059, '74.125.28.106', 80, 'tcp')
+STEM_CONNECTION_1 = connection.Connection('127.0.0.1', 3531, '75.119.206.243', 22, 'tcp', False)
+STEM_CONNECTION_2 = connection.Connection('127.0.0.1', 1766, '86.59.30.40', 443, 'tcp', False)
+STEM_CONNECTION_3 = connection.Connection('127.0.0.1', 1059, '74.125.28.106', 80, 'tcp', False)
class TestConnectionTracker(unittest.TestCase):
@@ -19,6 +19,7 @@ class TestConnectionTracker(unittest.TestCase):
@patch('nyx.util.tracker.connection.system_resolvers', Mock(return_value = [connection.Resolver.NETSTAT]))
def test_fetching_connections(self, get_value_mock, tor_controller_mock):
tor_controller_mock().get_pid.return_value = 12345
+ tor_controller_mock().get_conf.return_value = '0'
get_value_mock.return_value = [STEM_CONNECTION_1, STEM_CONNECTION_2, STEM_CONNECTION_3]
with ConnectionTracker(0.04) as daemon:
@@ -42,6 +43,7 @@ class TestConnectionTracker(unittest.TestCase):
@patch('nyx.util.tracker.connection.system_resolvers', Mock(return_value = [connection.Resolver.NETSTAT, connection.Resolver.LSOF]))
def test_resolver_failover(self, get_value_mock, tor_controller_mock):
tor_controller_mock().get_pid.return_value = 12345
+ tor_controller_mock().get_conf.return_value = '0'
get_value_mock.side_effect = IOError()
with ConnectionTracker(0.01) as daemon:
@@ -81,6 +83,7 @@ class TestConnectionTracker(unittest.TestCase):
@patch('nyx.util.tracker.connection.system_resolvers', Mock(return_value = [connection.Resolver.NETSTAT]))
def test_tracking_uptime(self, get_value_mock, tor_controller_mock):
tor_controller_mock().get_pid.return_value = 12345
+ tor_controller_mock().get_conf.return_value = '0'
get_value_mock.return_value = [STEM_CONNECTION_1]
first_start_time = time.time()
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits