src
PhysicsTools
HeppyCore
python
statistics
counter_test.py
Go to the documentation of this file.
1
from
__future__
import
absolute_import
2
import
unittest
3
import
os
4
import
shutil
5
6
from
.counter
import
Counter
7
8
class
CounterTestCase
(unittest.TestCase):
9
10
def
test_simple
(self):
11
c =
Counter
(
'Test'
)
12
c.register(
'a'
)
13
c.register(
'b'
)
14
c.inc(
'a'
)
15
self.assertEqual(c[
'a'
], [
'a'
, 1])
16
self.assertEqual(c[
'b'
], [
'b'
, 0])
17
c.inc(
'a'
)
18
self.assertEqual(c[
'a'
], [
'a'
, 2])
19
20
def
test_add
(self):
21
c =
Counter
(
'Test'
)
22
c.register(
'a'
)
23
c.register(
'b'
)
24
c.inc(
'a'
)
25
d =
Counter
(
'Test'
)
26
d.register(
'a'
)
27
d.register(
'b'
)
28
d.inc(
'a'
)
29
d.inc(
'b'
)
30
d += c
31
self.assertEqual(d[
'a'
], [
'a'
, 2])
32
self.assertEqual(d[
'b'
], [
'b'
, 1])
33
34
def
test_bad_add
(self):
35
c =
Counter
(
'Test'
)
36
c.register(
'a'
)
37
c.register(
'b'
)
38
c.inc(
'a'
)
39
d =
Counter
(
'Test'
)
40
d.register(
'b'
)
41
self.assertRaises(ValueError, d.__iadd__, c)
42
43
def
test_write
(self):
44
c =
Counter
(
'Test'
)
45
c.register(
'a'
)
46
c.register(
'b'
)
47
c.inc(
'a'
)
48
dirname =
'test_dir'
49
if
os.path.exists(dirname):
50
shutil.rmtree(dirname)
51
os.mkdir(dirname)
52
c.write(dirname)
53
shutil.rmtree(dirname)
54
55
56
57
58
59
60
if
__name__ ==
'__main__'
:
61
unittest.main()
counter_test.CounterTestCase
Definition:
counter_test.py:8
counter_test.CounterTestCase.test_bad_add
def test_bad_add(self)
Definition:
counter_test.py:34
counter_test.CounterTestCase.test_simple
def test_simple(self)
Definition:
counter_test.py:10
counter.Counter
Definition:
counter.py:8
counter_test.CounterTestCase.test_add
def test_add(self)
Definition:
counter_test.py:20
counter_test.CounterTestCase.test_write
def test_write(self)
Definition:
counter_test.py:43
Generated for CMSSW Reference Manual by
1.8.14