[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [nyx/master] Make tests python 3.x compatible



commit c551866e1d24ffdc213c3ecd7e31bc595a899d6c
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Oct 30 10:42:15 2017 -0700

    Make tests python 3.x compatible
---
 test/__init__.py                   | 7 ++++++-
 test/cache.py                      | 6 +++++-
 test/panel/config.py               | 7 ++++++-
 test/panel/connection.py           | 7 ++++++-
 test/panel/graph.py                | 7 ++++++-
 test/panel/header.py               | 7 ++++++-
 test/panel/interpreter.py          | 7 ++++++-
 test/panel/log.py                  | 7 ++++++-
 test/panel/torrc.py                | 7 ++++++-
 test/popups.py                     | 7 ++++++-
 test/subwindow.py                  | 8 ++++++--
 test/tracker/connection_tracker.py | 6 +++++-
 test/tracker/daemon.py             | 6 +++++-
 test/tracker/port_usage_tracker.py | 6 +++++-
 test/tracker/resource_tracker.py   | 8 ++++++--
 15 files changed, 86 insertions(+), 17 deletions(-)

diff --git a/test/__init__.py b/test/__init__.py
index 4a998f0..7f7f19d 100644
--- a/test/__init__.py
+++ b/test/__init__.py
@@ -10,7 +10,12 @@ import unittest
 import nyx.curses
 
 from nyx import expand_path, chroot, join, uses_settings
-from mock import patch, Mock
+
+try:
+  # added in python 3.3
+  from unittest.mock import Mock, patch
+except ImportError:
+  from mock import Mock, patch
 
 __all__ = [
   'arguments',
diff --git a/test/cache.py b/test/cache.py
index 4c93c75..b6bfffb 100644
--- a/test/cache.py
+++ b/test/cache.py
@@ -9,7 +9,11 @@ import unittest
 
 import nyx
 
-from mock import Mock, patch
+try:
+  # added in python 3.3
+  from unittest.mock import Mock, patch
+except ImportError:
+  from mock import Mock, patch
 
 
 class TestCache(unittest.TestCase):
diff --git a/test/panel/config.py b/test/panel/config.py
index 99bbaec..0bf51ab 100644
--- a/test/panel/config.py
+++ b/test/panel/config.py
@@ -8,7 +8,12 @@ import nyx.panel.config
 import test
 
 from test import require_curses
-from mock import patch
+
+try:
+  # added in python 3.3
+  from unittest.mock import patch
+except ImportError:
+  from mock import patch
 
 EXPECTED_LINE = 'ControlPort               9051       Port providing access to tor...'
 
diff --git a/test/panel/connection.py b/test/panel/connection.py
index f075f77..ccc3aa5 100644
--- a/test/panel/connection.py
+++ b/test/panel/connection.py
@@ -13,7 +13,12 @@ import test
 from nyx.tracker import Connection
 from nyx.panel.connection import Category, LineType, Line, Entry
 from test import require_curses
-from mock import Mock, patch
+
+try:
+  # added in python 3.3
+  from unittest.mock import Mock, patch
+except ImportError:
+  from mock import Mock, patch
 
 TIMESTAMP = 1468170303.7
 CONNECTION = Connection(TIMESTAMP, False, '127.0.0.1', 3531, '75.119.206.243', 22, 'tcp', False)
diff --git a/test/panel/graph.py b/test/panel/graph.py
index 513a757..d22d6fb 100644
--- a/test/panel/graph.py
+++ b/test/panel/graph.py
@@ -12,7 +12,12 @@ import nyx.panel.graph
 import test
 
 from test import require_curses
-from mock import patch
+
+try:
+  # added in python 3.3
+  from unittest.mock import patch
+except ImportError:
+  from mock import patch
 
 EXPECTED_BLANK_GRAPH = """
 Download:
diff --git a/test/panel/header.py b/test/panel/header.py
index 1b07799..12db48f 100644
--- a/test/panel/header.py
+++ b/test/panel/header.py
@@ -14,7 +14,12 @@ import nyx.panel.header
 import test
 
 from test import require_curses
-from mock import patch, Mock
+
+try:
+  # added in python 3.3
+  from unittest.mock import Mock, patch
+except ImportError:
+  from mock import Mock, patch
 
 EXPECTED_PANEL = """
 nyx - odin (Linux 3.5.0-54-generic)        Tor 0.2.8.1-alpha-dev
diff --git a/test/panel/interpreter.py b/test/panel/interpreter.py
index b24a51f..3e68596 100644
--- a/test/panel/interpreter.py
+++ b/test/panel/interpreter.py
@@ -9,7 +9,12 @@ import nyx.panel.interpreter
 import test
 
 from test import require_curses
-from mock import patch
+
+try:
+  # added in python 3.3
+  from unittest.mock import patch
+except ImportError:
+  from mock import patch
 
 EXPECTED_PANEL = """
 Control Interpreter:
diff --git a/test/panel/log.py b/test/panel/log.py
index 95d7e9d..a05ed4f 100644
--- a/test/panel/log.py
+++ b/test/panel/log.py
@@ -10,7 +10,12 @@ import test
 
 from nyx.log import LogEntry, LogFilters
 from test import require_curses
-from mock import patch, Mock
+
+try:
+  # added in python 3.3
+  from unittest.mock import Mock, patch
+except ImportError:
+  from mock import Mock, patch
 
 EXPECTED_WRAPPED_MSG = """\
 16:41:37 [NOTICE] ho hum, ho hum, ho hum, ho hum, ho hum, ho hum, ho hum, ho
diff --git a/test/panel/torrc.py b/test/panel/torrc.py
index 732ec63..273f8f3 100644
--- a/test/panel/torrc.py
+++ b/test/panel/torrc.py
@@ -8,7 +8,12 @@ import nyx.panel.torrc
 import test
 
 from test import require_curses
-from mock import patch, Mock
+
+try:
+  # added in python 3.3
+  from unittest.mock import Mock, patch
+except ImportError:
+  from mock import Mock, patch
 
 TORRC = """
 ORPort 9050
diff --git a/test/popups.py b/test/popups.py
index 3e64914..6aabff4 100644
--- a/test/popups.py
+++ b/test/popups.py
@@ -11,7 +11,12 @@ import nyx.popups
 import test
 
 from test import require_curses, mock_keybindings
-from mock import patch, Mock
+
+try:
+  # added in python 3.3
+  from unittest.mock import Mock, patch
+except ImportError:
+  from mock import Mock, patch
 
 EXPECTED_HELP_POPUP = """
 Page 1 Commands:---------------------------------------------------------------+
diff --git a/test/subwindow.py b/test/subwindow.py
index bc7ce5a..52bfeb8 100644
--- a/test/subwindow.py
+++ b/test/subwindow.py
@@ -11,11 +11,15 @@ import nyx.curses
 import nyx.panel.interpreter
 import test
 
-from mock import call, Mock
-
 from test import require_curses
 from nyx.curses import Color, Attr
 
+try:
+  # added in python 3.3
+  from unittest.mock import call, Mock
+except ImportError:
+  from mock import call, Mock
+
 EXPECTED_ADDSTR_WRAP = """
 0123456789 0123456789
 0123456789 0123456789
diff --git a/test/tracker/connection_tracker.py b/test/tracker/connection_tracker.py
index 50faef1..672240b 100644
--- a/test/tracker/connection_tracker.py
+++ b/test/tracker/connection_tracker.py
@@ -5,7 +5,11 @@ from nyx.tracker import ConnectionTracker
 
 from stem.util import connection
 
-from mock import Mock, patch
+try:
+  # added in python 3.3
+  from unittest.mock import Mock, patch
+except ImportError:
+  from mock import Mock, patch
 
 STEM_CONNECTIONS = [
   connection.Connection('127.0.0.1', 3531, '75.119.206.243', 22, 'tcp', False),
diff --git a/test/tracker/daemon.py b/test/tracker/daemon.py
index 4a527f7..27f59e1 100644
--- a/test/tracker/daemon.py
+++ b/test/tracker/daemon.py
@@ -3,7 +3,11 @@ import unittest
 
 from nyx.tracker import Daemon
 
-from mock import Mock, patch
+try:
+  # added in python 3.3
+  from unittest.mock import Mock, patch
+except ImportError:
+  from mock import Mock, patch
 
 
 class TestDaemon(unittest.TestCase):
diff --git a/test/tracker/port_usage_tracker.py b/test/tracker/port_usage_tracker.py
index 7e69f21..c4c430a 100644
--- a/test/tracker/port_usage_tracker.py
+++ b/test/tracker/port_usage_tracker.py
@@ -3,7 +3,11 @@ import unittest
 
 from nyx.tracker import Process, PortUsageTracker, _process_for_ports
 
-from mock import Mock, patch
+try:
+  # added in python 3.3
+  from unittest.mock import Mock, patch
+except ImportError:
+  from mock import Mock, patch
 
 LSOF_OUTPUT = """\
 COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
diff --git a/test/tracker/resource_tracker.py b/test/tracker/resource_tracker.py
index 25837f1..3d31c3f 100644
--- a/test/tracker/resource_tracker.py
+++ b/test/tracker/resource_tracker.py
@@ -3,7 +3,11 @@ import unittest
 
 from nyx.tracker import ResourceTracker, _resources_via_ps, _resources_via_proc
 
-from mock import Mock, patch
+try:
+  # added in python 3.3
+  from unittest.mock import Mock, patch
+except ImportError:
+  from mock import Mock, patch
 
 PS_OUTPUT = """\
     TIME     ELAPSED   RSS %MEM
@@ -38,7 +42,7 @@ class TestResourceTracker(unittest.TestCase):
       resources = daemon.get_value()
 
       self.assertEqual(2, daemon.run_counter())
-      self.assertEqual(6.600189933523267, resources.cpu_sample)
+      self.assertTrue(17000 < resources.cpu_sample < 18000)
       self.assertEqual(250.09374999999997, resources.cpu_average)
       self.assertEqual(800.3, resources.cpu_total)
       self.assertEqual(6020, resources.memory_bytes)

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits