4 # Copyright 2016 RIFT.IO Inc
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
26 import tornado
.platform
.asyncio
27 import tornado
.testing
32 import rift
.tasklets
.rwmonparam
.aggregator
as aggregator
35 from gi
.repository
import VnfrYang
37 logger
= logging
.getLogger("mon_params_test.py")
40 class TestAggregator(unittest
.TestCase
):
42 def test_int_aggregator(self
):
43 int_agg
= aggregator
.IntValueAggregator("SUM", [1, 2, 3])
44 self
.assertEqual(int_agg
.aggregate(), ("value_integer", 6))
46 int_agg
= aggregator
.IntValueAggregator("AVERAGE", [1, 2, 3])
47 self
.assertEqual(int_agg
.aggregate(), ("value_integer", 2))
49 int_agg
= aggregator
.IntValueAggregator("MAXIMUM", [1, 2, 3])
50 self
.assertEqual(int_agg
.aggregate(), ("value_integer", 3))
52 int_agg
= aggregator
.IntValueAggregator("MINIMUM", [1, 2, 3])
53 self
.assertEqual(int_agg
.aggregate(), ("value_integer", 1))
55 int_agg
= aggregator
.IntValueAggregator("COUNT", [1, 2, 3])
56 self
.assertEqual(int_agg
.aggregate(), ("value_integer", 3))
58 def test_decimal_aggregator(self
):
59 int_agg
= aggregator
.DecimalValueAggregator("SUM", [1.1, 2, 3])
60 self
.assertEqual(int_agg
.aggregate(), ("value_decimal", 6.1))
62 int_agg
= aggregator
.DecimalValueAggregator("AVERAGE", [1, 2, 3])
63 self
.assertEqual(int_agg
.aggregate(), ("value_decimal", 2.0))
65 int_agg
= aggregator
.DecimalValueAggregator("MAXIMUM", [1, 2, 3.3])
66 self
.assertEqual(int_agg
.aggregate(), ("value_decimal", 3.3))
68 int_agg
= aggregator
.DecimalValueAggregator("MINIMUM", [1.1, 2, 3.3])
69 self
.assertEqual(int_agg
.aggregate(), ("value_decimal", 1.1))
71 int_agg
= aggregator
.DecimalValueAggregator("COUNT", [1.1, 2, 3.3])
72 self
.assertEqual(int_agg
.aggregate(), ("value_decimal", 3))
75 def main(argv
=sys
.argv
[1:]):
77 # The unittest framework requires a program name, so use the name of this
78 # file instead (we do not want to have to pass a fake program name to main
79 # when this is called from the interpreter).
81 argv
=[__file__
] + argv
,
82 testRunner
=xmlrunner
.XMLTestRunner(output
=os
.environ
["RIFT_MODULE_TEST"])
85 if __name__
== '__main__':