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