aboutsummaryrefslogtreecommitdiffstats
path: root/selftest/rate_ctrs_test/rate_ctrs_test.py
blob: 935bd9debcfeefa0feda246ece4c2bdd6017277b (plain)
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
#!/usr/bin/env python3
import _prep

from osmo_gsm_tester.obj.osmo_ctrl import *

rc = RateCounters()
print('- empty RateCounters()' + rc.str())

rc = RateCounters('inst', 'var')
print('- initialized RateCounters, single var' + rc.str())
rc.inc('inst', 'var')
print('- incremented inst.var' + rc.str())
rc.inc('inst', 'var')
print('- incremented inst.var again' + rc.str())
rc.inc('inst', 'var', 5)
print('- incremented inst.var by 5' + rc.str())

rc = RateCounters('inst', ('foo', 'var'))
print('- initialized RateCounters, two vars' + rc.str())
rc.inc('inst', ('foo', 'var'))
print('- incremented foo and var' + rc.str())
rc.inc('inst', 'var')
print('- incremented var again' + rc.str())
rc.inc('inst', 'foo', 5)
print('- incremented foo by 5' + rc.str())

rc = RateCounters('inst', ('foo', 'var'), instances=range(3))
print('- initialized RateCounters, two vars, three instances' + rc.str())
rc.inc('inst', 'foo', instances=0)
rc.inc('inst', 'var', instances=1)
print('- incremented foo and var on separate instances' + rc.str())
rc.inc('inst', 'var', instances=2)
print('- incremented var on instance 2' + rc.str())
rc.inc('inst', 'foo', 5, instances=(1,2))
print('- incremented foo by 5 on instances 1,2' + rc.str())

rc_rel = rc.copy()
print('- copy' + rc_rel.str())
rc.inc('inst', ('foo', 'var'), 100, instances=range(3))
print('- increment two vars by 100 on all three instances' + rc.str())
rc.subtract(rc_rel)
print('- subtract original copy' + rc.str())
rc.add(rc_rel)
print('- add original copy' + rc.str())

rc.inc('inst', ('foo', 'var', 'moo'), 23, instances=range(3), kinds=('per_hour', 'per_day'))
print('- increment types per_hour, per_day by 23' + rc.str())

rc2 = rc.copy()
print('- copy' + rc2.str())
print('- match? ', (rc == rc2))
rc2.inc('inst', 'foo')
print('- increment foo' + rc2.str())
print('- match? ', (rc == rc2))

# vim: expandtab tabstop=4 shiftwidth=4