Exemple #1
0
 def now(self, tz=_missing, strip_tzinfo=True):
     # We can't automatically fast-forward because some tests require us to
     # stay on the same day for a while, e.g. autorespond.txt.
     if tz is _missing:
         tz = utc
     # Storm cannot yet handle datetimes with tz suffixes.  Assume we're
     # using UTC datetimes everywhere, so set the tzinfo to None.  This
     # does *not* change the actual time values.  LP: #280708
     tz_now = (self.predictable_now
               if layers.is_testing() else datetime.datetime.now(tz))
     return (tz_now.replace(tzinfo=None) if strip_tzinfo else tz_now)
Exemple #2
0
 def new(self):
     """Return a new unique ID or a predictable one if in testing mode."""
     if layers.is_testing():
         # When in testing mode we want to produce predictable ids, but we
         # need to coordinate this among separate processes.  We could use
         # the database, but I don't want to add schema just to handle this
         # case, and besides transactions could get aborted, causing some
         # ids to be recycled.  So we'll use a data file with a lock.  This
         # may still not be ideal due to race conditions, but I think the
         # tests will be serialized enough (and the ids reset between
         # tests) that it will not be a problem.  Maybe.
         return self._next_predictable_id()
     return self._next_unpredictable_id()
Exemple #3
0
 def new(self):
     """Return a new unique ID or a predictable one if in testing mode."""
     if layers.is_testing():
         # When in testing mode we want to produce predictable ids, but we
         # need to coordinate this among separate processes.  We could use
         # the database, but I don't want to add schema just to handle this
         # case, and besides transactions could get aborted, causing some
         # ids to be recycled.  So we'll use a data file with a lock.  This
         # may still not be ideal due to race conditions, but I think the
         # tests will be serialized enough (and the ids reset between
         # tests) that it will not be a problem.  Maybe.
         return self._next_predictable_id()
     return self._next_unpredictable_id()
Exemple #4
0
 def now(self, tz=_missing, strip_tzinfo=True):
     # We can't automatically fast-forward because some tests require us to
     # stay on the same day for a while, e.g. autorespond.txt.
     if tz is _missing:
         tz = utc
     # Storm cannot yet handle datetimes with tz suffixes.  Assume we're
     # using UTC datetimes everywhere, so set the tzinfo to None.  This
     # does *not* change the actual time values.  LP: #280708
     tz_now = (self.predictable_now
               if layers.is_testing()
               else datetime.datetime.now(tz))
     return (tz_now.replace(tzinfo=None)
             if strip_tzinfo
             else tz_now)
Exemple #5
0
    def new_uid(self):
        """Return a new UID.

        :return: The new uid
        :rtype: int
        """
        if layers.is_testing():
            # When in testing mode we want to produce predictable id, but we
            # need to coordinate this among separate processes.  We could use
            # the database, but I don't want to add schema just to handle this
            # case, and besides transactions could get aborted, causing some
            # ids to be recycled.  So we'll use a data file with a lock.  This
            # may still not be ideal due to race conditions, but I think the
            # tests will be serialized enough (and the ids reset between
            # tests) that it will not be a problem.  Maybe.
            return self._next_uid()
        while True:
            uid = uuid.uuid4()
            try:
                UID.record(uid)
            except ValueError:
                pass
            else:
                return uid
Exemple #6
0
    def new_uid(self):
        """Return a new UID.

        :return: The new uid
        :rtype: int
        """
        if layers.is_testing():
            # When in testing mode we want to produce predictable id, but we
            # need to coordinate this among separate processes.  We could use
            # the database, but I don't want to add schema just to handle this
            # case, and besides transactions could get aborted, causing some
            # ids to be recycled.  So we'll use a data file with a lock.  This
            # may still not be ideal due to race conditions, but I think the
            # tests will be serialized enough (and the ids reset between
            # tests) that it will not be a problem.  Maybe.
            return self._next_uid()
        while True:
            uid = uuid.uuid4()
            try:
                UID.record(uid)
            except ValueError:
                pass
            else:
                return uid
Exemple #7
0
 def today(self):
     return (self.predictable_today
             if layers.is_testing()
             else datetime.date.today())
Exemple #8
0
 def today(self):
     return (self.predictable_today
             if layers.is_testing()
             else datetime.date.today())