Esempio n. 1
0
    def test_switching(self):
        orig_datetime = datetime.datetime

        class derived_datetime(datetime.datetime):
            pass

        assert issubclass(datetime_tz.datetime_tz, orig_datetime)
        assert issubclass(datetime_tz.datetime_tz, datetime.datetime)
        assert issubclass(derived_datetime, orig_datetime)
        assert issubclass(derived_datetime, datetime.datetime)
        virtualtime.enable()

        class derived_datetime2(datetime.datetime):
            pass

        assert issubclass(datetime_tz.datetime_tz, orig_datetime)
        assert issubclass(datetime_tz.datetime_tz, datetime.datetime)
        assert issubclass(derived_datetime, orig_datetime)
        assert issubclass(derived_datetime, datetime.datetime)
        assert issubclass(derived_datetime2, orig_datetime)
        assert issubclass(derived_datetime2, datetime.datetime)
        virtualtime.disable()
        assert issubclass(datetime_tz.datetime_tz, orig_datetime)
        assert issubclass(datetime_tz.datetime_tz, datetime.datetime)
        assert issubclass(derived_datetime, orig_datetime)
        assert issubclass(derived_datetime, datetime.datetime)
        assert issubclass(derived_datetime2, orig_datetime)
        assert issubclass(derived_datetime2, datetime.datetime)
Esempio n. 2
0
 def test_switching_values(self):
     now = datetime_tz.datetime_tz.now()
     assert isinstance(now, datetime.datetime)
     assert isinstance(now, datetime_tz.datetime_tz)
     later = now + datetime.timedelta(hours=1)
     assert isinstance(later, datetime.datetime)
     assert isinstance(later, datetime_tz.datetime_tz)
     start = datetime.datetime.combine(now.date(), now.time())
     assert isinstance(start, datetime.datetime)
     local_start = datetime_tz.localize(start)
     assert local_start == now
     assert isinstance(local_start, datetime_tz.datetime_tz)
     start_tz = datetime_tz.datetime_tz.combine(now.date(), now.time(),
                                                datetime_tz.localtz())
     assert isinstance(start_tz, datetime_tz.datetime_tz)
     local_start_tz = datetime_tz.localize(start_tz)
     assert local_start_tz == now
     assert isinstance(local_start_tz, datetime_tz.datetime_tz)
     assert isinstance(datetime_tz.datetime_tz.min, datetime_tz.datetime_tz)
     assert isinstance(datetime_tz.datetime_tz.max, datetime_tz.datetime_tz)
     virtualtime.enable()
     now = datetime_tz.datetime_tz.now()
     assert isinstance(now, datetime.datetime)
     assert isinstance(now, datetime_tz.datetime_tz)
     later = now + datetime.timedelta(hours=1)
     assert isinstance(later, datetime.datetime)
     assert isinstance(later, datetime_tz.datetime_tz)
     start = datetime.datetime.combine(now.date(), now.time())
     assert isinstance(start, datetime.datetime)
     local_start = datetime_tz.localize(start)
     assert local_start == now
     assert isinstance(local_start, datetime_tz.datetime_tz)
     start_tz = datetime_tz.datetime_tz.combine(now.date(), now.time(),
                                                datetime_tz.localtz())
     assert isinstance(start_tz, datetime_tz.datetime_tz)
     local_start_tz = datetime_tz.localize(start_tz)
     assert local_start_tz == now
     assert isinstance(local_start_tz, datetime_tz.datetime_tz)
     assert isinstance(datetime_tz.datetime_tz.min, datetime_tz.datetime_tz)
     assert isinstance(datetime_tz.datetime_tz.max, datetime_tz.datetime_tz)
