コード例 #1
0
ファイル: test_classifier.py プロジェクト: ldotlopez/zizi
class TestClassifierApp(unittest.TestCase):
    """
    Test bypass application
    """
    def __init__(self, *args, **kw):
        super(TestClassifierApp, self).__init__(*args, **kw)
        self._pp = pprint.PrettyPrinter(indent=4)

    def setUp(self):
        self._settings = ZiziConfigParser()
        self._settings.read_string(SETTINGS_STR)

        self._prefix = tempfile.mkdtemp()
        for i in [x for x in self._settings['pattern_renaming'].keys()]:
            path = join(self._prefix, self._settings.get('pattern_renaming', i))
            self._settings.set('pattern_renaming', i, path)

        for path in [x for x in INPUT.split("\n") if x]:
            path = join(self._prefix, path)

            (dname, bname) = split(path)
            if not isdir(dname):
                makedirs(dname)
            if (bname):
                open(path, 'a').close()

    def test_classifier(self):
        app = ClassifierApp()
        app.run(targets=[self._prefix], recursive=True, keep_root=True, settings=self._settings)

        outs = [x for x in OUTPUT.split("\n") if x]

        for path in outs:
            path = join(self._prefix, path)

            if path.endswith('/'):
                self.assertTrue(isdir(path), "Missing dir {}".format(path))
            else:
                self.assertTrue(isfile(path), "Missing file {}".format(path))
        print("Test run on {}".format(self._prefix))
コード例 #2
0
ファイル: misc.py プロジェクト: ldotlopez/zizi
def withconfig(f):
    """
    Decorates methods to read some parameters from config.ini and user-defined
    config
    """
    dname = dirname(sys.modules[f.__module__].__file__)
    appname = basename(dname)

    configfiles = (join(dname, 'config.ini'),
                   get_user_config_file(appname))

    cp = ZiziConfigParser()
    cp.read(configfiles)

    @wraps(f)
    def decorator(*args, **kwargs):
        if 'settings' not in kwargs:
            kwargs['settings'] = cp

        return f(*args, **kwargs)

    return decorator
コード例 #3
0
ファイル: test_classifier.py プロジェクト: ldotlopez/zizi
    def setUp(self):
        self._settings = ZiziConfigParser()
        self._settings.read_string(SETTINGS_STR)

        self._prefix = tempfile.mkdtemp()
        for i in [x for x in self._settings['pattern_renaming'].keys()]:
            path = join(self._prefix, self._settings.get('pattern_renaming', i))
            self._settings.set('pattern_renaming', i, path)

        for path in [x for x in INPUT.split("\n") if x]:
            path = join(self._prefix, path)

            (dname, bname) = split(path)
            if not isdir(dname):
                makedirs(dname)
            if (bname):
                open(path, 'a').close()