aodh/ceilometer/tests/api/v2/test_statistics.py
Martin Geisler d7054053ae Remove (c) and remove unnecessary encoding lines
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
2014-05-31 13:02:21 +02:00

114 lines
4.3 KiB
Python

#
# Copyright 2012 New Dream Network, LLC (DreamHost)
#
# Author: Doug Hellmann <doug.hellmann@dreamhost.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.
"""Test statistics objects."""
import datetime
from ceilometer.api.controllers import v2
from ceilometer.openstack.common import test
class TestStatisticsDuration(test.BaseTestCase):
def setUp(self):
super(TestStatisticsDuration, self).setUp()
# Create events relative to the range and pretend
# that the intervening events exist.
self.early1 = datetime.datetime(2012, 8, 27, 7, 0)
self.early2 = datetime.datetime(2012, 8, 27, 17, 0)
self.start = datetime.datetime(2012, 8, 28, 0, 0)
self.middle1 = datetime.datetime(2012, 8, 28, 8, 0)
self.middle2 = datetime.datetime(2012, 8, 28, 18, 0)
self.end = datetime.datetime(2012, 8, 28, 23, 59)
self.late1 = datetime.datetime(2012, 8, 29, 9, 0)
self.late2 = datetime.datetime(2012, 8, 29, 19, 0)
def test_nulls(self):
s = v2.Statistics(duration_start=None,
duration_end=None,
start_timestamp=None,
end_timestamp=None,
)
self.assertIsNone(s.duration_start)
self.assertIsNone(s.duration_end)
self.assertIsNone(s.duration)
def test_overlap_range_start(self):
s = v2.Statistics(duration_start=self.early1,
duration_end=self.middle1,
start_timestamp=self.start,
end_timestamp=self.end,
)
self.assertEqual(self.start, s.duration_start)
self.assertEqual(self.middle1, s.duration_end)
self.assertEqual(8 * 60 * 60, s.duration)
def test_within_range(self):
s = v2.Statistics(duration_start=self.middle1,
duration_end=self.middle2,
start_timestamp=self.start,
end_timestamp=self.end,
)
self.assertEqual(self.middle1, s.duration_start)
self.assertEqual(self.middle2, s.duration_end)
self.assertEqual(10 * 60 * 60, s.duration)
def test_within_range_zero_duration(self):
s = v2.Statistics(duration_start=self.middle1,
duration_end=self.middle1,
start_timestamp=self.start,
end_timestamp=self.end,
)
self.assertEqual(self.middle1, s.duration_start)
self.assertEqual(self.middle1, s.duration_end)
self.assertEqual(0, s.duration)
def test_overlap_range_end(self):
s = v2.Statistics(duration_start=self.middle2,
duration_end=self.late1,
start_timestamp=self.start,
end_timestamp=self.end,
)
self.assertEqual(self.middle2, s.duration_start)
self.assertEqual(self.end, s.duration_end)
self.assertEqual(((6 * 60) - 1) * 60, s.duration)
def test_after_range(self):
s = v2.Statistics(duration_start=self.late1,
duration_end=self.late2,
start_timestamp=self.start,
end_timestamp=self.end,
)
self.assertIsNone(s.duration_start)
self.assertIsNone(s.duration_end)
self.assertIsNone(s.duration)
def test_without_timestamp(self):
s = v2.Statistics(duration_start=self.late1,
duration_end=self.late2,
start_timestamp=None,
end_timestamp=None,
)
self.assertEqual(self.late1, s.duration_start)
self.assertEqual(self.late2, s.duration_end)