diff --git a/.gitignore b/.gitignore index 51cbe85..bba402f 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,8 @@ coverage.xml # Sphinx documentation docs/_build/ +# IDE Project Files +*.project +*.pydev* +*.idea + diff --git a/notification_utils/__init__.py b/notification_utils/__init__.py index 862ce44..f0acefb 100644 --- a/notification_utils/__init__.py +++ b/notification_utils/__init__.py @@ -27,13 +27,13 @@ def now(): def dt_to_decimal(utc): decimal.getcontext().prec = 30 - return decimal.Decimal(str(calendar.timegm(utc.utctimetuple()))) + \ - (decimal.Decimal(str(utc.microsecond)) / - decimal.Decimal("1000000.0")) + return (decimal.Decimal(str(calendar.timegm(utc.utctimetuple()))) + + (decimal.Decimal(str(utc.microsecond)) / decimal.Decimal( + "1000000.0"))) def dt_from_decimal(dec): - if dec == None: + if dec is None: return "n/a" integer = int(dec) micro = (dec - decimal.Decimal(integer)) * decimal.Decimal(1000000) diff --git a/requirements.txt b/requirements.txt index 80ab0c7..b72e6ee 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ +hacking>=0.10.0,<0.11 dateutils diff --git a/tests/test_utils.py b/tests/test_utils.py index caab86e..a6fe323 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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 decimal import unittest @@ -22,7 +38,7 @@ class TestUtils(unittest.TestCase): def test_handle_datetime_offset(self): now = datetime.datetime(day=1, month=2, year=2014, 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)) @@ -35,9 +51,10 @@ class TestDatetimeToDecimal(unittest.TestCase): def test_decimal_to_datetime(self): 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) self.assertEqual(actual_datetime, expected_datetime) 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)) diff --git a/tox.ini b/tox.ini index 495df0b..6a662f1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py26, py27 +envlist = py26, py27, pep8 [testenv] deps = @@ -12,3 +12,12 @@ commands = nosetests tests 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