summaryrefslogtreecommitdiffstats
path: root/tests/format_manager.py
blob: c2b80c434bc44831b8b39dc389de2a9f1597caec (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
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: UTF-8 -*-
# Copyright 2013 Red Hat, Inc.
# Part of clufter project
# Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
"""Testing format manager"""
__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"

import unittest

import _bootstrap  # known W402, required

from clufter.format_manager import FormatManager
from clufter.formats.ccs import ccs
from clufter.formats.ccs import flatccs
from clufter.formats.pcs import pcs


class FormatManagerTestCase(unittest.TestCase):
    def setUp(self):
        self.fmt_mgr = FormatManager()

    def tearDown(self):
        self.fmt_mgr.registry.setup(True)  # start from scratch
        self.fmt_mgr = None


class Default(FormatManagerTestCase):
    def test_default(self):
        formats = self.fmt_mgr.formats
        #print formats
        for cls in ccs, flatccs, pcs:
            self.assertTrue(cls.__name__ in formats)
            # the first was needed in the past, but now the more restrictive
            # one is ok
            self.assertEqual(type(cls), type(formats[cls.__name__]))
            self.assertEqual(cls, formats[cls.__name__])


class Injection(FormatManagerTestCase):
    formats = {'frobniccs': ccs}

    def setUp(self):
        self.fmt_mgr = FormatManager(paths=None, formats=self.formats)

    def test_injection(self):
        formats = self.fmt_mgr.formats
        #print formats
        self.assertTrue(len(formats) == len(self.formats))
        for fmt_id, fmt_cls in self.formats.iteritems():
            self.assertTrue(fmt_id in formats)
            self.assertEqual(fmt_cls, formats[fmt_id])


if __name__ == '__main__':
    unittest.main()