debug-viewer: PEP8 all the things

This commit is contained in:
Philippe Normand 2018-04-14 16:04:22 +01:00
parent e557b5326d
commit 8a9d72b7e6
17 changed files with 529 additions and 517 deletions

View file

@ -221,6 +221,7 @@ class ExceptHookManagerClass (object):
RuntimeWarning,
stacklevel=2)
ExceptHookManager = ExceptHookManagerClass()
@ -315,6 +316,7 @@ def _init_locale(gettext_domain=None):
gettext.textdomain(gettext_domain)
gettext.bind_textdomain_codeset(gettext_domain, "UTF-8")
def _init_logging(level):
if level == "none":
return
@ -332,6 +334,7 @@ def _init_logging(level):
logger.debug("logging at level %s", logging.getLevelName(level))
logger.info("using Python %i.%i.%i %s %i", *sys.version_info)
def _init_log_option(parser):
choices = ["none", "debug", "info", "warning", "error", "critical"]
parser.add_option("--log-level", "-l",
@ -343,6 +346,7 @@ def _init_log_option(parser):
help=_("Enable logging, possible values: ") + ", ".join(choices))
return parser
def main(main_function, option_parser, gettext_domain=None, paths=None):
# FIXME:

View file

@ -58,7 +58,7 @@ def gettext_cache():
def gettext_cache_access(s):
if not s in d:
if s not in d:
d[s] = gettext(s)
return d[s]
@ -104,6 +104,7 @@ class _XDGClass (object):
setattr(self, name, dir)
XDG = _XDGClass()

View file

@ -113,6 +113,7 @@ class DebugLevel (int):
return DebugLevel(self - 1)
debug_level_none = DebugLevel("NONE")
debug_level_error = DebugLevel("ERROR")
debug_level_warning = DebugLevel("WARN")
@ -310,10 +311,10 @@ class LineCache (Producer):
"I": debug_level_info, "W": debug_level_warning,
"E": debug_level_error, " ": debug_level_none}
ANSI = "(?:\x1b\\[[0-9;]*m)?"
ANSI_PATTERN = (r"\d:\d\d:\d\d\.\d+ " + ANSI +
r" *\d+" + ANSI +
r" +0x[0-9a-f]+ +" + ANSI +
r"([TFLDIEW ])")
ANSI_PATTERN = r"\d:\d\d:\d\d\.\d+ " + ANSI + \
r" *\d+" + ANSI + \
r" +0x[0-9a-f]+ +" + ANSI + \
r"([TFLDIEW ])"
BARE_PATTERN = ANSI_PATTERN.replace(ANSI, "")
rexp_bare = re.compile(BARE_PATTERN)
rexp_ansi = re.compile(ANSI_PATTERN)
@ -345,7 +346,7 @@ class LineCache (Producer):
break
match = rexp_match(line)
if match is None:
if rexp is rexp_ansi or not "\x1b" in line:
if rexp is rexp_ansi or "\x1b" not in line:
continue
match = rexp_ansi.match(line)
@ -432,9 +433,9 @@ class LogLines (object):
def __iter__(self):
l = len(self)
size = len(self)
i = 0
while i < l:
while i < size:
yield self[i]
i += 1

View file

@ -39,5 +39,6 @@ def main(args):
app.run()
if __name__ == "__main__":
main()

View file

@ -19,10 +19,6 @@
"""GStreamer Debug Viewer GUI module."""
def _(s):
return s
import logging
from gi.repository import Gtk, GLib
@ -31,6 +27,10 @@ from GstDebugViewer import Common, Data
from GstDebugViewer.GUI.colors import LevelColorThemeTango
from GstDebugViewer.GUI.models import LazyLogModel, LogModelBase
def _(s):
return s
# Sync with gst-inspector!
@ -526,7 +526,7 @@ class ColumnManager (Common.GUI.Manager):
before = self.column_order[:pos]
shown_names = [col.name for col in self.columns]
for col_class in before:
if not col_class.name in shown_names:
if col_class.name not in shown_names:
pos -= 1
return pos

View file

