Patchwork [V2] util: add doctest to datestr()

login
register
mail settings
Submitter Adrian Buehlmann
Date April 11, 2016, 5:54 p.m.
Message ID <9e883d780661cf2ef47c.1460397295@kork>
Download mbox | patch
Permalink /patch/14525/
State Accepted
Headers show

Comments

Adrian Buehlmann - April 11, 2016, 5:54 p.m.
# HG changeset patch
# User Adrian Buehlmann <adrian@cadifra.com>
# Date 1460396810 -7200
# Node ID 9e883d780661cf2ef47ca9ade115fd94f287be5b
# Parent  3819c349b1947964573e014a36c00801356d4123
util: add doctest to datestr()
Yuya Nishihara - April 12, 2016, 2:19 p.m.
On Mon, 11 Apr 2016 19:54:55 +0200, Adrian Buehlmann wrote:
> # HG changeset patch
> # User Adrian Buehlmann <adrian@cadifra.com>
> # Date 1460396810 -7200
> # Node ID 9e883d780661cf2ef47ca9ade115fd94f287be5b
> # Parent  3819c349b1947964573e014a36c00801356d4123
> util: add doctest to datestr()

Queued, thanks.

> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -1583,7 +1583,19 @@
>  def datestr(date=None, format='%a %b %d %H:%M:%S %Y %1%2'):
>      """represent a (unixtime, offset) tuple as a localized time.
>      unixtime is seconds since the epoch, and offset is the time zone's
> -    number of seconds away from UTC."""
> +    number of seconds away from UTC.
> +
> +    >>> datestr((0, 0))
> +    'Thu Jan 01 00:00:00 1970 +0000'
> +    >>> datestr((42, 0))
> +    'Thu Jan 01 00:00:42 1970 +0000'
> +    >>> datestr((-42, 0))
> +    'Wed Dec 31 23:59:18 1969 +0000'
> +    >>> datestr((0x7fffffff, 0))
> +    'Tue Jan 19 03:14:07 2038 +0000'
> +    >>> datestr((-0x7fffffff, 0))
> +    'Fri Dec 13 20:45:53 1901 +0000'

I've updated the last example to use -0x80000000 to follow up Florent's patch.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1583,7 +1583,19 @@ 
 def datestr(date=None, format='%a %b %d %H:%M:%S %Y %1%2'):
     """represent a (unixtime, offset) tuple as a localized time.
     unixtime is seconds since the epoch, and offset is the time zone's
-    number of seconds away from UTC."""
+    number of seconds away from UTC.
+
+    >>> datestr((0, 0))
+    'Thu Jan 01 00:00:00 1970 +0000'
+    >>> datestr((42, 0))
+    'Thu Jan 01 00:00:42 1970 +0000'
+    >>> datestr((-42, 0))
+    'Wed Dec 31 23:59:18 1969 +0000'
+    >>> datestr((0x7fffffff, 0))
+    'Tue Jan 19 03:14:07 2038 +0000'
+    >>> datestr((-0x7fffffff, 0))
+    'Fri Dec 13 20:45:53 1901 +0000'
+    """
     t, tz = date or makedate()
     if "%1" in format or "%2" in format or "%z" in format:
         sign = (tz > 0) and "-" or "+"