[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Drop expand_events()
commit 2ee29e7bd0557ec214f457777efb1789ca100274
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Tue Jun 7 09:25:01 2016 -0700
Drop expand_events()
With the move to the new event selection dialog this function is now unused.
---
nyx/arguments.py | 71 -------------------------------------------------------
test/arguments.py | 42 +-------------------------------
2 files changed, 1 insertion(+), 112 deletions(-)
diff --git a/nyx/arguments.py b/nyx/arguments.py
index 0515cea..6ed405d 100644
--- a/nyx/arguments.py
+++ b/nyx/arguments.py
@@ -203,77 +203,6 @@ def validate_events(events):
return accepted_events
-def expand_events(flags):
- """
- Expands event abbreviations to their full names. Beside mappings provided in
- TOR_EVENT_TYPES this recognizes the following special events and aliases:
-
- * A - all events
- * X - no events
- * U - UKNOWN events
- * DINWE - runlevel and higher
- * 12345 - nyx/stem runlevel and higher (NYX_DEBUG - NYX_ERR)
-
- For example...
-
- ::
-
- >>> expand_events('inUt')
- set(['INFO', 'NOTICE', 'UNKNOWN', 'STATUS_CLIENT'])
-
- >>> expand_events('N4')
- set(['NOTICE', 'WARN', 'ERR', 'NYX_WARN', 'NYX_ERR'])
-
- >>> expand_events('cfX')
- set([])
-
- :param str flags: character flags to be expanded
-
- :returns: **set** of the expanded event types
-
- :raises: **ValueError** with invalid input if any flags are unrecognized
- """
-
- expanded_events, invalid_flags = set(), ''
-
- for flag in flags:
- if flag == 'A':
- return set(list(TOR_EVENT_TYPES) + nyx.log.NYX_RUNLEVELS + ['UNKNOWN'])
- elif flag == 'X':
- return set()
- elif flag in 'DINWE12345':
- # all events for a runlevel and higher
-
- if flag in 'D1':
- runlevel_index = 0
- elif flag in 'I2':
- runlevel_index = 1
- elif flag in 'N3':
- runlevel_index = 2
- elif flag in 'W4':
- runlevel_index = 3
- elif flag in 'E5':
- runlevel_index = 4
-
- if flag in 'DINWE':
- runlevels = nyx.log.TOR_RUNLEVELS[runlevel_index:]
- elif flag in '12345':
- runlevels = nyx.log.NYX_RUNLEVELS[runlevel_index:]
-
- expanded_events.update(set(runlevels))
- elif flag == 'U':
- expanded_events.add('UNKNOWN')
- elif flag in TOR_EVENT_TYPES:
- expanded_events.add(TOR_EVENT_TYPES[flag])
- else:
- invalid_flags += flag
-
- if invalid_flags:
- raise ValueError(''.join(set(invalid_flags)))
- else:
- return expanded_events
-
-
def missing_event_types():
"""
Provides the event types the current tor connection supports but nyx
diff --git a/test/arguments.py b/test/arguments.py
index a0f678e..9d12651 100644
--- a/test/arguments.py
+++ b/test/arguments.py
@@ -2,7 +2,7 @@ import unittest
from mock import Mock, patch
-from nyx.arguments import DEFAULT_ARGS, parse, expand_events, missing_event_types
+from nyx.arguments import DEFAULT_ARGS, parse, missing_event_types
class TestArgumentParsing(unittest.TestCase):
@@ -65,46 +65,6 @@ class TestArgumentParsing(unittest.TestCase):
self.assertRaises(ValueError, parse, ['--interface', invalid_input])
-class TestExpandEvents(unittest.TestCase):
- def test_examples(self):
- self.assertEqual(set(['INFO', 'NOTICE', 'UNKNOWN', 'TRANSPORT_LAUNCHED']), expand_events('inUt'))
- self.assertEqual(set(['NOTICE', 'WARN', 'ERR', 'NYX_WARNING', 'NYX_ERROR']), expand_events('N4'))
- self.assertEqual(set(), expand_events('cfX'))
-
- def test_runlevel_expansion(self):
- self.assertEqual(set(['DEBUG', 'INFO', 'NOTICE', 'WARN', 'ERR']), expand_events('D'))
- self.assertEqual(set(['INFO', 'NOTICE', 'WARN', 'ERR']), expand_events('I'))
- self.assertEqual(set(['NOTICE', 'WARN', 'ERR']), expand_events('N'))
- self.assertEqual(set(['WARN', 'ERR']), expand_events('W'))
- self.assertEqual(set(['ERR']), expand_events('E'))
-
- self.assertEqual(set(['NYX_DEBUG', 'NYX_INFO', 'NYX_NOTICE', 'NYX_WARNING', 'NYX_ERROR']), expand_events('1'))
- self.assertEqual(set(['NYX_INFO', 'NYX_NOTICE', 'NYX_WARNING', 'NYX_ERROR']), expand_events('2'))
- self.assertEqual(set(['NYX_NOTICE', 'NYX_WARNING', 'NYX_ERROR']), expand_events('3'))
- self.assertEqual(set(['NYX_WARNING', 'NYX_ERROR']), expand_events('4'))
- self.assertEqual(set(['NYX_ERROR']), expand_events('5'))
-
- def test_short_circuit_options(self):
- # Check that the 'A' and 'X' options short circuit normal parsing,
- # providing results even if there's other invalid options.
-
- self.assertEqual(set(), expand_events('z*X*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*')
-
- def _expect_invalid_flags(self, argument, expected):
- try:
- expand_events(argument)
- self.fail()
- except ValueError as exc:
- self.assertEqual(set(expected), set(str(exc)))
-
-
class TestMissingEventTypes(unittest.TestCase):
@patch('nyx.arguments.tor_controller')
def test_with_a_failed_query(self, controller_mock):
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits