[tor-commits] [nyx/master] Mock static screen size in tests

atagar at torproject.org atagar at torproject.org
Wed Apr 6 16:29:04 UTC 2016


commit 12be6c891d8ff84246152bb940f7a99d94080508
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Apr 5 10:45:38 2016 -0700

    Mock static screen size in tests
    
    Our unit tests fail on smaller minitors (like my netbook) since the popup
    dimensions are smaller than expected. Mocking a static size to make these more
    reliable.
---
 test/popups.py | 68 ++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 40 insertions(+), 28 deletions(-)

diff --git a/test/popups.py b/test/popups.py
index 34ff587..0394003 100644
--- a/test/popups.py
+++ b/test/popups.py
@@ -163,38 +163,40 @@ Consensus Descriptor:----------+
 """.strip()
 
 EXPECTED_DESCRIPTOR = """
-Consensus Descriptor (29787760145CD1A473552A2FC64C72A9A130820E):---------------------------------------------------+
-|  1 Consensus:                                                                                                    |
-|  2                                                                                                               |
-|  3 r cyberphunk KXh3YBRc0aRzVSovxkxyqaEwgg4 VjdJThHuYj0jDY2tkkDJkCa8s1s 2016-04-04 19:03:16 94.23.150.191 8080 0 |
-|  4 s Fast Guard Running Stable Valid                                                                             |
-|  5 w Bandwidth=8410                                                                                              |
-|  6 p reject 1-65535                                                                                              |
-|  7                                                                                                               |
-|  8 Server Descriptor:                                                                                            |
-|  9                                                                                                               |
-| 10 router cyberphunk 94.23.150.191 8080 0 0                                                                      |
-| 11 platform Tor 0.2.4.27 on Linux                                                                                |
-| 12 protocols Link 1 2 Circuit 1                                                                                  |
-| 13 published 2016-04-04 19:03:16                                                                                 |
-| 14 fingerprint 2978 7760 145C D1A4 7355 2A2F C64C 72A9 A130 820E                                                 |
-| 15 uptime 3899791                                                                                                |
-| 16 bandwidth 10240000 10444800 6482376                                                                           |
-| 17 extra-info-digest 9DC532664DDFD238A4119D623D30F136A3B851BF                                                    |
-| 18 reject *:*                                                                                                    |
-| 19 router-signature                                                                                              |
-| 20 -----BEGIN SIGNATURE-----                                                                                     |
-| 21 EUFm38gONCoDuY7ZWHyJtBKuvk6Xi1MPuKuecS5frP3fX0wiZSrOVcpX0X8J+4Hr                                              |
-| 22 Fb5i+yuMIAXeEn6UhtjqhhZBbY9PW9GdZOMTH8hJpG+evURyr+10PZq6UElg86rA                                              |
-| 23 NCGI042p6+7UgCVT1x3WcLnq3ScV//s1wXHrUXa7vi0=                                                                  |
-| 24 -----END SIGNATURE-----                                                                                       |
-+------------------------------------------------------------------------------------------------------------------+
+Consensus Descriptor (29787760145CD1A473552A2FC64C72A9A130820E):---------------+
+|  1 Consensus:                                                                |
+|  2                                                                           |
+|  3 r cyberphunk KXh3YBRc0aRzVSovxkxyqaEwgg4 VjdJThHuYj0jDY2tkkDJkCa8s1s      |
+|     2016-04-04 19:03:16 94.23.150.191 8080 0                                 |
+|  4 s Fast Guard Running Stable Valid                                         |
+|  5 w Bandwidth=8410                                                          |
+|  6 p reject 1-65535                                                          |
+|  7                                                                           |
+|  8 Server Descriptor:                                                        |
+|  9                                                                           |
+| 10 router cyberphunk 94.23.150.191 8080 0 0                                  |
+| 11 platform Tor 0.2.4.27 on Linux                                            |
+| 12 protocols Link 1 2 Circuit 1                                              |
+| 13 published 2016-04-04 19:03:16                                             |
+| 14 fingerprint 2978 7760 145C D1A4 7355 2A2F C64C 72A9 A130 820E             |
+| 15 uptime 3899791                                                            |
+| 16 bandwidth 10240000 10444800 6482376                                       |
+| 17 extra-info-digest 9DC532664DDFD238A4119D623D30F136A3B851BF                |
+| 18 reject *:*                                                                |
+| 19 router-signature                                                          |
+| 20 -----BEGIN SIGNATURE-----                                                 |
+| 21 EUFm38gONCoDuY7ZWHyJtBKuvk6Xi1MPuKuecS5frP3fX0wiZSrOVcpX0X8J+4Hr          |
+| 22 Fb5i+yuMIAXeEn6UhtjqhhZBbY9PW9GdZOMTH8hJpG+evURyr+10PZq6UElg86rA          |
+| 23 NCGI042p6+7UgCVT1x3WcLnq3ScV//s1wXHrUXa7vi0=                              |
+| 24 -----END SIGNATURE-----                                                   |
++------------------------------------------------------------------------------+
 """.strip()
 
 
 class TestPopups(unittest.TestCase):
-  @patch('nyx.controller.get_controller')
   @patch('nyx.popups._top', Mock(return_value = 0))
+  @patch('nyx.curses.screen_size', Mock(return_value = nyx.curses.Dimensions(80, 60)))
+  @patch('nyx.controller.get_controller')
   def test_help(self, get_controller_mock):
     header_panel = Mock()
 
@@ -229,16 +231,19 @@ class TestPopups(unittest.TestCase):
     self.assertEqual(EXPECTED_HELP_POPUP, rendered.content)
 
   @patch('nyx.popups._top', Mock(return_value = 0))
+  @patch('nyx.curses.screen_size', Mock(return_value = nyx.curses.Dimensions(80, 60)))
   def test_about(self):
     rendered = test.render(nyx.popups.show_about)
     self.assertEqual(EXPECTED_ABOUT_POPUP, rendered.content)
 
   @patch('nyx.popups._top', Mock(return_value = 0))
+  @patch('nyx.curses.screen_size', Mock(return_value = nyx.curses.Dimensions(80, 60)))
   def test_counts_when_empty(self):
     rendered = test.render(nyx.popups.show_counts, 'Client Locales', {})
     self.assertEqual(EXPECTED_EMPTY_COUNTS, rendered.content)
 
   @patch('nyx.popups._top', Mock(return_value = 0))
+  @patch('nyx.curses.screen_size', Mock(return_value = nyx.curses.Dimensions(80, 60)))
   def test_counts(self):
     clients = {
       'fr': 5,
@@ -252,6 +257,7 @@ class TestPopups(unittest.TestCase):
     self.assertEqual(EXPECTED_COUNTS, rendered.content)
 
   @patch('nyx.popups._top', Mock(return_value = 0))
+  @patch('nyx.curses.screen_size', Mock(return_value = nyx.curses.Dimensions(80, 60)))
   def test_select_from_list(self):
     options = ['each second', '5 seconds', '30 seconds', 'minutely', '15 minute', '30 minute', 'hourly', 'daily']
     rendered = test.render(nyx.popups.select_from_list, 'Update Interval:', options, 'each second')
@@ -259,6 +265,7 @@ class TestPopups(unittest.TestCase):
     self.assertEqual('each second', rendered.return_value)
 
   @patch('nyx.popups._top', Mock(return_value = 0))
+  @patch('nyx.curses.screen_size', Mock(return_value = nyx.curses.Dimensions(80, 60)))
   def test_select_sort_order(self):
     previous_order = ['Man Page Entry', 'Name', 'Is Set']
     options = ['Name', 'Value', 'Value Type', 'Category', 'Usage', 'Summary', 'Description', 'Man Page Entry', 'Is Set']
@@ -268,6 +275,7 @@ class TestPopups(unittest.TestCase):
     self.assertEqual(None, rendered.return_value)
 
   @patch('nyx.popups._top', Mock(return_value = 0))
+  @patch('nyx.curses.screen_size', Mock(return_value = nyx.curses.Dimensions(80, 60)))
   def test_select_sort_order_usage(self):
     # Use the dialog to make a selection. At the end we render two options as
     # being selected (rather than three) because the act of selecing the third
@@ -292,6 +300,7 @@ class TestPopups(unittest.TestCase):
     self.assertEqual(['Name', 'Summary', 'Description'], rendered.return_value)
 
   @patch('nyx.popups._top', Mock(return_value = 0))
+  @patch('nyx.curses.screen_size', Mock(return_value = nyx.curses.Dimensions(80, 60)))
   @patch('nyx.controller.input_prompt', Mock(return_value = None))
   def test_select_event_types_when_canceled(self):
     rendered = test.render(nyx.popups.select_event_types)
@@ -299,14 +308,15 @@ class TestPopups(unittest.TestCase):
     self.assertEqual(None, rendered.return_value)
 
   @patch('nyx.popups._top', Mock(return_value = 0))
+  @patch('nyx.curses.screen_size', Mock(return_value = nyx.curses.Dimensions(80, 60)))
   @patch('nyx.controller.input_prompt', Mock(return_value = '2bwe'))
   def test_select_event_types_with_input(self):
     rendered = test.render(nyx.popups.select_event_types)
     self.assertEqual(EXPECTED_EVENT_SELECTOR, rendered.content)
     self.assertEqual(set(['NYX_INFO', 'ERR', 'WARN', 'BW', 'NYX_ERR', 'NYX_WARN', 'NYX_NOTICE']), rendered.return_value)
 
-  @patch('nyx.curses.screen_size', Mock(return_value = nyx.curses.Dimensions(80, 60)))
   @patch('nyx.popups._top', Mock(return_value = 0))
+  @patch('nyx.curses.screen_size', Mock(return_value = nyx.curses.Dimensions(80, 60)))
   def test_confirm_save_torrc(self):
     rendered = test.render(nyx.popups.confirm_save_torrc, TORRC)
     self.assertEqual(EXPECTED_SAVE_TORRC_CONFIRMATION, rendered.content)
@@ -321,12 +331,14 @@ class TestPopups(unittest.TestCase):
     self.assertEqual(True, rendered.return_value)
 
   @patch('nyx.popups._top', Mock(return_value = 0))
+  @patch('nyx.curses.screen_size', Mock(return_value = nyx.curses.Dimensions(80, 60)))
   def test_descriptor_without_fingerprint(self):
     rendered = test.render(nyx.popups.show_descriptor, None, nyx.curses.Color.RED, lambda key: key.match('esc'))
     self.assertEqual(EXPECTED_DESCRIPTOR_WITHOUT_FINGERPRINT, rendered.content)
     self.assertEqual(nyx.curses.KeyInput(27), rendered.return_value)
 
   @patch('nyx.popups._top', Mock(return_value = 0))
+  @patch('nyx.curses.screen_size', Mock(return_value = nyx.curses.Dimensions(80, 60)))
   @patch('nyx.popups._descriptor_text', Mock(return_value = DESCRIPTOR_TEXT))
   def test_descriptor(self):
     rendered = test.render(nyx.popups.show_descriptor, '29787760145CD1A473552A2FC64C72A9A130820E', nyx.curses.Color.RED, lambda key: key.match('esc'))



More information about the tor-commits mailing list