File: config_fs.py

package info (click to toggle)
pcs 0.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,148 kB
  • sloc: python: 238,810; xml: 20,833; ruby: 13,203; makefile: 1,595; sh: 484
file content (164 lines) | stat: -rw-r--r-- 3,960 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
from pcs_test.tools.command_env.mock_fs import Call as FsCall


class FsConfig:
    """
    Any new call must be manually added to the patch_env function in the
    pcs_test.tools.command_env.assistant module otherwise it will be ignored!
    Also its arguments must be described in the _FUNC_ARGS mapping in the
    pcs_test.tools.command_env.mock_fs module.
    """

    def __init__(self, call_collection):
        self.__calls = call_collection

    def open(
        self,
        path,
        return_value=None,
        side_effect=None,
        name="fs.open",
        mode="r",
        before=None,
        instead=None,
    ):
        call = FsCall(
            "open",
            call_kwargs={"name": path, "mode": mode},
            # TODO use mock_open here. Allow to use simply "read_data",
            # "side_effect" etc. It depends on future use cases...
            return_value=return_value,
            side_effect=side_effect,
        )
        self.__calls.place(name, call, before, instead)

    def exists(
        self,
        path,
        return_value=True,
        name="fs.exists",
        before=None,
        instead=None,
    ):
        call = FsCall(
            "os.path.exists",
            call_kwargs={"path": path},
            return_value=return_value,
        )
        self.__calls.place(name, call, before, instead)

    def chmod(
        self,
        path,
        mode,
        side_effect=None,
        name="os.chmod",
        before=None,
        instead=None,
    ):
        call = FsCall(
            "os.chmod",
            call_kwargs=dict(
                fd=path,
                mode=mode,
            ),
            side_effect=side_effect,
        )
        self.__calls.place(name, call, before, instead)

    def chown(
        self,
        path,
        uid,
        gid,
        side_effect=None,
        name="os.chown",
        before=None,
        instead=None,
    ):
        call = FsCall(
            "os.chown",
            call_kwargs=dict(
                fd=path,
                uid=uid,
                gid=gid,
            ),
            side_effect=side_effect,
        )
        self.__calls.place(name, call, before, instead)

    def isfile(
        self,
        path,
        return_value=True,
        name="fs.isfile",
        before=None,
        instead=None,
    ):
        call = FsCall(
            "os.path.isfile",
            call_kwargs={"path": path},
            return_value=return_value,
        )
        self.__calls.place(name, call, before, instead)

    def isdir(
        self,
        path,
        return_value=True,
        name="fs.isdir",
        before=None,
        instead=None,
    ):
        call = FsCall(
            "os.path.isdir",
            call_kwargs={"path": path},
            return_value=return_value,
        )
        self.__calls.place(name, call, before, instead)

    def listdir(
        self,
        path,
        return_value=(),
        name="fs.listdir",
        before=None,
        instead=None,
    ):
        call = FsCall(
            "os.listdir",
            call_kwargs={"path": path},
            return_value=list(return_value),
        )
        self.__calls.place(name, call, before, instead)

    def rmtree(
        self,
        path,
        return_value=None,
        name="fs.rmtree",
        before=None,
        instead=None,
    ):
        call = FsCall(
            "shutil.rmtree",
            call_kwargs={"path": path},
            return_value=return_value,
        )
        self.__calls.place(name, call, before, instead)

    def makedirs(
        self,
        path,
        mode,
        side_effect=None,
        name="fs.rmtree",
        before=None,
        instead=None,
    ):
        call = FsCall(
            "os.makedirs",
            call_kwargs={"path": path, "mode": mode},
            side_effect=side_effect,
        )
        self.__calls.place(name, call, before, instead)