[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Test _draw_title()
commit e5d29ccfdc8390a8e33b81256dc29cd917ed9b38
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Mon Jul 4 12:21:34 2016 -0700
Test _draw_title()
Testing our panel title draw function.
---
nyx/log.py | 2 ++
nyx/panel/log.py | 35 ++++++++++++++++++-----------------
test/panel/log.py | 21 ++++++++++++++++++++-
3 files changed, 40 insertions(+), 18 deletions(-)
diff --git a/nyx/log.py b/nyx/log.py
index ccc11e0..6e9eb83 100644
--- a/nyx/log.py
+++ b/nyx/log.py
@@ -414,6 +414,8 @@ class LogFilters(object):
self._lock = threading.RLock()
if initial_filters:
+ # register these regexes as options, then blank our selection
+
for regex in initial_filters:
self.select(regex)
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index 29bb159..bc229d9 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -298,7 +298,7 @@ class LogPanel(nyx.panel.DaemonPanel):
# drawing the title after the content, so we'll clear content from the top line
- self._draw_title(subwindow, subwindow.width, event_types, event_filter)
+ _draw_title(subwindow, event_types, event_filter)
# redraw the display if...
# - last_content_height was off by too much
@@ -326,22 +326,6 @@ class LogPanel(nyx.panel.DaemonPanel):
log.debug('redrawing the log panel with the corrected content height (%s)' % force_redraw_reason)
self.redraw(True)
- def _draw_title(self, subwindow, width, event_types, event_filter):
- """
- Panel title with the event types we're logging and our regex filter if set.
- """
-
- subwindow.addstr(0, 0, ' ' * width) # clear line
- title_comp = list(nyx.log.condense_runlevels(*event_types))
-
- if event_filter.selection():
- title_comp.append('filter: %s' % event_filter.selection())
-
- title_comp_str = join(title_comp, ', ', width - 10)
- title = 'Events (%s):' % title_comp_str if title_comp_str else 'Events:'
-
- subwindow.addstr(0, 0, title, HIGHLIGHT)
-
def _update(self):
"""
Redraws the display, coalescing updates if events are rapidly logged (for
@@ -381,6 +365,23 @@ class LogPanel(nyx.panel.DaemonPanel):
self._has_new_event = True
+def _draw_title(subwindow, event_types, event_filter):
+ """
+ Panel title with the event types we're logging and our regex filter if set.
+ """
+
+ subwindow.addstr(0, 0, ' ' * subwindow.width) # clear line
+ title_comp = list(nyx.log.condense_runlevels(*event_types))
+
+ if event_filter.selection():
+ title_comp.append('filter: %s' % event_filter.selection())
+
+ title_comp_str = join(title_comp, ', ', subwindow.width - 10)
+ title = 'Events (%s):' % title_comp_str if title_comp_str else 'Events:'
+
+ subwindow.addstr(0, 0, title, HIGHLIGHT)
+
+
def _draw_entry(subwindow, x, y, entry, show_duplicates):
"""
Presents a log entry with line wrapping.
diff --git a/test/panel/log.py b/test/panel/log.py
index 0fad2f1..9a408f4 100644
--- a/test/panel/log.py
+++ b/test/panel/log.py
@@ -7,7 +7,7 @@ import unittest
import nyx.panel.log
import test
-from nyx.log import LogEntry
+from nyx.log import LogEntry, LogFilters
from test import require_curses
EXPECTED_WRAPPED_MSG = """\
@@ -19,6 +19,25 @@ EXPECTED_WRAPPED_MSG = """\
class TestLogPanel(unittest.TestCase):
@require_curses
+ def test_draw_title(self):
+ rendered = test.render(nyx.panel.log._draw_title, ['NOTICE', 'WARN', 'ERR'], LogFilters())
+ self.assertEqual('Events (NOTICE-ERR):', rendered.content)
+
+ rendered = test.render(nyx.panel.log._draw_title, ['NYX_NOTICE', 'NYX_WARNING', 'NYX_ERROR', 'NOTICE', 'WARN', 'ERR'], LogFilters())
+ self.assertEqual('Events (TOR/NYX NOTICE-ERR):', rendered.content)
+
+ rendered = test.render(nyx.panel.log._draw_title, ['NYX_DEBUG', 'NYX_INFO', 'NYX_NOTICE', 'NYX_WARNING', 'NYX_ERROR', 'NOTICE', 'WARN', 'ERR'], LogFilters())
+ self.assertEqual('Events (NOTICE-ERR, NYX DEBUG-ERR):', rendered.content)
+
+ @require_curses
+ def test_draw_title_with_filter(self):
+ log_filter = LogFilters()
+ log_filter.select('stuff*')
+
+ rendered = test.render(nyx.panel.log._draw_title, ['NOTICE', 'WARN', 'ERR'], log_filter)
+ self.assertEqual('Events (NOTICE-ERR, filter: stuff*):', rendered.content)
+
+ @require_curses
def test_draw_entry(self):
entry = LogEntry(1467656897.08663, 'NOTICE', 'feeding sulfur to baby dragons is just mean...')
rendered = test.render(nyx.panel.log._draw_entry, 0, 0, entry, True)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits