Fix PEP257 issues
This commit is contained in:
1 parent
d6eab03a61
commit
9838697d2b
120 files changed
+1447
-1297
No files matched your search
@@ -1,4 +1,4 @@
|
||||
"""Tests Home Assistant color util methods."""
|
||||
"""Test Home Assistant color util methods."""
|
||||
import unittest
|
||||
import homeassistant.util.color as color_util
|
||||
|
||||
|
||||
+21
-21
@@ -1,9 +1,4 @@
|
||||
"""
|
||||
tests.util.test_dt
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Tests Home Assistant date util methods.
|
||||
"""
|
||||
"""Test Home Assistant date util methods."""
|
||||
# pylint: disable=too-many-public-methods
|
||||
import unittest
|
||||
from datetime import datetime, timedelta
|
||||
@@ -14,29 +9,31 @@ TEST_TIME_ZONE = 'America/Los_Angeles'
|
||||
|
||||
|
||||
class TestDateUtil(unittest.TestCase):
|
||||
""" Tests util date methods. """
|
||||
"""Test util date methods."""
|
||||
|
||||
def setUp(self):
|
||||
"""Setup the tests."""
|
||||
self.orig_default_time_zone = dt_util.DEFAULT_TIME_ZONE
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
dt_util.set_default_time_zone(self.orig_default_time_zone)
|
||||
|
||||
def test_get_time_zone_retrieves_valid_time_zone(self):
|
||||
""" Test getting a time zone. """
|
||||
"""Test getting a time zone."""
|
||||
time_zone = dt_util.get_time_zone(TEST_TIME_ZONE)
|
||||
|
||||
self.assertIsNotNone(time_zone)
|
||||
self.assertEqual(TEST_TIME_ZONE, time_zone.zone)
|
||||
|
||||
def test_get_time_zone_returns_none_for_garbage_time_zone(self):
|
||||
""" Test getting a non existing time zone. """
|
||||
"""Test getting a non existing time zone."""
|
||||
time_zone = dt_util.get_time_zone("Non existing time zone")
|
||||
|
||||
self.assertIsNone(time_zone)
|
||||
|
||||
def test_set_default_time_zone(self):
|
||||
""" Test setting default time zone. """
|
||||
"""Test setting default time zone."""
|
||||
time_zone = dt_util.get_time_zone(TEST_TIME_ZONE)
|
||||
|
||||
dt_util.set_default_time_zone(time_zone)
|
||||
@@ -45,14 +42,14 @@ class TestDateUtil(unittest.TestCase):
|
||||
self.assertEqual(time_zone.zone, dt_util.now().tzinfo.zone)
|
||||
|
||||
def test_utcnow(self):
|
||||
""" Test the UTC now method. """
|
||||
"""Test the UTC now method."""
|
||||
self.assertAlmostEqual(
|
||||
dt_util.utcnow().replace(tzinfo=None),
|
||||
datetime.utcnow(),
|
||||
delta=timedelta(seconds=1))
|
||||
|
||||
def test_now(self):
|
||||
""" Test the now method. """
|
||||
"""Test the now method."""
|
||||
dt_util.set_default_time_zone(dt_util.get_time_zone(TEST_TIME_ZONE))
|
||||
|
||||
self.assertAlmostEqual(
|
||||
@@ -61,39 +58,41 @@ class TestDateUtil(unittest.TestCase):
|
||||
delta=timedelta(seconds=1))
|
||||
|
||||
def test_as_utc_with_naive_object(self):
|
||||
"""Test the now method."""
|
||||
utcnow = datetime.utcnow()
|
||||
|
||||
self.assertEqual(utcnow,
|
||||
dt_util.as_utc(utcnow).replace(tzinfo=None))
|
||||
|
||||
def test_as_utc_with_utc_object(self):
|
||||
"""Test UTC time with UTC object."""
|
||||
utcnow = dt_util.utcnow()
|
||||
|
||||
self.assertEqual(utcnow, dt_util.as_utc(utcnow))
|
||||
|
||||
def test_as_utc_with_local_object(self):
|
||||
"""Test the UTC time with local object."""
|
||||
dt_util.set_default_time_zone(dt_util.get_time_zone(TEST_TIME_ZONE))
|
||||
|
||||
localnow = dt_util.now()
|
||||
|
||||
utcnow = dt_util.as_utc(localnow)
|
||||
|
||||
self.assertEqual(localnow, utcnow)
|
||||
self.assertNotEqual(localnow.tzinfo, utcnow.tzinfo)
|
||||
|
||||
def test_as_local_with_naive_object(self):
|
||||
"""Test local time with native object."""
|
||||
now = dt_util.now()
|
||||
|
||||
self.assertAlmostEqual(
|
||||
now, dt_util.as_local(datetime.utcnow()),
|
||||
delta=timedelta(seconds=1))
|
||||
|
||||
def test_as_local_with_local_object(self):
|
||||
"""Test local with local object."""
|
||||
now = dt_util.now()
|
||||
|
||||
self.assertEqual(now, now)
|
||||
|
||||
def test_as_local_with_utc_object(self):
|
||||
"""Test local time with UTC object."""
|
||||
dt_util.set_default_time_zone(dt_util.get_time_zone(TEST_TIME_ZONE))
|
||||
|
||||
utcnow = dt_util.utcnow()
|
||||
@@ -103,34 +102,35 @@ class TestDateUtil(unittest.TestCase):
|
||||
self.assertNotEqual(localnow.tzinfo, utcnow.tzinfo)
|
||||
|
||||
def test_utc_from_timestamp(self):
|
||||
""" Test utc_from_timestamp method. """
|
||||
"""Test utc_from_timestamp method."""
|
||||
self.assertEqual(
|
||||
datetime(1986, 7, 9, tzinfo=dt_util.UTC),
|
||||
dt_util.utc_from_timestamp(521251200))
|
||||
|
||||
def test_datetime_to_str(self):
|
||||
""" Test datetime_to_str. """
|
||||
"""Test datetime_to_str."""
|
||||
self.assertEqual(
|
||||
"12:00:00 09-07-1986",
|
||||
dt_util.datetime_to_str(datetime(1986, 7, 9, 12, 0, 0)))
|
||||
|
||||
def test_datetime_to_local_str(self):
|
||||
""" Test datetime_to_local_str. """
|
||||
"""Test datetime_to_local_str."""
|
||||
self.assertEqual(
|
||||
dt_util.datetime_to_str(dt_util.now()),
|
||||
dt_util.datetime_to_local_str(dt_util.utcnow()))
|
||||
|
||||
def test_str_to_datetime_converts_correctly(self):
|
||||
""" Test str_to_datetime converts strings. """
|
||||
"""Test str_to_datetime converts strings."""
|
||||
self.assertEqual(
|
||||
datetime(1986, 7, 9, 12, 0, 0, tzinfo=dt_util.UTC),
|
||||
dt_util.str_to_datetime("12:00:00 09-07-1986"))
|
||||
|
||||
def test_str_to_datetime_returns_none_for_incorrect_format(self):
|
||||
""" Test str_to_datetime returns None if incorrect format. """
|
||||
"""Test str_to_datetime returns None if incorrect format."""
|
||||
self.assertIsNone(dt_util.str_to_datetime("not a datetime string"))
|
||||
|
||||
def test_strip_microseconds(self):
|
||||
"""Test the now method."""
|
||||
test_time = datetime(2015, 1, 1, microsecond=5000)
|
||||
|
||||
self.assertNotEqual(0, test_time.microsecond)
|
||||
|
||||
+26
-19
@@ -1,9 +1,4 @@
|
||||
"""
|
||||
tests.util.test_init
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Tests Home Assistant util methods.
|
||||
"""
|
||||
"""Test Home Assistant util methods."""
|
||||
# pylint: disable=too-many-public-methods
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
@@ -14,9 +9,10 @@ import homeassistant.util.dt as dt_util
|
||||
|
||||
|
||||
class TestUtil(unittest.TestCase):
|
||||
""" Tests util methods. """
|
||||
"""Test util methods."""
|
||||
|
||||
def test_sanitize_filename(self):
|
||||
""" Test sanitize_filename. """
|
||||
"""Test sanitize_filename."""
|
||||
self.assertEqual("test", util.sanitize_filename("test"))
|
||||
self.assertEqual("test", util.sanitize_filename("/test"))
|
||||
self.assertEqual("test", util.sanitize_filename("..test"))
|
||||
@@ -24,20 +20,20 @@ class TestUtil(unittest.TestCase):
|
||||
self.assertEqual("test", util.sanitize_filename("\\../test"))
|
||||
|
||||
def test_sanitize_path(self):
|
||||
""" Test sanitize_path. """
|
||||
"""Test sanitize_path."""
|
||||
self.assertEqual("test/path", util.sanitize_path("test/path"))
|
||||
self.assertEqual("test/path", util.sanitize_path("~test/path"))
|
||||
self.assertEqual("//test/path",
|
||||
util.sanitize_path("~/../test/path"))
|
||||
|
||||
def test_slugify(self):
|
||||
""" Test slugify. """
|
||||
"""Test slugify."""
|
||||
self.assertEqual("test", util.slugify("T-!@#$!#@$!$est"))
|
||||
self.assertEqual("test_more", util.slugify("Test More"))
|
||||
self.assertEqual("test_more", util.slugify("Test_(More)"))
|
||||
|
||||
def test_repr_helper(self):
|
||||
""" Test repr_helper. """
|
||||
"""Test repr_helper."""
|
||||
self.assertEqual("A", util.repr_helper("A"))
|
||||
self.assertEqual("5", util.repr_helper(5))
|
||||
self.assertEqual("True", util.repr_helper(True))
|
||||
@@ -47,7 +43,7 @@ class TestUtil(unittest.TestCase):
|
||||
util.repr_helper(datetime(1986, 7, 9, 12, 0, 0)))
|
||||
|
||||
def test_convert(self):
|
||||
""" Test convert. """
|
||||
"""Test convert."""
|
||||
self.assertEqual(5, util.convert("5", int))
|
||||
self.assertEqual(5.0, util.convert("5", float))
|
||||
self.assertEqual(True, util.convert("True", bool))
|
||||
@@ -56,7 +52,7 @@ class TestUtil(unittest.TestCase):
|
||||
self.assertEqual(1, util.convert(object, int, 1))
|
||||
|
||||
def test_ensure_unique_string(self):
|
||||
""" Test ensure_unique_string. """
|
||||
"""Test ensure_unique_string."""
|
||||
self.assertEqual(
|
||||
"Beer_3",
|
||||
util.ensure_unique_string("Beer", ["Beer", "Beer_2"]))
|
||||
@@ -65,10 +61,10 @@ class TestUtil(unittest.TestCase):
|
||||
util.ensure_unique_string("Beer", ["Wine", "Soda"]))
|
||||
|
||||
def test_ordered_enum(self):
|
||||
""" Test the ordered enum class. """
|
||||
"""Test the ordered enum class."""
|
||||
|
||||
class TestEnum(util.OrderedEnum):
|
||||
""" Test enum that can be ordered. """
|
||||
"""Test enum that can be ordered."""
|
||||
FIRST = 1
|
||||
SECOND = 2
|
||||
THIRD = 3
|
||||
@@ -104,6 +100,7 @@ class TestUtil(unittest.TestCase):
|
||||
lambda x, y: x >= y, TestEnum.FIRST, 1)
|
||||
|
||||
def test_ordered_set(self):
|
||||
"""Test ordering of set."""
|
||||
set1 = util.OrderedSet([1, 2, 3, 4])
|
||||
set2 = util.OrderedSet([3, 4, 5])
|
||||
|
||||
@@ -164,7 +161,7 @@ class TestUtil(unittest.TestCase):
|
||||
self.assertEqual([2, 3, 1, 5, 6], set1)
|
||||
|
||||
def test_throttle(self):
|
||||
""" Test the add cooldown decorator. """
|
||||
"""Test the add cooldown decorator."""
|
||||
calls1 = []
|
||||
calls2 = []
|
||||
|
||||
@@ -216,21 +213,27 @@ class TestUtil(unittest.TestCase):
|
||||
self.assertEqual(2, len(calls2))
|
||||
|
||||
def test_throttle_per_instance(self):
|
||||
""" Test that the throttle method is done per instance of a class. """
|
||||
"""Test that the throttle method is done per instance of a class."""
|
||||
|
||||
class Tester(object):
|
||||
"""A tester class for the throttle."""
|
||||
|
||||
@util.Throttle(timedelta(seconds=1))
|
||||
def hello(self):
|
||||
"""Test the throttle."""
|
||||
return True
|
||||
|
||||
self.assertTrue(Tester().hello())
|
||||
self.assertTrue(Tester().hello())
|
||||
|
||||
def test_throttle_on_method(self):
|
||||
""" Test that throttle works when wrapping a method. """
|
||||
"""Test that throttle works when wrapping a method."""
|
||||
|
||||
class Tester(object):
|
||||
"""A tester class for the throttle."""
|
||||
|
||||
def hello(self):
|
||||
"""Test the throttle."""
|
||||
return True
|
||||
|
||||
tester = Tester()
|
||||
@@ -240,15 +243,19 @@ class TestUtil(unittest.TestCase):
|
||||
self.assertIsNone(throttled())
|
||||
|
||||
def test_throttle_on_two_method(self):
|
||||
""" Test that throttle works when wrapping two methods. """
|
||||
"""Test that throttle works when wrapping two methods."""
|
||||
|
||||
class Tester(object):
|
||||
"""A test class for the throttle."""
|
||||
|
||||
@util.Throttle(timedelta(seconds=1))
|
||||
def hello(self):
|
||||
"""Test the throttle."""
|
||||
return True
|
||||
|
||||
@util.Throttle(timedelta(seconds=1))
|
||||
def goodbye(self):
|
||||
"""Test the throttle."""
|
||||
return True
|
||||
|
||||
tester = Tester()
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
"""
|
||||
tests.util.test_packages
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Tests Home Assistant package util methods.
|
||||
"""
|
||||
"""Test Home Assistant package util methods."""
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
@@ -21,26 +16,26 @@ TEST_ZIP_REQ = 'file://{}#{}' \
|
||||
|
||||
|
||||
class TestPackageUtil(unittest.TestCase):
|
||||
""" Tests for homeassistant.util.package module. """
|
||||
"""Test for homeassistant.util.package module."""
|
||||
|
||||
def setUp(self):
|
||||
""" Create local library for testing. """
|
||||
"""Create local library for testing."""
|
||||
self.tmp_dir = tempfile.TemporaryDirectory()
|
||||
self.lib_dir = os.path.join(self.tmp_dir.name, 'lib')
|
||||
|
||||
def tearDown(self):
|
||||
""" Remove local library. """
|
||||
"""Stop everything that was started."""
|
||||
self.tmp_dir.cleanup()
|
||||
|
||||
def test_install_existing_package(self):
|
||||
""" Test an install attempt on an existing package. """
|
||||
"""Test an install attempt on an existing package."""
|
||||
self.assertTrue(package.check_package_exists(
|
||||
TEST_EXIST_REQ, self.lib_dir))
|
||||
|
||||
self.assertTrue(package.install_package(TEST_EXIST_REQ))
|
||||
|
||||
def test_install_package_zip(self):
|
||||
""" Test an install attempt from a zip path. """
|
||||
"""Test an install attempt from a zip path."""
|
||||
self.assertFalse(package.check_package_exists(
|
||||
TEST_ZIP_REQ, self.lib_dir))
|
||||
self.assertFalse(package.check_package_exists(
|
||||
|
||||
Reference in new issue
Block a user