summaryrefslogtreecommitdiffstats
path: root/tests/_com
blob: 0a1e3e151ae2a2bd7686dab1f7f7621b59ba6649 (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
41
42
43
44
# -*- 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
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