@ -43,7 +43,8 @@ class DebugLevelFilter (Filter):
col_id = LogModelBase.COL_LEVEL
if mode == self.this_and_above:
comparison_function = lambda x, y: x < y
def comparison_function(x, y):
return x < y
else:
comparison_function = get_comparison_function(
mode == self.all_but_this)

View file

@ -401,21 +401,21 @@ class FilteredLogModel (FilteredLogModelBase):
class SubRange (object):
__slots__ = ("l", "start", "stop",)
__slots__ = ("size", "start", "stop",)
def __init__(self, l, start, stop):
def __init__(self, size, start, stop):
if start > stop:
raise ValueError(
"need start <= stop (got %r, %r)" % (start, stop,))
if type(l) == type(self):
if type(size) == type(self):
# Another SubRange, don't stack:
start += l.start
stop += l.start
l = l.l
start += size.start
stop += size.start
size = size.size
self.l = l
self.size = size
self.start = start
self.stop = stop
@ -428,9 +428,9 @@ class SubRange (object):
else:
stop += self.stop
return self.l[i.start + self.start:stop]
return self.size[i.start + self.start:stop]
else:
return self.l[i + self.start]
return self.size[i + self.start]
def __len__(self):
@ -438,9 +438,9 @@ class SubRange (object):
def __iter__(self):
l = self.l
size = self.size
for i in range(self.start, self.stop):
yield l[i]
yield size[i]
class LineViewLogModel (FilteredLogModelBase):

View file

@ -19,12 +19,6 @@
"""GStreamer Debug Viewer GUI module."""
ZOOM_FACTOR = 1.15
def _(s):
return s
import os.path
from bisect import bisect_right, bisect_left
import logging
@ -48,6 +42,13 @@ from GstDebugViewer.GUI.models import (FilteredLogModel,
LogModelBase)
ZOOM_FACTOR = 1.15
def _(s):
return s
def action(func):
func.is_action_handler = True
@ -692,7 +693,8 @@ class Window (object):
def handle_edit_copy_message_action_activate(self, action):
col_id = LogModelBase.COL_MESSAGE
self.clipboard.set_text(self.get_active_line()[col_id].decode('utf8'), -1)
self.clipboard.set_text(self.get_active_line()[
col_id].decode('utf8'), -1)
@action
def handle_enlarge_text_action_activate(self, action):

View file

@ -39,6 +39,7 @@ def main_version(opt, value, parser, *args, **kwargs):
print("GStreamer Debug Viewer %s" % (version,))
sys.exit(0)
class Paths (Common.Main.PathsProgramBase):
program_name = "gst-debug-viewer"

View file

