blue-yonder / bonfire

A CLI Graylog Client with Follow Mode
BSD 3-Clause "New" or "Revised" License
72 stars 26 forks source link

Incompatiable with new arrow #32

Closed jonringer closed 4 years ago

jonringer commented 4 years ago

with arrow==0.15.4, the tests throw the following error:

_____________________________ test_datetime_parser _____________________________

    def test_datetime_parser():
        now = arrow.now()

        ts_tuples = [
            ("10 minutes ago", lambda x: x.replace(minutes=-10, microsecond=0, tzinfo='local')),
            ("1 day ago", lambda x: x.replace(days=-1, microsecond=0, tzinfo='local')),
            ("yesterday midnight", lambda x: x.replace(days=-1, hour=0, minute=0, second=0, microsecond=0, tzinfo='local')),
            ("1986-04-24 00:51:24+02:00", lambda x: arrow.get("1986-04-24 00:51:24+02:00")),
            ("2001-01-01 01:01:01", lambda x: arrow.get("2001-01-01 01:01:01").replace(tzinfo="local")),
            (now, lambda x: now)]

        for (s, ts) in ts_tuples:
>           assert datetime_parser(s) == ts(arrow.now())

tests/test_dateutils.py:25:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_dateutils.py:17: in <lambda>
    ("10 minutes ago", lambda x: x.replace(minutes=-10, microsecond=0, tzinfo='local')),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <Arrow [2019-12-22T18:24:15.958968+00:00]>
kwargs = {'microsecond': 0, 'minutes': -10, 'tzinfo': 'local'}
absolute_kwargs = {}, key = 'minutes', value = -10

    def replace(self, **kwargs):
        """ Returns a new :class:`Arrow <arrow.arrow.Arrow>` object with attributes updated
        according to inputs.

        Use property names to set their value absolutely::

            >>> import arrow
            >>> arw = arrow.utcnow()
            >>> arw
            <Arrow [2013-05-11T22:27:34.787885+00:00]>
            >>> arw.replace(year=2014, month=6)
            <Arrow [2014-06-11T22:27:34.787885+00:00]>

        You can also replace the timezone without conversion, using a
        :ref:`timezone expression <tz-expr>`::

            >>> arw.replace(tzinfo=tz.tzlocal())
            <Arrow [2013-05-11T22:27:34.787885-07:00]>

        """

        absolute_kwargs = {}

        for key, value in kwargs.items():

            if key in self._ATTRS:
                absolute_kwargs[key] = value
            elif key in ["week", "quarter"]:
                raise AttributeError("setting absolute {} is not supported".format(key))
            elif key != "tzinfo":
>               raise AttributeError('unknown attribute: "{}"'.format(key))
E               AttributeError: unknown attribute: "minutes"
systemcatch commented 4 years ago

arrow was changed (way before 0.15.4) to stop replace being used to shift the entire object.

This changes only the second attribute, nothing else.

arw=arrow.utcnow()
arw_later=arw.replace(second=37)

To fix your tests use the shift method which will update the entire object.

arw=arrow.utcnow()
arw_later=arw.shift(seconds=+37)

I'd recommend upping your pinned arrow versions (see changelog) if possible as 0.5.4 is very old, note that 0.15.0+ have breaking changes to do with parsing.

valentin-krasontovitsch commented 4 years ago

i think it might be fixed now - the tests pass, at least with arrow 0.15.5 - thanks for the pointers regarding the necessary changes!

My impression of the changes is that one must use replace when changing the locale and setting a value, like microsecond=0, while shift is good to use for days=+1, as you describe. but i don't claim to really get arrow... let's hope that this holds up.

will merge soon, i think, and cut a new release - which i sadly still cannot publish on pip, but hopefully that will be fixed soon as well!