d7054053ae
The word "Copyright" alone is sufficient to claim copyright, the (c) symbol need not be present.[1] As per PEP 263, a Python file with non-ASCII characters must have a line with "coding: <some-encoding>". Python files containing only 7-bit ASCII characters need no such line.[2] This commit removes unnecessary Unicode copyright symbols and unnecessary encoding lines. [1]: http://www.copyright.gov/circs/circ03.pdf [2]: http://legacy.python.org/dev/peps/pep-0263/ Closes-Bug: #1324686 Change-Id: Id381ea1f029a0cfddd3773c6d9f16c47842d9c33
118 lines
4.3 KiB
Python
118 lines
4.3 KiB
Python
#
|
|
# Copyright 2013 Rackspace Hosting.
|
|
#
|
|
# Author: Monsyne Dragon <mdragon@rackspace.com>
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
from ceilometer.event import trait_plugins
|
|
from ceilometer.openstack.common import test
|
|
|
|
|
|
class TestSplitterPlugin(test.BaseTestCase):
|
|
|
|
def setUp(self):
|
|
super(TestSplitterPlugin, self).setUp()
|
|
self.pclass = trait_plugins.SplitterTraitPlugin
|
|
|
|
def test_split(self):
|
|
param = dict(separator='-', segment=0)
|
|
plugin = self.pclass(**param)
|
|
match_list = [('test.thing', 'test-foobar-baz')]
|
|
value = plugin.trait_value(match_list)
|
|
self.assertEqual('test', value)
|
|
|
|
param = dict(separator='-', segment=1)
|
|
plugin = self.pclass(**param)
|
|
match_list = [('test.thing', 'test-foobar-baz')]
|
|
value = plugin.trait_value(match_list)
|
|
self.assertEqual('foobar', value)
|
|
|
|
param = dict(separator='-', segment=1, max_split=1)
|
|
plugin = self.pclass(**param)
|
|
match_list = [('test.thing', 'test-foobar-baz')]
|
|
value = plugin.trait_value(match_list)
|
|
self.assertEqual('foobar-baz', value)
|
|
|
|
def test_no_sep(self):
|
|
param = dict(separator='-', segment=0)
|
|
plugin = self.pclass(**param)
|
|
match_list = [('test.thing', 'test.foobar.baz')]
|
|
value = plugin.trait_value(match_list)
|
|
self.assertEqual('test.foobar.baz', value)
|
|
|
|
def test_no_segment(self):
|
|
param = dict(separator='-', segment=5)
|
|
plugin = self.pclass(**param)
|
|
match_list = [('test.thing', 'test-foobar-baz')]
|
|
value = plugin.trait_value(match_list)
|
|
self.assertIs(None, value)
|
|
|
|
def test_no_match(self):
|
|
param = dict(separator='-', segment=0)
|
|
plugin = self.pclass(**param)
|
|
match_list = []
|
|
value = plugin.trait_value(match_list)
|
|
self.assertIs(None, value)
|
|
|
|
|
|
class TestBitfieldPlugin(test.BaseTestCase):
|
|
|
|
def setUp(self):
|
|
super(TestBitfieldPlugin, self).setUp()
|
|
self.pclass = trait_plugins.BitfieldTraitPlugin
|
|
self.init = 0
|
|
self.params = dict(initial_bitfield=self.init,
|
|
flags=[dict(path='payload.foo', bit=0, value=42),
|
|
dict(path='payload.foo', bit=1, value=12),
|
|
dict(path='payload.thud', bit=1, value=23),
|
|
dict(path='thingy.boink', bit=4),
|
|
dict(path='thingy.quux', bit=6,
|
|
value="wokka"),
|
|
dict(path='payload.bar', bit=10,
|
|
value='test')])
|
|
|
|
def test_bitfield(self):
|
|
match_list = [('payload.foo', 12),
|
|
('payload.bar', 'test'),
|
|
('thingy.boink', 'testagain')]
|
|
|
|
plugin = self.pclass(**self.params)
|
|
value = plugin.trait_value(match_list)
|
|
self.assertEqual(0x412, value)
|
|
|
|
def test_initial(self):
|
|
match_list = [('payload.foo', 12),
|
|
('payload.bar', 'test'),
|
|
('thingy.boink', 'testagain')]
|
|
self.params['initial_bitfield'] = 0x2000
|
|
plugin = self.pclass(**self.params)
|
|
value = plugin.trait_value(match_list)
|
|
self.assertEqual(0x2412, value)
|
|
|
|
def test_no_match(self):
|
|
match_list = []
|
|
plugin = self.pclass(**self.params)
|
|
value = plugin.trait_value(match_list)
|
|
self.assertEqual(self.init, value)
|
|
|
|
def test_multi(self):
|
|
match_list = [('payload.foo', 12),
|
|
('payload.thud', 23),
|
|
('payload.bar', 'test'),
|
|
('thingy.boink', 'testagain')]
|
|
|
|
plugin = self.pclass(**self.params)
|
|
value = plugin.trait_value(match_list)
|
|
self.assertEqual(0x412, value)
|