summaryrefslogtreecommitdiffstats
path: root/tests/_com
blob: 61ce2f8e149d794246bd7676d955ad8b90e557c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- 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ý <jpokorny @at@ Red Hat .dot. com>"


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


def rewrite_root(flt, new_root):
    # /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)
    flt._fnc = (lambda orig_fnc:
        lambda *args, **kwargs: orig_fnc(*args, root_dir=new_root_dir,
                                                xml_root=new_xml_root, **kwargs)
    )(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