summaryrefslogtreecommitdiffstats
path: root/src/nbblib/test-plugins.py
blob: aee2d235070e645489528ea18be5e602b6cc7c5b (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python
"""Test newplugins module"""

import logging
import sys

logging.basicConfig(level = logging.DEBUG,
                    format = "%(levelname)s: %(message)s",
                    stream = sys.stderr)
if True:
   logging.debug("xxx debug")
   logging.info("xxx info")
   logging.warning("xxx warn")
   logging.error("xxx error")


from plugins import *

# Not for __all__
def selftest():

    class PluginNoMatchA(PluginNoMatch):
        pass
    class AmbigousPluginDetectionA(AmbigousPluginDetection):
        pass


    class TestDetectPluginA(GenericDetectPlugin):
        __metaclass__ = GenericPluginMeta
        no_match_exception = PluginNoMatchA
        ambigous_match_exception = AmbigousPluginDetectionA
        @classmethod
        def validate(cls, obj, context, *args, **kwargs):
            logging.debug("Aval")
            return False


    class TestDetectPluginB(GenericDetectPlugin):
        __metaclass__ = GenericPluginMeta


    class TestDetectPluginC(GenericDetectPlugin):
        __metaclass__ = GenericPluginMeta
        @classmethod
        def validate(cls, obj, context, *args, **kwargs):
            logging.debug("Cval")
            return False


    class TestDetectPluginA1(TestDetectPluginA):
        name = "A1"
    class TestDetectPluginA2(TestDetectPluginA):
        name = "A2"
    class TestDetectPluginA3(TestDetectPluginA):
        name = "A3"

    class TestDetectPluginB1(TestDetectPluginB):
        name = "B1"
    class TestDetectPluginB2(TestDetectPluginB):
        name = "B2"
    class TestDetectPluginB3(TestDetectPluginB):
        name = "B3"

    class TestDetectPluginC1(TestDetectPluginC):
        name = "C1"
    class TestDetectPluginC2(TestDetectPluginC):
        name = "C2"
    class TestDetectPluginC3(TestDetectPluginC):
        name = "C3"
        @classmethod
        def validate(cls, obj, context, *args, **kwargs):
            logging.debug("C3val")
            return True

    ctx = None

    print "GenericPluginMeta", dir(GenericPluginMeta)
    print "GenericDetectPlugin", dir(GenericDetectPlugin)
    print "TestDetectPluginA", dir(TestDetectPluginA)
    print "TestDetectPluginA", dir(TestDetectPluginA)
    print "TestDetectPluginB", dir(TestDetectPluginB)
    print "TestDetectPluginC", dir(TestDetectPluginC)

    try:
        a = TestDetectPluginA.detect(ctx)
    except:
        logging.error("aaaa", exc_info=True)

    try:
        b = TestDetectPluginB.detect(ctx)
    except:
        logging.error("bbbb", exc_info=True)

    try:
        c = TestDetectPluginC.detect(ctx)
    except:
        logging.error("cccc", exc_info=True)

selftest()