Add PEP8 check and fix related issues
- Add PEP8 section to tox.ini - Add hacking to requirements to enforce OpenStack style requirements - Fix formatting issues flagged by flake8 check - Add copyright notices to all remaining files - Update .gitignore file Change-Id: I8133009ef5db8e98bb4aa00dbdd36d837eabe84f
This commit is contained in:
parent
2230eb0f15
commit
c5b313c297
5
.gitignore
vendored
5
.gitignore
vendored
@ -52,3 +52,8 @@ coverage.xml
|
|||||||
# Sphinx documentation
|
# Sphinx documentation
|
||||||
docs/_build/
|
docs/_build/
|
||||||
|
|
||||||
|
# IDE Project Files
|
||||||
|
*.project
|
||||||
|
*.pydev*
|
||||||
|
*.idea
|
||||||
|
|
||||||
|
@ -27,13 +27,13 @@ def now():
|
|||||||
|
|
||||||
def dt_to_decimal(utc):
|
def dt_to_decimal(utc):
|
||||||
decimal.getcontext().prec = 30
|
decimal.getcontext().prec = 30
|
||||||
return decimal.Decimal(str(calendar.timegm(utc.utctimetuple()))) + \
|
return (decimal.Decimal(str(calendar.timegm(utc.utctimetuple()))) +
|
||||||
(decimal.Decimal(str(utc.microsecond)) /
|
(decimal.Decimal(str(utc.microsecond)) / decimal.Decimal(
|
||||||
decimal.Decimal("1000000.0"))
|
"1000000.0")))
|
||||||
|
|
||||||
|
|
||||||
def dt_from_decimal(dec):
|
def dt_from_decimal(dec):
|
||||||
if dec == None:
|
if dec is None:
|
||||||
return "n/a"
|
return "n/a"
|
||||||
integer = int(dec)
|
integer = int(dec)
|
||||||
micro = (dec - decimal.Decimal(integer)) * decimal.Decimal(1000000)
|
micro = (dec - decimal.Decimal(integer)) * decimal.Decimal(1000000)
|
||||||
|
@ -1 +1,2 @@
|
|||||||
|
hacking>=0.10.0,<0.11
|
||||||
dateutils
|
dateutils
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
# Copyright (c) 2014 Dark Secret Software Inc.
|
||||||
|
# Copyright (c) 2015 Rackspace
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import decimal
|
import decimal
|
||||||
import unittest
|
import unittest
|
||||||
@ -22,7 +38,7 @@ class TestUtils(unittest.TestCase):
|
|||||||
def test_handle_datetime_offset(self):
|
def test_handle_datetime_offset(self):
|
||||||
now = datetime.datetime(day=1, month=2, year=2014,
|
now = datetime.datetime(day=1, month=2, year=2014,
|
||||||
hour=10, minute=11, second=12,
|
hour=10, minute=11, second=12,
|
||||||
tzinfo=dateutil.tz.tzoffset(None, 4*60*60))
|
tzinfo=dateutil.tz.tzoffset(None, 4 * 60 * 60))
|
||||||
self.assertEqual("1391220672", self.handler.default(now))
|
self.assertEqual("1391220672", self.handler.default(now))
|
||||||
|
|
||||||
|
|
||||||
@ -35,9 +51,10 @@ class TestDatetimeToDecimal(unittest.TestCase):
|
|||||||
|
|
||||||
def test_decimal_to_datetime(self):
|
def test_decimal_to_datetime(self):
|
||||||
expected_decimal = decimal.Decimal('1356093296.123')
|
expected_decimal = decimal.Decimal('1356093296.123')
|
||||||
expected_datetime = datetime.datetime.utcfromtimestamp(expected_decimal)
|
expected_datetime = datetime.datetime.utcfromtimestamp(
|
||||||
|
expected_decimal)
|
||||||
actual_datetime = notification_utils.dt_from_decimal(expected_decimal)
|
actual_datetime = notification_utils.dt_from_decimal(expected_decimal)
|
||||||
self.assertEqual(actual_datetime, expected_datetime)
|
self.assertEqual(actual_datetime, expected_datetime)
|
||||||
|
|
||||||
def test_dt_from_decimal_none(self):
|
def test_dt_from_decimal_none(self):
|
||||||
self.assertEqual("n/a",notification_utils.dt_from_decimal(None))
|
self.assertEqual("n/a", notification_utils.dt_from_decimal(None))
|
||||||
|
11
tox.ini
11
tox.ini
@ -1,5 +1,5 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist = py26, py27
|
envlist = py26, py27, pep8
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
deps =
|
deps =
|
||||||
@ -12,3 +12,12 @@ commands =
|
|||||||
nosetests tests
|
nosetests tests
|
||||||
|
|
||||||
sitepackages = False
|
sitepackages = False
|
||||||
|
|
||||||
|
[testenv:pep8]
|
||||||
|
commands =
|
||||||
|
flake8
|
||||||
|
|
||||||
|
[flake8]
|
||||||
|
ignore =
|
||||||
|
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,*db/__init__.py,*db/migrations/versions/*_.py
|
||||||
|
show-source = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user