# -*- coding: UTF-8 -*- # Copyright 2015 Red Hat, Inc. # Part of clufter project # Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt) """Common base for testing""" __author__ = "Jan Pokorný " from os.path import join, dirname as d; execfile(join(d(d((__file__))), '_go')) from os.path import dirname, join, split from sys import modules from unittest import TestCase from .filter_manager import FilterManager from .utils import filterdict_pop def rewrite_root(flt, new_root, **kwargs): # /foo/bar -> (/foo, bar) # /foo/bar/ -> (/foo/bar, ) new_root_dir, new_xml_root = split(new_root) old_root_dir = dirname(modules[flt.__class__.__module__].__file__) new_root_dir = join(old_root_dir, new_root_dir) new_kws = filterdict_pop(kwargs, 'walk_transform', root_dir=new_root_dir, xml_root=new_xml_root) flt._fnc = (lambda orig_fnc: lambda *args, **kws: orig_fnc(*args, **dict(kws, **new_kws)) )(flt._fnc) return flt class CommonFilterTestCase(TestCase): def setUp(self): self.flt_mgr = FilterManager.init_lookup(ext_plugins=False) class TeardownFilterTestCase(CommonFilterTestCase): def tearDown(self): self.flt_mgr.registry.setup(True) # start from scratch self.flt_mgr = None