File: test_decorators.py

package info (click to toggle)
python-easydev 0.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 504 kB
  • sloc: python: 2,130; javascript: 49; makefile: 13
file content (51 lines) | stat: -rw-r--r-- 794 bytes parent folder | download | duplicates (3)
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
from easydev.decorators import requires, ifpandas, ifpylab, _require


class A(object):

    def __init__(self):
        pass

    def create(self):
        self.a = 1
        self.b = 1

    @requires("a", "what to do")
    def print_str(self):
        print(self.a)

    @requires(["a",'b'], "what to do")
    def print_list(self):
        print(self.a +self.b)
    
    @_require("a", "what to do")
    def print_list(self):
        print(self.a)


def test():
    a = A()
    try:
        a.print_str()
        assert False
    except:
        assert True
    try:
        a.print_list()
        assert False
    except:
        assert True

    a.create()
    a.print_str()
    a.print_list()


@ifpandas
def test_deco_pandas():
    print(1)


@ifpylab
def test_deco_pylab():
    print(1)