File: test_mutables.py

package info (click to toggle)
gaupol 1.15-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,112 kB
  • sloc: python: 18,822; sh: 98; makefile: 79
file content (181 lines) | stat: -rw-r--r-- 4,331 bytes parent folder | download | duplicates (6)
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# -*- coding: utf-8 -*-

# Copyright (C) 2006 Osmo Salomaa
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import aeidon
import copy


class PuppetMaster:

    def __init__(self):
        self.count = 0

    def notify(self, name):
        self.count += 1


class _TestObservable(aeidon.TestCase):

    def edit_obs(self):
        raise NotImplementedError

    def setup_method(self, method):
        self.master = PuppetMaster()
        self.obs = None

    def teardown_method(self, method):
        if method.__name__ in self.__class__.__dict__:
            assert self.master.count == 1

    def test___copy__(self):
        obs_copy = copy.copy(self.obs)
        assert obs_copy == self.obs
        assert obs_copy.master is self.obs.master
        self.edit_obs()
        assert obs_copy != self.obs
        assert obs_copy.master is self.obs.master

    def test___deepcopy__(self):
        obs_copy = copy.deepcopy(self.obs)
        assert obs_copy == self.obs
        assert obs_copy.master is self.obs.master
        self.edit_obs()
        assert obs_copy != self.obs
        assert obs_copy.master is self.obs.master


class TestObservableDict(_TestObservable):

    def edit_obs(self):
        del self.obs[1]

    def setup_method(self, method):
        _TestObservable.setup_method(self, method)
        self.obs = aeidon.ObservableDict({1:1, 2:2}, self.master, "")

    def test___delitem__(self):
        del self.obs[1]

    def test___setitem__(self):
        self.obs[1] = 2

    def test_clear(self):
        self.obs.clear()

    def test_pop(self):
        self.obs.pop(1)

    def test_popitem(self):
        self.obs.popitem()

    def test_setdefault(self):
        self.obs.setdefault(1, 2)

    def test_update(self):
        self.obs.update({1:2, 3:3})


class TestObservableList(_TestObservable):

    def edit_obs(self):
        self.obs.pop()

    def setup_method(self, method):
        _TestObservable.setup_method(self, method)
        self.obs = aeidon.ObservableList((1, 2, 3), self.master, "")

    def test___delitem__(self):
        del self.obs[0]

    def test___iadd__(self):
        self.obs += (4, 5)

    def test___imul__(self):
        self.obs *= 2

    def test___setitem__(self):
        self.obs[0] = 2

    def test_append(self):
        self.obs.append(4)

    def test_extend(self):
        self.obs.extend((4, 5))

    def test_insert(self):
        self.obs.insert(0, 0)

    def test_pop(self):
        self.obs.pop()

    def test_remove(self):
        self.obs.remove(1)

    def test_reverse(self):
        self.obs.reverse()

    def test_sort(self):
        self.obs.sort()


class TestObservableSet(_TestObservable):

    def edit_obs(self):
        self.obs.pop()

    def setup_method(self, method):
        _TestObservable.setup_method(self, method)
        self.obs = aeidon.ObservableSet((1, 2, 3), self.master, "")

    def test___iand__(self):
        self.obs &= set((1, 2))

    def test___ior__(self):
        self.obs |= set((1, 2))

    def test___isub__(self):
        self.obs -= set((1, 2))

    def test___ixor__(self):
        self.obs ^= set((1, 2))

    def test_add(self):
        self.obs.add(4)

    def test_clear(self):
        self.obs.clear()

    def test_difference_update(self):
        self.obs.difference_update(set((1, 2)))

    def test_discard(self):
        self.obs.discard(1)

    def test_intersection_update(self):
        self.obs.intersection_update(set((1, 2)))

    def test_pop(self):
        self.obs.pop()

    def test_remove(self):
        self.obs.remove(1)

    def test_symmetric_difference_update(self):
        self.obs.symmetric_difference_update(set((1, 2)))

    def test_update(self):
        self.obs.update(set((4, 5)))