commit 915b4d5f5c549d846aa0441b3528b48e354e16b9
Author: Damian Johnson <ata...@torproject.org>
Date:   Mon Aug 7 15:08:06 2017 -0700

    Pycodestyle compliance issues
    
    Newer version of pycodestyle does some additional validation. Some aren't
    issues we're concerned with.
---
 test/menu.py             | 25 ++++++++-------
 test/panel/connection.py | 81 +++++++++++++++++++++++++++---------------------
 test/settings.cfg        | 23 +++++++++-----
 test/subwindow.py        | 25 +++++++--------
 4 files changed, 87 insertions(+), 67 deletions(-)

diff --git a/test/menu.py b/test/menu.py
index 162e08c..c935c27 100644
--- a/test/menu.py
+++ b/test/menu.py
@@ -33,7 +33,10 @@ def menu_cursor(*key_inputs):
   return cursor
 
 
-NO_OP = lambda: None
+def no_op():
+  pass
+
+
 IS_CALLED = Container()
 
 TEST_MENU = Submenu('Root Submenu', [
@@ -59,7 +62,7 @@ class TestMenuItem(unittest.TestCase):
     IS_CALLED.value = False
 
   def test_parameters(self):
-    menu_item = MenuItem('Test Item', NO_OP)
+    menu_item = MenuItem('Test Item', no_op)
 
     self.assertEqual('', menu_item.prefix)
     self.assertEqual('Test Item', menu_item.label)
@@ -84,11 +87,11 @@ class TestMenuItem(unittest.TestCase):
     root_submenu = Submenu('Root Submenu')
     middle_submenu = Submenu('Middle Submenu')
 
-    root_submenu.add(MenuItem('Middle Item 1', NO_OP))
-    root_submenu.add(MenuItem('Middle Item 2', NO_OP))
+    root_submenu.add(MenuItem('Middle Item 1', no_op))
+    root_submenu.add(MenuItem('Middle Item 2', no_op))
     root_submenu.add(middle_submenu)
 
-    bottom_item = MenuItem('Bottom Item', NO_OP)
+    bottom_item = MenuItem('Bottom Item', no_op)
     middle_submenu.add(bottom_item)
 
     self.assertEqual(middle_submenu, bottom_item.parent)
@@ -118,16 +121,16 @@ class TestSubmenu(unittest.TestCase):
     self.assertEqual([], menu_item.children)
 
     menu_item = Submenu('Test Item', [
-      MenuItem('Test Item 1', NO_OP),
-      MenuItem('Test Item 2', NO_OP),
+      MenuItem('Test Item 1', no_op),
+      MenuItem('Test Item 2', no_op),
     ])
 
     self.assertEqual(2, len(menu_item.children))
 
   def test_add(self):
     submenu = Submenu('Menu')
-    item_1 = MenuItem('Test Item 1', NO_OP)
-    item_2 = MenuItem('Test Item 2', NO_OP)
+    item_1 = MenuItem('Test Item 1', no_op)
+    item_2 = MenuItem('Test Item 2', no_op)
 
     self.assertEqual([], submenu.children)
 
@@ -140,7 +143,7 @@ class TestSubmenu(unittest.TestCase):
   def test_add_raises_when_already_in_menu(self):
     submenu_1 = Submenu('Menu 1')
     submenu_2 = Submenu('Menu 2')
-    item = MenuItem('Test Item', NO_OP)
+    item = MenuItem('Test Item', no_op)
 
     submenu_1.add(item)
     self.assertRaises(ValueError, submenu_2.add, item)
@@ -151,7 +154,7 @@ class TestRadioMenuItem(unittest.TestCase):
     IS_CALLED.value = False
 
   def test_parameters(self):
-    group = RadioGroup(NO_OP, 'selected_item')
+    group = RadioGroup(no_op, 'selected_item')
     menu_item = RadioMenuItem('Test Item', group, 'selected_item')
 
     self.assertEqual('[X] ', menu_item.prefix)
diff --git a/test/panel/connection.py b/test/panel/connection.py
index 30db919..f01d99a 100644
--- a/test/panel/connection.py
+++ b/test/panel/connection.py
@@ -199,20 +199,24 @@ class TestConnectionPanel(unittest.TestCase):
     tor_controller_mock().get_info.return_value = '82.121.9.9'
     tor_controller_mock().is_geoip_unavailable.return_value = False
 
-    test_data = {
-      line():
-        ' 75.119.206.243:22 (de)  -->  82.121.9.9:3531                  15.4s 
(INBOUND)',
-      line(entry = MockEntry(entry_type = Category.CIRCUIT), line_type = 
LineType.CIRCUIT_HEADER):
-        ' 82.121.9.9             -->  75.119.206.243:22 (de)            15.4s 
(CIRCUIT)',
-      line(line_type = LineType.CIRCUIT, fingerprint = 
'1F43EE37A0670301AD9CB555D94AFEC2C89FDE86'):
-        ' |  82.121.9.9                                                    1 / 
Guard',
-      line(line_type = LineType.CIRCUIT, fingerprint = 
'B6D83EC2D9E18B0A7A33428F8CFA9C536769E209'):
-        ' |  82.121.9.9                                                    2 / 
Middle',
-      line(line_type = LineType.CIRCUIT, fingerprint = 
'E0BD57A11F00041A9789577C53A1B784473669E4'):
-        ' +- 82.121.9.9                                                    3 / 
Exit',
-    }
-
-    for test_line, expected in test_data.items():
+    test_data = ((
+      line(),
+      ' 75.119.206.243:22 (de)  -->  82.121.9.9:3531                  15.4s 
(INBOUND)',
+    ), (
+      line(entry = MockEntry(entry_type = Category.CIRCUIT), line_type = 
LineType.CIRCUIT_HEADER),
+      ' 82.121.9.9             -->  75.119.206.243:22 (de)            15.4s 
(CIRCUIT)',
+    ), (
+      line(line_type = LineType.CIRCUIT, fingerprint = 
'1F43EE37A0670301AD9CB555D94AFEC2C89FDE86'),
+      ' |  82.121.9.9                                                    1 / 
Guard',
+    ), (
+      line(line_type = LineType.CIRCUIT, fingerprint = 
'B6D83EC2D9E18B0A7A33428F8CFA9C536769E209'),
+      ' |  82.121.9.9                                                    2 / 
Middle',
+    ), (
+      line(line_type = LineType.CIRCUIT, fingerprint = 
'E0BD57A11F00041A9789577C53A1B784473669E4'),
+      ' +- 82.121.9.9                                                    3 / 
Exit',
+    ))
+
+    for test_line, expected in test_data:
       rendered = test.render(nyx.panel.connection._draw_line, 0, 0, test_line, 
False, 80, TIMESTAMP + 15.4)
       self.assertEqual(expected, rendered.content)
 
@@ -222,18 +226,21 @@ class TestConnectionPanel(unittest.TestCase):
     tor_controller_mock().get_info.return_value = '82.121.9.9'
     tor_controller_mock().is_geoip_unavailable.return_value = False
 
-    test_data = {
-      line():
-        '75.119.206.243:22 (de)  -->  82.121.9.9:3531',
-      line(entry = MockEntry(entry_type = Category.EXIT)):
-        '82.121.9.9:3531        -->  75.119.206.243:22 (SSH)',
-      line(line_type = LineType.CIRCUIT_HEADER, circ = MockCircuit(status = 
'EXTENDING')):
-        'Building...            -->  82.121.9.9',
-      line(line_type = LineType.CIRCUIT):
-        '82.121.9.9',
-    }
-
-    for test_line, expected in test_data.items():
+    test_data = ((
+      line(),
+      '75.119.206.243:22 (de)  -->  82.121.9.9:3531',
+    ), (
+      line(entry = MockEntry(entry_type = Category.EXIT)),
+      '82.121.9.9:3531        -->  75.119.206.243:22 (SSH)',
+    ), (
+      line(line_type = LineType.CIRCUIT_HEADER, circ = MockCircuit(status = 
'EXTENDING')),
+      'Building...            -->  82.121.9.9',
+    ), (
+      line(line_type = LineType.CIRCUIT),
+      '82.121.9.9',
+    ))
+
+    for test_line, expected in test_data:
       rendered = test.render(nyx.panel.connection._draw_address_column, 0, 0, 
test_line, ())
       self.assertEqual(expected, rendered.content)
 
@@ -246,16 +253,18 @@ class TestConnectionPanel(unittest.TestCase):
 
     port_usage_tracker_mock().fetch.return_value = process
 
-    test_data = {
-      line():
-        '1F43EE37A0670301AD9CB555D94AFEC2C89FDE86  Unnamed',
-      line(line_type = LineType.CIRCUIT_HEADER):
-        'Purpose: General, Circuit ID: 7',
-      line(entry = MockEntry(entry_type = Category.CONTROL)):
-        'firefox (722)',
-    }
-
-    for test_line, expected in test_data.items():
+    test_data = ((
+      line(),
+      '1F43EE37A0670301AD9CB555D94AFEC2C89FDE86  Unnamed',
+    ), (
+      line(line_type = LineType.CIRCUIT_HEADER),
+      'Purpose: General, Circuit ID: 7',
+    ), (
+      line(entry = MockEntry(entry_type = Category.CONTROL)),
+      'firefox (722)',
+    ))
+
+    for test_line, expected in test_data:
       rendered = test.render(nyx.panel.connection._draw_line_details, 0, 0, 
test_line, 80, ())
       self.assertEqual(expected, rendered.content)
 
diff --git a/test/settings.cfg b/test/settings.cfg
index 21679cd..dc1d851 100644
--- a/test/settings.cfg
+++ b/test/settings.cfg
@@ -1,15 +1,24 @@
-# PEP8 compliance issues that we're ignoreing.
+# Pycodestyle compliance issues that we're ignoreing.
 
-pep8.ignore E111
-pep8.ignore E114
-pep8.ignore E121
-pep8.ignore E501
-pep8.ignore E251
-pep8.ignore E127
+pycodestyle.ignore E111
+pycodestyle.ignore E114
+pycodestyle.ignore E121
+pycodestyle.ignore E501
+pycodestyle.ignore E251
+pycodestyle.ignore E127
+pycodestyle.ignore E722
 
 # False positives from pyflakes. These are mappings between the path and the
 # issue.
 
+pycodestyle.ignore nyx/__init__.py => E402: import nyx.curses
+pycodestyle.ignore nyx/__init__.py => E402: import nyx.menu
+pycodestyle.ignore nyx/__init__.py => E402: import nyx.panel
+pycodestyle.ignore nyx/__init__.py => E402: import nyx.panel.config
+pycodestyle.ignore nyx/__init__.py => E402: import nyx.panel.connection
+pycodestyle.ignore nyx/__init__.py => E402: import nyx.popups
+pycodestyle.ignore nyx/__init__.py => E402: import nyx.starter
+
 pyflakes.ignore nyx/prereq.py => 'stem' imported but unused
 pyflakes.ignore nyx/prereq.py => 'curses' imported but unused
 pyflakes.ignore run_tests.py => 'pyflakes' imported but unused
diff --git a/test/subwindow.py b/test/subwindow.py
index 61246d2..bee91f3 100644
--- a/test/subwindow.py
+++ b/test/subwindow.py
@@ -69,10 +69,13 @@ EXPECTED_SCROLLBAR_BOTTOM = """
 -+
 """.strip()
 
-NO_OP_HANDLER = lambda textbox, key: key
 DIMENSIONS = (40, 80)
 
 
+def no_op_handler(textbox, key):
+  return key
+
+
 def _textbox(x = 0, text = ''):
   textbox = Mock()
   textbox.win.getyx.return_value = (0, x)
@@ -185,31 +188,27 @@ class TestCurses(unittest.TestCase):
     self.assertEqual(curses.ascii.BEL, nyx.curses._handle_key(_textbox(), 410))
 
   def test_handle_tab_completion_no_op(self):
-    tab_completion = lambda txt_input: ['GETINFO version']
-    result = nyx.curses._handle_tab_completion(NO_OP_HANDLER, tab_completion, 
_textbox(), ord('a'))
+    result = nyx.curses._handle_tab_completion(no_op_handler, lambda 
txt_input: ['GETINFO version'], _textbox(), ord('a'))
     self.assertEqual(ord('a'), result)
 
   def test_handle_tab_completion_no_matches(self):
-    tab_completion = lambda txt_input: []
     textbox = _textbox(text = 'GETINF')
-    result = nyx.curses._handle_tab_completion(NO_OP_HANDLER, tab_completion, 
textbox, 9)
+    result = nyx.curses._handle_tab_completion(no_op_handler, lambda 
txt_input: [], textbox, 9)
 
     self.assertEqual(None, result)  # consumes input
     self.assertFalse(textbox.win.addstr.called)
 
   def test_handle_tab_completion_single_match(self):
-    tab_completion = lambda txt_input: ['GETINFO version']
     textbox = _textbox(text = 'GETINF')
-    result = nyx.curses._handle_tab_completion(NO_OP_HANDLER, tab_completion, 
textbox, 9)
+    result = nyx.curses._handle_tab_completion(no_op_handler, lambda 
txt_input: ['GETINFO version'], textbox, 9)
 
     self.assertEqual(None, result)  # consumes input
     self.assertEquals(call(0, 15), textbox.win.move.call_args)  # move cursor 
to end
     self.assertEqual(call(0, 0, 'GETINFO version'), 
textbox.win.addstr.call_args)
 
   def test_handle_tab_completion_multiple_matches(self):
-    tab_completion = lambda txt_input: ['GETINFO version', 'GETINFO 
info/events']
     textbox = _textbox(text = 'GETINF')
-    result = nyx.curses._handle_tab_completion(NO_OP_HANDLER, tab_completion, 
textbox, 9)
+    result = nyx.curses._handle_tab_completion(no_op_handler, lambda 
txt_input: ['GETINFO version', 'GETINFO info/events'], textbox, 9)
 
     self.assertEqual(None, result)  # consumes input
     self.assertEquals(call(0, 8), textbox.win.move.call_args)  # move cursor 
to end
@@ -219,22 +218,22 @@ class TestCurses(unittest.TestCase):
     backlog = nyx.curses._TextBacklog(['GETINFO version'])
     textbox = _textbox()
 
-    self.assertEqual(ord('a'), backlog._handler(NO_OP_HANDLER, textbox, 
ord('a')))
+    self.assertEqual(ord('a'), backlog._handler(no_op_handler, textbox, 
ord('a')))
     self.assertFalse(textbox.win.addstr.called)
 
   def test_text_backlog_fills_history(self):
     backlog = nyx.curses._TextBacklog(['GETINFO version'])
     textbox = _textbox()
 
-    self.assertEqual(None, backlog._handler(NO_OP_HANDLER, textbox, 
curses.KEY_UP))
+    self.assertEqual(None, backlog._handler(no_op_handler, textbox, 
curses.KEY_UP))
     self.assertEqual(call(0, 0, 'GETINFO version'), 
textbox.win.addstr.call_args)
 
   def test_text_backlog_remembers_custom_input(self):
     backlog = nyx.curses._TextBacklog(['GETINFO version'])
     textbox = _textbox(text = 'hello')
 
-    self.assertEqual(None, backlog._handler(NO_OP_HANDLER, textbox, 
curses.KEY_UP))
+    self.assertEqual(None, backlog._handler(no_op_handler, textbox, 
curses.KEY_UP))
     self.assertEqual(call(0, 0, 'GETINFO version'), 
textbox.win.addstr.call_args)
 
-    self.assertEqual(None, backlog._handler(NO_OP_HANDLER, textbox, 
curses.KEY_DOWN))
+    self.assertEqual(None, backlog._handler(no_op_handler, textbox, 
curses.KEY_DOWN))
     self.assertEqual(call(0, 0, 'hello'), textbox.win.addstr.call_args)



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

Reply via email to