Esempio n. 3
0
 def test_switching_values(self):
     now = datetime_tz.datetime_tz.now()
     assert isinstance(now, datetime.datetime)
     assert isinstance(now, datetime_tz.datetime_tz)
     later = now + datetime.timedelta(hours=1)
     assert isinstance(later, datetime.datetime)
     assert isinstance(later, datetime_tz.datetime_tz)
     start = datetime.datetime.combine(now.date(), now.time())
     assert isinstance(start, datetime.datetime)
     local_start = datetime_tz.localize(start)
     assert local_start == now
     assert isinstance(local_start, datetime_tz.datetime_tz)
     start_tz = datetime_tz.datetime_tz.combine(now.date(), now.time(), datetime_tz.localtz())
     assert isinstance(start_tz, datetime_tz.datetime_tz)
     local_start_tz = datetime_tz.localize(start_tz)
     assert local_start_tz == now
     assert isinstance(local_start_tz, datetime_tz.datetime_tz)
     assert isinstance(datetime_tz.datetime_tz.min, datetime_tz.datetime_tz)
     assert isinstance(datetime_tz.datetime_tz.max, datetime_tz.datetime_tz)
     virtualtime.enable()
     now = datetime_tz.datetime_tz.now()
     assert isinstance(now, datetime.datetime)
     assert isinstance(now, datetime_tz.datetime_tz)
     later = now + datetime.timedelta(hours=1)
     assert isinstance(later, datetime.datetime)
     assert isinstance(later, datetime_tz.datetime_tz)
     start = datetime.datetime.combine(now.date(), now.time())
     assert isinstance(start, datetime.datetime)
     local_start = datetime_tz.localize(start)
     assert local_start == now
     assert isinstance(local_start, datetime_tz.datetime_tz)
     start_tz = datetime_tz.datetime_tz.combine(now.date(), now.time(), datetime_tz.localtz())
     assert isinstance(start_tz, datetime_tz.datetime_tz)
     local_start_tz = datetime_tz.localize(start_tz)
     assert local_start_tz == now
     assert isinstance(local_start_tz, datetime_tz.datetime_tz)
     assert isinstance(datetime_tz.datetime_tz.min, datetime_tz.datetime_tz)
     assert isinstance(datetime_tz.datetime_tz.max, datetime_tz.datetime_tz)
Esempio n. 4
0
 def test_switching(self):
     orig_datetime = datetime.datetime
     class derived_datetime(datetime.datetime):
         pass
     assert issubclass(datetime_tz.datetime_tz, orig_datetime)
     assert issubclass(datetime_tz.datetime_tz, datetime.datetime)
     assert issubclass(derived_datetime, orig_datetime)
     assert issubclass(derived_datetime, datetime.datetime)
     virtualtime.enable()
     class derived_datetime2(datetime.datetime):
         pass
     assert issubclass(datetime_tz.datetime_tz, orig_datetime)
     assert issubclass(datetime_tz.datetime_tz, datetime.datetime)
     assert issubclass(derived_datetime, orig_datetime)
     assert issubclass(derived_datetime, datetime.datetime)
     assert issubclass(derived_datetime2, orig_datetime)
     assert issubclass(derived_datetime2, datetime.datetime)
     virtualtime.disable()
     assert issubclass(datetime_tz.datetime_tz, orig_datetime)
     assert issubclass(datetime_tz.datetime_tz, datetime.datetime)
     assert issubclass(derived_datetime, orig_datetime)
     assert issubclass(derived_datetime, datetime.datetime)
     assert issubclass(derived_datetime2, orig_datetime)
     assert issubclass(derived_datetime2, datetime.datetime)
Esempio n. 5
0
 def setup(self):
     virtualtime.enable()
     datetime.datetime.localtz_override = pytz.timezone("America/Chicago")
     patch_vt_module()
     test_datetime_tz.patch_datetime_module()
Esempio n. 6
0
 def test_enabled(self):
     virtualtime.enable()
     assert issubclass(datetime_tz.datetime_tz, datetime.datetime)
Esempio n. 7
0
 def setup_class(cls):
     """Ensure that virtualtime is disabled before, then enabled when running these tests"""
     assert not virtualtime.enabled()
     virtualtime.enable()
     cls.virtual_time_enabled = virtualtime.enabled()
     assert cls.virtual_time_enabled
Esempio n. 8
0
 def setup(self):
     virtualtime.enable()
     datetime.datetime.localtz_override = pytz.timezone("America/Chicago")
     patch_vt_module()
     test_datetime_tz.patch_datetime_module()
Esempio n. 9
0
 def test_enabled(self):
     virtualtime.enable()
     assert issubclass(datetime_tz.datetime_tz, datetime.datetime)
Esempio n. 10
0
 def setup_class(cls):
     """Ensure that virtualtime is disabled before, then enabled when running these tests"""
     assert not virtualtime.enabled()
     virtualtime.enable()
     cls.virtual_time_enabled = virtualtime.enabled()
     assert cls.virtual_time_enabled