예제 #1
0
def time_zone(value):
    """Validate timezone."""
    if dt_utility.get_time_zone(value) is not None:
        return value
    raise vol.Invalid(
        "Invalid time zone passed in. Valid options can be found here: "
        "http://en.wikipedia.org/wiki/List_of_tz_database_time_zones")
예제 #2
0
    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)
예제 #3
0
    def test_set_default_time_zone(self):
        """Test setting default time zone."""
        time_zone = dt_util.get_time_zone(TEST_TIME_ZONE)

        dt_util.set_default_time_zone(time_zone)

        # We cannot compare the timezones directly because of DST
        self.assertEqual(time_zone.zone, dt_util.now().tzinfo.zone)
예제 #4
0
def time_zone(value):
    """Validate timezone."""
    if dt_utility.get_time_zone(value) is not None:
        return value
    raise vol.Invalid(
        "Invalid time zone passed in. Valid options can be found here: "
        "http://en.wikipedia.org/wiki/List_of_tz_database_time_zones"
    )
예제 #5
0
    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)
예제 #6
0
    def test_set_default_time_zone(self):
        """Test setting default time zone."""
        time_zone = dt_util.get_time_zone(TEST_TIME_ZONE)

        dt_util.set_default_time_zone(time_zone)

        # We cannot compare the timezones directly because of DST
        self.assertEqual(time_zone.zone, dt_util.now().tzinfo.zone)
예제 #7
0
    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()
        localnow = dt_util.as_local(utcnow)

        self.assertEqual(localnow, utcnow)
        self.assertNotEqual(localnow.tzinfo, utcnow.tzinfo)
예제 #8
0
    def test_now(self):
        """Test the now method."""
        dt_util.set_default_time_zone(dt_util.get_time_zone(TEST_TIME_ZONE))

        self.assertAlmostEqual(
            dt_util.as_utc(dt_util.now()).replace(tzinfo=None),
            datetime.utcnow(),
            delta=timedelta(seconds=1),
        )
예제 #9
0
    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()
        localnow = dt_util.as_local(utcnow)

        self.assertEqual(localnow, utcnow)
        self.assertNotEqual(localnow.tzinfo, utcnow.tzinfo)
예제 #10
0
    def test_now(self):
        """Test the now method."""
        dt_util.set_default_time_zone(dt_util.get_time_zone(TEST_TIME_ZONE))

        self.assertAlmostEqual(
            dt_util.as_utc(dt_util.now()).replace(tzinfo=None),
            datetime.utcnow(),
            delta=timedelta(seconds=1),
        )
예제 #11
0
def async_test_scarlett_os(loop):
    """Return a ScarlettOS object pointing at test config dir."""
    # loop._thread_ident = threading.get_ident()

    ss = s.ScarlettSystem(loop)

    ss.config.location_name = "test scarlett"
    ss.config.config_dir = get_test_config_dir()
    ss.config.latitude = 32.87336
    ss.config.longitude = -117.22743
    ss.config.elevation = 0
    ss.config.time_zone = date_utility.get_time_zone("US/Pacific")
    ss.config.units = METRIC_SYSTEM
    ss.config.skip_pip = True

    # if 'custom_automations.test' not in loader.AVAILABLE_COMPONENTS:
    #     yield from loop.run_in_executor(None, loader.prepare, ss)

    ss.state = s.CoreState.running

    return ss
예제 #12
0
    def test_get_time_zone_returns_none_for_garbage_time_zone(self):
        """Test getting a non existing time zone."""
        time_zone = dt_util.get_time_zone("Non existing time zone")

        self.assertIsNone(time_zone)
예제 #13
0
    def test_get_time_zone_retrieves_valid_time_zone(self):
        """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)
예제 #14
0
    def test_get_time_zone_returns_none_for_garbage_time_zone(self):
        """Test getting a non existing time zone."""
        time_zone = dt_util.get_time_zone("Non existing time zone")

        self.assertIsNone(time_zone)
예제 #15
0
    def test_get_time_zone_retrieves_valid_time_zone(self):
        """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)