@ -434,7 +434,7 @@ class FindBarFeature (FeatureBase):
def handle_match_found(self, model, tree_iter):
if not self.search_state in ("search-forward", "search-backward",):
if self.search_state not in ("search-forward", "search-backward",):
self.logger.warning(
"inconsistent search state %r", self.search_state)
return

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python
def line_string(ts, pid, thread, level, category, filename, line, function,
object_, message):
@ -7,10 +8,12 @@ def line_string (ts, pid, thread, level, category, filename, line, function,
# FIXME: Regarding object_, this doesn't fully replicate the formatting!
return "%s %5d 0x%x %s %20s %s:%d:%s:<%s> %s" % (Data.time_args(ts), pid, thread,
level.name.ljust (5), category,
level.name.ljust(
5), category,
filename, line, function,
object_, message,)
def main():
import sys
@ -46,5 +49,6 @@ def main ():
print(line_string(ts, pid, thread, level, category, filename, file_line,
function, object_, message))
if __name__ == "__main__":
main()

View file

@ -30,9 +30,8 @@ import gi
from gi.repository import GObject
sys.path.insert (0, os.path.join (sys.path[0], os.pardir))
from .. import Common, Data, GUI
from GstDebugViewer import Common, Data, GUI
class TestParsingPerformance (object):
@ -68,11 +67,13 @@ class TestParsingPerformance (object):
print("time spent in user mode: %.2f s" % (rusage.ru_utime,))
print("time spent in system mode: %.2f s" % (rusage.ru_stime,))
def main():
if len(sys.argv) > 1:
test = TestParsingPerformance(sys.argv[1])
test.start()
if __name__ == "__main__":
main()

View file

@ -0,0 +1,281 @@
#!/usr/bin/env python
# -*- coding: utf-8; mode: python; -*-
#
# GStreamer Debug Viewer - View and analyze GStreamer debug log files
#
# Copyright (C) 2007 René Stadler <mail@renestadler.de>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
"""GStreamer Debug Viewer test suite for the custom tree models."""
import sys
import os
import os.path
from glob import glob
from unittest import TestCase, main as test_main
from .. import Common, Data
from .. GUI.filters import CategoryFilter, Filter
from .. GUI.models import (FilteredLogModel,
LogModelBase,
SubRange,)
class TestSubRange (TestCase):
def test_len(self):
values = list(range(20))
sr = SubRange(values, 0, 20)
self.assertEqual(len(sr), 20)
sr = SubRange(values, 10, 20)
self.assertEqual(len(sr), 10)
sr = SubRange(values, 0, 10)
self.assertEqual(len(sr), 10)
sr = SubRange(values, 5, 15)
self.assertEqual(len(sr), 10)
def test_iter(self):
values = list(range(20))
sr = SubRange(values, 0, 20)
self.assertEqual(list(sr), values)
sr = SubRange(values, 10, 20)
self.assertEqual(list(sr), list(range(10, 20)))
sr = SubRange(values, 0, 10)
self.assertEqual(list(sr), list(range(0, 10)))
sr = SubRange(values, 5, 15)
self.assertEqual(list(sr), list(range(5, 15)))
class Model (LogModelBase):
def __init__(self):
LogModelBase.__init__(self)
for i in range(20):
self.line_offsets.append(i * 100)
self.line_levels.append(Data.debug_level_debug)
def ensure_cached(self, line_offset):
pid = line_offset // 100
if pid % 2 == 0:
category = b"EVEN"
else:
category = b"ODD"
line_fmt = (b"0:00:00.000000000 %5i 0x0000000 DEBUG "
b"%20s dummy.c:1:dummy: dummy")
line_str = line_fmt % (pid, category,)
log_line = Data.LogLine.parse_full(line_str)
self.line_cache[line_offset] = log_line
def access_offset(self, line_offset):
return ""
class IdentityFilter (Filter):
def __init__(self):
def filter_func(row):
return True
self.filter_func = filter_func
class RandomFilter (Filter):
def __init__(self, seed):
import random
rand = random.Random()
rand.seed(seed)
def filter_func(row):
return rand.choice((True, False,))
self.filter_func = filter_func
class TestDynamicFilter (TestCase):
def test_unset_filter_rerange(self):
full_model = Model()
filtered_model = FilteredLogModel(full_model)
row_list = self.__row_list
self.assertEqual(row_list(full_model), list(range(20)))
self.assertEqual(row_list(filtered_model), list(range(20)))
filtered_model.set_range(5, 16)
self.assertEqual(row_list(filtered_model), list(range(5, 16)))
def test_identity_filter_rerange(self):
full_model = Model()
filtered_model = FilteredLogModel(full_model)
row_list = self.__row_list
self.assertEqual(row_list(full_model), list(range(20)))
self.assertEqual(row_list(filtered_model), list(range(20)))
filtered_model.add_filter(IdentityFilter(),
Common.Data.DefaultDispatcher())
filtered_model.set_range(5, 16)
self.assertEqual(row_list(filtered_model), list(range(5, 16)))
def test_filtered_range_refilter_skip(self):
full_model = Model()
filtered_model = FilteredLogModel(full_model)
row_list = self.__row_list
filtered_model.add_filter(CategoryFilter("EVEN"),
Common.Data.DefaultDispatcher())
self.__dump_model(filtered_model, "filtered")
self.assertEqual(row_list(filtered_model), list(range(1, 20, 2)))
self.assertEqual([filtered_model.line_index_from_super(i)
for i in range(1, 20, 2)],
list(range(10)))
self.assertEqual([filtered_model.line_index_to_super(i)
for i in range(10)],
list(range(1, 20, 2)))
filtered_model.set_range(1, 20)
self.__dump_model(filtered_model, "ranged (1, 20)")
self.__dump_model(filtered_model, "filtered range")
self.assertEqual([filtered_model.line_index_from_super(i)
for i in range(0, 19, 2)],
list(range(10)))
self.assertEqual([filtered_model.line_index_to_super(i)
for i in range(10)],
list(range(1, 20, 2)))
filtered_model.set_range(2, 20)
self.__dump_model(filtered_model, "ranged (2, 20)")
self.assertEqual(row_list(filtered_model), list(range(3, 20, 2)))
def test_filtered_range_refilter(self):
full_model = Model()
filtered_model = FilteredLogModel(full_model)
row_list = self.__row_list
rows = row_list(full_model)
rows_filtered = row_list(filtered_model)
self.__dump_model(full_model, "full model")
self.assertEqual(rows, rows_filtered)
self.assertEqual([filtered_model.line_index_from_super(i)
for i in range(20)],
list(range(20)))
self.assertEqual([filtered_model.line_index_to_super(i)
for i in range(20)],
list(range(20)))
filtered_model.set_range(5, 16)
self.__dump_model(filtered_model, "ranged model (5, 16)")
rows_ranged = row_list(filtered_model)
self.assertEqual(rows_ranged, list(range(5, 16)))
self.__dump_model(filtered_model, "filtered model (nofilter, 5, 15)")
filtered_model.add_filter(CategoryFilter("EVEN"),
Common.Data.DefaultDispatcher())
rows_filtered = row_list(filtered_model)
self.assertEqual(rows_filtered, list(range(5, 16, 2)))
self.__dump_model(filtered_model, "filtered model")
def test_random_filtered_range_refilter(self):
full_model = Model()
filtered_model = FilteredLogModel(full_model)
row_list = self.__row_list
self.assertEqual(row_list(full_model), list(range(20)))
self.assertEqual(row_list(filtered_model), list(range(20)))
filtered_model.add_filter(RandomFilter(538295943),
Common.Data.DefaultDispatcher())
random_rows = row_list(filtered_model)
self.__dump_model(filtered_model)
filtered_model = FilteredLogModel(full_model)
filtered_model.add_filter(RandomFilter(538295943),
Common.Data.DefaultDispatcher())
self.__dump_model(filtered_model, "filtered model")
self.assertEqual(row_list(filtered_model), random_rows)
filtered_model.set_range(1, 10)
self.__dump_model(filtered_model)
self.assertEqual(row_list(filtered_model), [
x for x in range(0, 10) if x in random_rows])
def __row_list(self, model):
return [row[Model.COL_PID] for row in model]
def __dump_model(self, model, comment=None):
# TODO: Provide a command line option to turn this on and off.
return
if not hasattr(model, "super_model"):
# Top model.
print("\t(%s)" % ("|".join([str(i).rjust(2)
for i in self.__row_list(model)]),), end=' ')
else:
top_model = model.super_model
if hasattr(top_model, "super_model"):
top_model = top_model.super_model
top_indices = self.__row_list(top_model)
positions = self.__row_list(model)
output = [" "] * len(top_indices)
for i, position in enumerate(positions):
output[position] = str(i).rjust(2)
print("\t(%s)" % ("|".join(output),), end=' ')
if comment is None:
print()
else:
print(comment)
if __name__ == "__main__":
test_main()

View file

@ -25,13 +25,14 @@ import os
import os.path
import distutils.cmd
from distutils.core import setup
from setuptools import setup
from distutils.command.clean import clean
from distutils.command.build import build
from distutils.command.sdist import sdist
from distutils.command.install_scripts import install_scripts
from distutils.errors import *
def perform_substitution(filename, values):
fp = file(filename, "rt")
@ -45,29 +46,6 @@ def perform_substitution (filename, values):
fp.write(data)
fp.close()
class tests (distutils.cmd.Command):
description = "run unit tests"
user_options = [("files=", "f", "test scripts",)]
def initialize_options (self):
self.files = []
def finalize_options (self):
from glob import glob
if self.files:
self.files = glob (os.path.join (*self.files.split ("/")))
else:
self.files = []
def run (self):
for filename in self.files:
self.spawn ([sys.executable, filename])
class clean_custom (clean):
@ -105,6 +83,7 @@ class clean_custom (clean):
file_path = os.path.join(path, filename)
self.remove_file(file_path)
class build_custom (build):
def build_l10n(self):
@ -112,7 +91,8 @@ class build_custom (build):
return self.l10n
sub_commands = build.sub_commands + [("build_l10n", build_l10n,)]
user_options = build.user_options + [("l10n", None, "enable translations",)]
user_options = build.user_options + \
[("l10n", None, "enable translations",)]
boolean_options = build.boolean_options + ["l10n"]
def initialize_options(self):
@ -121,6 +101,7 @@ class build_custom (build):
self.l10n = False
class build_l10n (distutils.cmd.Command):
# Based on code from python-distutils-extra by Sebastian Heinlein.
@ -172,7 +153,8 @@ class build_l10n (distutils.cmd.Command):
cwd = os.getcwd()
if self.bug_contact is not None:
os.environ["XGETTEXT_ARGS"] = "--msgid-bugs-address=%s" % (self.bug_contact,)
os.environ["XGETTEXT_ARGS"] = "--msgid-bugs-address=%s" % (
self.bug_contact,)
os.chdir(os.path.join(cwd, "po"))
# Update .pot file.
self.spawn(["intltool-update", "-p", "-g", self.domain])
@ -214,6 +196,7 @@ class build_l10n (distutils.cmd.Command):
self.spawn(["intltool-merge", option, "po", file, file_merged])
data_files.append((target, [file_merged],))
class distcheck (sdist):
# Originally based on code from telepathy-python.
@ -256,7 +239,8 @@ class distcheck (sdist):
# Unpack tarball into dist/distcheck/again.
os.chdir(cwd)
os.chdir(os.path.join(distcheck_dir, "again"))
archive_rel = os.path.join (os.pardir, base_dir, "dist", "%s.tar.gz" % (base_dir,))
archive_rel = os.path.join(
os.pardir, base_dir, "dist", "%s.tar.gz" % (base_dir,))
spawn(["tar", "-xzf", archive_rel, base_dir])
os.chdir(cwd)
@ -271,6 +255,7 @@ class distcheck (sdist):
if not self.keep_temp:
dir_util.remove_tree(distcheck_dir)
class install_scripts_custom (install_scripts):
user_options = install_scripts.user_options \
@ -312,33 +297,37 @@ class install_scripts_custom (install_scripts):
# ...then substitute in-place:
for filename in eval(self.substitute_files):
perform_substitution (os.path.join (self.install_dir, filename), values)
perform_substitution(os.path.join(
self.install_dir, filename), values)
cmdclass = {"build": build_custom,
"clean": clean_custom,
"install_scripts": install_scripts_custom,
"build_l10n": build_l10n,
"distcheck" : distcheck,
"tests" : tests}
"distcheck": distcheck}
setup(cmdclass=cmdclass,
packages=["GstDebugViewer",
"GstDebugViewer.Common",
"GstDebugViewer.GUI",
"GstDebugViewer.Plugins"],
"GstDebugViewer.Plugins",
"GstDebugViewer.tests"],
scripts=["gst-debug-viewer"],
data_files=[("share/gst-debug-viewer", ["data/about-dialog.ui",
"data/main-window.ui",
"data/menus.ui"],),
("share/icons/hicolor/48x48/apps", ["data/gst-debug-viewer.png"],),
("share/icons/hicolor/48x48/apps",
["data/gst-debug-viewer.png"],),
("share/icons/hicolor/scalable/apps", ["data/gst-debug-viewer.svg"],)],
name="gst-debug-viewer",
version="0.1",
description="GStreamer Debug Viewer",
long_description="""""",
test_suite="GstDebugViewer.tests",
license="GNU GPL",
author="Rene Stadler",
author_email="mail@renestadler.de",

View file

@ -1,274 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8; mode: python; -*-
#
# GStreamer Debug Viewer - View and analyze GStreamer debug log files
#
# Copyright (C) 2007 René Stadler <mail@renestadler.de>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
"""GStreamer Debug Viewer test suite for the custom tree models."""
import sys
import os
import os.path
from glob import glob
sys.path.insert (0, os.path.join (sys.path[0], os.pardir))
from unittest import TestCase, main as test_main
from GstDebugViewer import Common, Data
from GstDebugViewer.GUI.filters import CategoryFilter, Filter
from GstDebugViewer.GUI.models import (FilteredLogModel,
LogModelBase,
SubRange,)
class TestSubRange (TestCase):
def test_len (self):
l = list(range(20))
sr = SubRange (l, 0, 20)
self.assertEqual (len (sr), 20)
sr = SubRange (l, 10, 20)
self.assertEqual (len (sr), 10)
sr = SubRange (l, 0, 10)
self.assertEqual (len (sr), 10)
sr = SubRange (l, 5, 15)
self.assertEqual (len (sr), 10)
def test_iter (self):
l = list(range(20))
sr = SubRange (l, 0, 20)
self.assertEqual (list (sr), l)
sr = SubRange (l, 10, 20)
self.assertEqual (list (sr), list(range(10, 20)))
sr = SubRange (l, 0, 10)
self.assertEqual (list (sr), list(range(0, 10)))
sr = SubRange (l, 5, 15)
self.assertEqual (list (sr), list(range(5, 15)))
class Model (LogModelBase):
def __init__ (self):
LogModelBase.__init__ (self)
for i in range (20):
self.line_offsets.append (i * 100)
self.line_levels.append (Data.debug_level_debug)
def ensure_cached (self, line_offset):
pid = line_offset // 100
if pid % 2 == 0:
category = b"EVEN"
else:
category = b"ODD"
line_fmt = (b"0:00:00.000000000 %5i 0x0000000 DEBUG "
b"%20s dummy.c:1:dummy: dummy")
line_str = line_fmt % (pid, category,)
log_line = Data.LogLine.parse_full (line_str)
self.line_cache[line_offset] = log_line
def access_offset (self, line_offset):
return ""
class IdentityFilter (Filter):
def __init__ (self):
def filter_func (row):
return True
self.filter_func = filter_func
class RandomFilter (Filter):
def __init__ (self, seed):
import random
rand = random.Random ()
rand.seed (seed)
def filter_func (row):
return rand.choice ((True, False,))
self.filter_func = filter_func
class TestDynamicFilter (TestCase):
def test_unset_filter_rerange (self):
full_model = Model ()
filtered_model = FilteredLogModel (full_model)
row_list = self.__row_list
self.assertEqual (row_list (full_model), list(range(20)))
self.assertEqual (row_list (filtered_model), list(range(20)))
filtered_model.set_range (5, 16)
self.assertEqual (row_list (filtered_model), list(range(5, 16)))
def test_identity_filter_rerange (self):
full_model = Model ()
filtered_model = FilteredLogModel (full_model)
row_list = self.__row_list
self.assertEqual (row_list (full_model), list(range(20)))
self.assertEqual (row_list (filtered_model), list(range(20)))
filtered_model.add_filter (IdentityFilter (),
Common.Data.DefaultDispatcher ())
filtered_model.set_range (5, 16)
self.assertEqual (row_list (filtered_model), list(range(5, 16)))
def test_filtered_range_refilter_skip (self):
full_model = Model ()
filtered_model = FilteredLogModel (full_model)
row_list = self.__row_list
filtered_model.add_filter (CategoryFilter ("EVEN"),
Common.Data.DefaultDispatcher ())
self.__dump_model (filtered_model, "filtered")
self.assertEqual (row_list (filtered_model), list(range(1, 20, 2)))
self.assertEqual ([filtered_model.line_index_from_super (i)
for i in range (1, 20, 2)],
list(range(10)))
self.assertEqual ([filtered_model.line_index_to_super (i)
for i in range (10)],
list(range(1, 20, 2)))
filtered_model.set_range (1, 20)
self.__dump_model (filtered_model, "ranged (1, 20)")
self.__dump_model (filtered_model, "filtered range")
self.assertEqual ([filtered_model.line_index_from_super (i)
for i in range (0, 19, 2)],
list(range(10)))
self.assertEqual ([filtered_model.line_index_to_super (i)
for i in range (10)],
list(range(1, 20, 2)))
filtered_model.set_range (2, 20)
self.__dump_model (filtered_model, "ranged (2, 20)")
self.assertEqual (row_list (filtered_model), list(range(3, 20, 2)))
def test_filtered_range_refilter (self):
full_model = Model ()
filtered_model = FilteredLogModel (full_model)
row_list = self.__row_list
rows = row_list (full_model)
rows_filtered = row_list (filtered_model)
self.__dump_model (full_model, "full model")
self.assertEqual (rows, rows_filtered)
self.assertEqual ([filtered_model.line_index_from_super (i)
for i in range (20)],
list(range(20)))
self.assertEqual ([filtered_model.line_index_to_super (i)
for i in range (20)],
list(range(20)))
filtered_model.set_range (5, 16)
self.__dump_model (filtered_model, "ranged model (5, 16)")
rows_ranged = row_list (filtered_model)
self.assertEqual (rows_ranged, list(range(5, 16)))
self.__dump_model (filtered_model, "filtered model (nofilter, 5, 15)")
filtered_model.add_filter (CategoryFilter ("EVEN"),
Common.Data.DefaultDispatcher ())
rows_filtered = row_list (filtered_model)
self.assertEqual (rows_filtered, list(range(5, 16, 2)))
self.__dump_model (filtered_model, "filtered model")
def test_random_filtered_range_refilter (self):
full_model = Model ()
filtered_model = FilteredLogModel (full_model)
row_list = self.__row_list
self.assertEqual (row_list (full_model), list(range(20)))
self.assertEqual (row_list (filtered_model), list(range(20)))
filtered_model.add_filter (RandomFilter (538295943),
Common.Data.DefaultDispatcher ())
random_rows = row_list (filtered_model)
self.__dump_model (filtered_model)
filtered_model = FilteredLogModel (full_model)
filtered_model.add_filter (RandomFilter (538295943),
Common.Data.DefaultDispatcher ())
self.__dump_model (filtered_model, "filtered model")
self.assertEqual (row_list (filtered_model), random_rows)
filtered_model.set_range (1, 10)
self.__dump_model (filtered_model)
self.assertEqual (row_list (filtered_model), [x for x in range (0, 10) if x in random_rows])
def __row_list (self, model):
return [row[Model.COL_PID] for row in model]
def __dump_model (self, model, comment = None):
# TODO: Provide a command line option to turn this on and off.
return
if not hasattr (model, "super_model"):
# Top model.
print("\t(%s)" % ("|".join ([str (i).rjust (2) for i in self.__row_list (model)]),), end=' ')
else:
top_model = model.super_model
if hasattr (top_model, "super_model"):
top_model = top_model.super_model
top_indices = self.__row_list (top_model)
positions = self.__row_list (model)
output = [" "] * len (top_indices)
for i, position in enumerate (positions):
output[position] = str (i).rjust (2)
print("\t(%s)" % ("|".join (output),), end=' ')
if comment is None:
print()
else:
print(comment)
if __name__ == "__main__":
test_main ()

View file

@ -56,7 +56,7 @@ def main():
try:
if not modified_file.endswith(".py"):
continue
pycodestyle_errors = system('pycodestyle', '--repeat', '--ignore', 'E501,E128', modified_file)
pycodestyle_errors = system('pycodestyle', '--repeat', '--ignore', 'E501,E128,W605', modified_file)
if pycodestyle_errors:
if output_message is None:
output_message = NOT_PYCODESTYLE_COMPLIANT_MESSAGE_PRE