[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Fix unit tests
commit 3ea784a3af26e6772e8ab3531e7185895567a6c7
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Wed Oct 28 15:02:01 2020 -0700
Fix unit tests
I don't run Nyx's unit tests very often so a few regressions slipped in. Some
due to Nyx adjustments, some from Stem.
Stem renamed its is_pep8_available() function to
is_pycodestyle_available() because the upstream project renamed itself...
Traceback (most recent call last):
File "./run_tests.py", line 80, in <module>
main()
File "/home/atagar/Desktop/nyx/stem/util/conf.py", line 289, in wrapped
return func(*args, **kwargs)
File "./run_tests.py", line 46, in main
if stem.util.test_tools.is_pep8_available():
AttributeError: module 'stem.util.test_tools' has no attribute 'is_pep8_available'
---
nyx/__init__.py | 1 +
nyx/curses.py | 2 +-
nyx/panel/log.py | 2 +-
run_tests.py | 2 +-
setup.py | 2 +-
test/panel/config.py | 2 +-
test/panel/connection.py | 12 ++++++++----
test/panel/header.py | 2 +-
8 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/nyx/__init__.py b/nyx/__init__.py
index 67053aa..9fbf2c0 100644
--- a/nyx/__init__.py
+++ b/nyx/__init__.py
@@ -138,6 +138,7 @@ def conf_handler(key, value):
if key == 'redraw_rate':
return max(1, value)
+
CONFIG = stem.util.conf.config_dict('nyx', {
'confirm_quit': True,
'redraw_rate': 5,
diff --git a/nyx/curses.py b/nyx/curses.py
index 3c3fa69..5ff5cfb 100644
--- a/nyx/curses.py
+++ b/nyx/curses.py
@@ -115,7 +115,7 @@ RED, GREEN, YELLOW, BLUE, CYAN, MAGENTA, BLACK, WHITE = list(Color)
Attr = stem.util.enum.Enum('NORMAL', 'BOLD', 'UNDERLINE', 'HIGHLIGHT')
NORMAL, BOLD, UNDERLINE, HIGHLIGHT = list(Attr)
-ANSI_RE = re.compile('\x1B\[([0-9;]+)m')
+ANSI_RE = re.compile('\x1B\\[([0-9;]+)m')
CURSES_COLORS = {
Color.RED: curses.COLOR_RED,
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index bbb1961..c6587a1 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -196,7 +196,7 @@ class LogPanel(nyx.panel.DaemonPanel):
try:
if not os.path.exists(base_dir):
os.makedirs(base_dir)
- except OSError as exc:
+ except OSError:
raise IOError("unable to make directory '%s'" % base_dir)
event_log = list(self._event_log)
diff --git a/run_tests.py b/run_tests.py
index 4c7f73d..3cab8a6 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -43,7 +43,7 @@ def main():
if stem.util.test_tools.is_pyflakes_available():
pyflakes_task = stem.util.system.DaemonTask(stem.util.test_tools.pyflakes_issues, (SRC_PATHS,), start = True)
- if stem.util.test_tools.is_pep8_available():
+ if stem.util.test_tools.is_pycodestyle_available():
pycodestyle_task = stem.util.system.DaemonTask(stem.util.test_tools.stylistic_issues, (SRC_PATHS,), start = True)
tests = unittest.defaultTestLoader.discover('test', pattern = '*.py')
diff --git a/setup.py b/setup.py
index 7e9b996..a4cd132 100644
--- a/setup.py
+++ b/setup.py
@@ -51,7 +51,7 @@ global-exclude *~
# installation. As such, just reading our file for the parameters we need.
ATTR = {}
-ATTR_LINE = re.compile("^__(\S+)__ = '(.+)'")
+ATTR_LINE = re.compile("^__(\\S+)__ = '(.+)'")
with open('nyx/__init__.py') as init_file:
for line in init_file:
diff --git a/test/panel/config.py b/test/panel/config.py
index 0bf51ab..7b138d0 100644
--- a/test/panel/config.py
+++ b/test/panel/config.py
@@ -20,7 +20,7 @@ EXPECTED_LINE = 'ControlPort 9051 Port providing access to t
EXPECTED_DETAIL_DIALOG = """
+------------------------------------------------------------------------------+
| ControlPort (General Option) |
-| Value: 9051 (custom, LineList, usage: PORT|unix:path|auto [flags]) |
+| Value: 9051 (custom, LineList, usage: [address:]port|unix:path|auto [flags]) |
| Description: If set, Tor will accept connections on this port and allow those|
| connections to control the Tor process using the Tor Control Protocol (des-|
| cribed in control-spec.txt in torspec). Note: unless you also specify one |
diff --git a/test/panel/connection.py b/test/panel/connection.py
index b432df5..56a7a66 100644
--- a/test/panel/connection.py
+++ b/test/panel/connection.py
@@ -201,8 +201,10 @@ class TestConnectionPanel(unittest.TestCase):
@require_curses
@patch('nyx.panel.connection.tor_controller')
def test_draw_line(self, tor_controller_mock):
- tor_controller_mock().is_geoip_unavailable.return_value = False
- tor_controller_mock().get_info.return_value = '82.121.9.9'
+ tor_controller_mock().get_info.side_effect = lambda param, default = None: {
+ 'ip-to-country/ipv4-available': '1',
+ 'address': '82.121.9.9',
+ }[param]
test_data = ((
line(),
@@ -228,8 +230,10 @@ class TestConnectionPanel(unittest.TestCase):
@require_curses
@patch('nyx.panel.connection.tor_controller')
def test_draw_address_column(self, tor_controller_mock):
- tor_controller_mock().is_geoip_unavailable.return_value = False
- tor_controller_mock().get_info.return_value = '82.121.9.9'
+ tor_controller_mock().get_info.side_effect = lambda param, default = None: {
+ 'ip-to-country/ipv4-available': '1',
+ 'address': '82.121.9.9',
+ }[param]
test_data = ((
line(),
diff --git a/test/panel/header.py b/test/panel/header.py
index 12db48f..fade2be 100644
--- a/test/panel/header.py
+++ b/test/panel/header.py
@@ -92,7 +92,6 @@ class TestHeaderPanel(unittest.TestCase):
@patch('time.time', Mock(return_value = 1234.5))
@patch('os.times', Mock(return_value = (0.08, 0.03, 0.0, 0.0, 18759021.31)))
@patch('os.uname', Mock(return_value = ('Linux', 'odin', '3.5.0-54-generic', '#81~precise1-Ubuntu SMP Tue Jul 15 04:05:58 UTC 2014', 'i686')))
- @patch('stem.util.system.start_time', Mock(return_value = 5678))
@patch('stem.util.proc.file_descriptors_used', Mock(return_value = 89))
def test_sample(self, consensus_tracker_mock, resource_tracker_mock, tor_controller_mock):
tor_controller_mock().is_alive.return_value = True
@@ -100,6 +99,7 @@ class TestHeaderPanel(unittest.TestCase):
tor_controller_mock().get_latest_heartbeat.return_value = 89.0
tor_controller_mock().get_newnym_wait.return_value = 0
tor_controller_mock().get_exit_policy.return_value = stem.exit_policy.ExitPolicy('reject *:*')
+ tor_controller_mock().get_start_time.return_value = 5678
tor_controller_mock().get_version.return_value = stem.version.Version('0.1.2.3-tag')
tor_controller_mock().get_pid.return_value = '123'
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits