ยปCore Development>Code coverage>Doc/includes/test.py

Python code coverage for Doc/includes/test.py

#countcontent
1n/a"""Test module for the noddy examples
2n/a
3n/aNoddy 1:
4n/a
5n/a>>> import noddy
6n/a>>> n1 = noddy.Noddy()
7n/a>>> n2 = noddy.Noddy()
8n/a>>> del n1
9n/a>>> del n2
10n/a
11n/a
12n/aNoddy 2
13n/a
14n/a>>> import noddy2
15n/a>>> n1 = noddy2.Noddy('jim', 'fulton', 42)
16n/a>>> n1.first
17n/a'jim'
18n/a>>> n1.last
19n/a'fulton'
20n/a>>> n1.number
21n/a42
22n/a>>> n1.name()
23n/a'jim fulton'
24n/a>>> n1.first = 'will'
25n/a>>> n1.name()
26n/a'will fulton'
27n/a>>> n1.last = 'tell'
28n/a>>> n1.name()
29n/a'will tell'
30n/a>>> del n1.first
31n/a>>> n1.name()
32n/aTraceback (most recent call last):
33n/a...
34n/aAttributeError: first
35n/a>>> n1.first
36n/aTraceback (most recent call last):
37n/a...
38n/aAttributeError: first
39n/a>>> n1.first = 'drew'
40n/a>>> n1.first
41n/a'drew'
42n/a>>> del n1.number
43n/aTraceback (most recent call last):
44n/a...
45n/aTypeError: can't delete numeric/char attribute
46n/a>>> n1.number=2
47n/a>>> n1.number
48n/a2
49n/a>>> n1.first = 42
50n/a>>> n1.name()
51n/a'42 tell'
52n/a>>> n2 = noddy2.Noddy()
53n/a>>> n2.name()
54n/a' '
55n/a>>> n2.first
56n/a''
57n/a>>> n2.last
58n/a''
59n/a>>> del n2.first
60n/a>>> n2.first
61n/aTraceback (most recent call last):
62n/a...
63n/aAttributeError: first
64n/a>>> n2.first
65n/aTraceback (most recent call last):
66n/a...
67n/aAttributeError: first
68n/a>>> n2.name()
69n/aTraceback (most recent call last):
70n/a File "<stdin>", line 1, in ?
71n/aAttributeError: first
72n/a>>> n2.number
73n/a0
74n/a>>> n3 = noddy2.Noddy('jim', 'fulton', 'waaa')
75n/aTraceback (most recent call last):
76n/a File "<stdin>", line 1, in ?
77n/aTypeError: an integer is required
78n/a>>> del n1
79n/a>>> del n2
80n/a
81n/a
82n/aNoddy 3
83n/a
84n/a>>> import noddy3
85n/a>>> n1 = noddy3.Noddy('jim', 'fulton', 42)
86n/a>>> n1 = noddy3.Noddy('jim', 'fulton', 42)
87n/a>>> n1.name()
88n/a'jim fulton'
89n/a>>> del n1.first
90n/aTraceback (most recent call last):
91n/a File "<stdin>", line 1, in ?
92n/aTypeError: Cannot delete the first attribute
93n/a>>> n1.first = 42
94n/aTraceback (most recent call last):
95n/a File "<stdin>", line 1, in ?
96n/aTypeError: The first attribute value must be a string
97n/a>>> n1.first = 'will'
98n/a>>> n1.name()
99n/a'will fulton'
100n/a>>> n2 = noddy3.Noddy()
101n/a>>> n2 = noddy3.Noddy()
102n/a>>> n2 = noddy3.Noddy()
103n/a>>> n3 = noddy3.Noddy('jim', 'fulton', 'waaa')
104n/aTraceback (most recent call last):
105n/a File "<stdin>", line 1, in ?
106n/aTypeError: an integer is required
107n/a>>> del n1
108n/a>>> del n2
109n/a
110n/aNoddy 4
111n/a
112n/a>>> import noddy4
113n/a>>> n1 = noddy4.Noddy('jim', 'fulton', 42)
114n/a>>> n1.first
115n/a'jim'
116n/a>>> n1.last
117n/a'fulton'
118n/a>>> n1.number
119n/a42
120n/a>>> n1.name()
121n/a'jim fulton'
122n/a>>> n1.first = 'will'
123n/a>>> n1.name()
124n/a'will fulton'
125n/a>>> n1.last = 'tell'
126n/a>>> n1.name()
127n/a'will tell'
128n/a>>> del n1.first
129n/a>>> n1.name()
130n/aTraceback (most recent call last):
131n/a...
132n/aAttributeError: first
133n/a>>> n1.first
134n/aTraceback (most recent call last):
135n/a...
136n/aAttributeError: first
137n/a>>> n1.first = 'drew'
138n/a>>> n1.first
139n/a'drew'
140n/a>>> del n1.number
141n/aTraceback (most recent call last):
142n/a...
143n/aTypeError: can't delete numeric/char attribute
144n/a>>> n1.number=2
145n/a>>> n1.number
146n/a2
147n/a>>> n1.first = 42
148n/a>>> n1.name()
149n/a'42 tell'
150n/a>>> n2 = noddy4.Noddy()
151n/a>>> n2 = noddy4.Noddy()
152n/a>>> n2 = noddy4.Noddy()
153n/a>>> n2 = noddy4.Noddy()
154n/a>>> n2.name()
155n/a' '
156n/a>>> n2.first
157n/a''
158n/a>>> n2.last
159n/a''
160n/a>>> del n2.first
161n/a>>> n2.first
162n/aTraceback (most recent call last):
163n/a...
164n/aAttributeError: first
165n/a>>> n2.first
166n/aTraceback (most recent call last):
167n/a...
168n/aAttributeError: first
169n/a>>> n2.name()
170n/aTraceback (most recent call last):
171n/a File "<stdin>", line 1, in ?
172n/aAttributeError: first
173n/a>>> n2.number
174n/a0
175n/a>>> n3 = noddy4.Noddy('jim', 'fulton', 'waaa')
176n/aTraceback (most recent call last):
177n/a File "<stdin>", line 1, in ?
178n/aTypeError: an integer is required
179n/a
180n/a
181n/aTest cyclic gc(?)
182n/a
183n/a>>> import gc
184n/a>>> gc.disable()
185n/a
186n/a>>> x = []
187n/a>>> l = [x]
188n/a>>> n2.first = l
189n/a>>> n2.first
190n/a[[]]
191n/a>>> l.append(n2)
192n/a>>> del l
193n/a>>> del n1
194n/a>>> del n2
195n/a>>> sys.getrefcount(x)
196n/a3
197n/a>>> ignore = gc.collect()
198n/a>>> sys.getrefcount(x)
199n/a2
200n/a
201n/a>>> gc.enable()
202n/a"""
203n/a
204n/aimport os
205n/aimport sys
206n/afrom distutils.util import get_platform
207n/aPLAT_SPEC = "%s-%d.%d" % (get_platform(), *sys.version_info[:2])
208n/asrc = os.path.join("build", "lib.%s" % PLAT_SPEC)
209n/asys.path.append(src)
210n/a
211n/aif __name__ == "__main__":
212n/a import doctest, __main__
213n/a doctest.testmod(__main__)