Patchwork [in,crew] test-command-template.t: fix test so it all year

login
register
mail settings
Submitter Augie Fackler
Date Jan. 1, 2013, 3:53 a.m.
Message ID <9916d104c485e744dad5.1357012430@imladris.local>
Download mbox | patch
Permalink /patch/339/
State Accepted
Commit 24f5bec1601fb2a0fe5dbfa18588435dc4eb2bda
Headers show

Comments

Augie Fackler - Jan. 1, 2013, 3:53 a.m.
# HG changeset patch
# User Augie Fackler <raf at durin42.com>
# Date 1357012235 21600
# Node ID 9916d104c485e744dad50d63398d540f429e0caa
# Parent  e6c5e009246955f5c7ff042a195923bda46b2430
test-command-template.t: fix test so it all year

This test started failing for me after midnight UTC on December
31st. Fixed it by specifying a date 7 years in the future more
precisely (rather than just adding 8 to the year and specifying
January 1st), which allows the test to pass both now and on 2012-12-01
at the same time.
Augie Fackler - Jan. 1, 2013, 3:54 a.m.
On Dec 31, 2012, at 10:53 PM, Augie Fackler <raf at durin42.com> wrote:

> test-command-template.t: fix test so it all year

Swing and a miss at writing my native language. That said, this should fix the buildbot.
Julien Cristau - Jan. 2, 2013, 11:40 a.m.
Hi,

On Mon, Dec 31, 2012 at 21:53:50 -0600, Augie Fackler wrote:

> # HG changeset patch
> # User Augie Fackler <raf at durin42.com>
> # Date 1357012235 21600
> # Node ID 9916d104c485e744dad50d63398d540f429e0caa
> # Parent  e6c5e009246955f5c7ff042a195923bda46b2430
> test-command-template.t: fix test so it all year
> 
> This test started failing for me after midnight UTC on December
> 31st. Fixed it by specifying a date 7 years in the future more
> precisely (rather than just adding 8 to the year and specifying
> January 1st), which allows the test to pass both now and on 2012-12-01
> at the same time.
> 
> diff --git a/tests/test-command-template.t b/tests/test-command-template.t
> --- a/tests/test-command-template.t
> +++ b/tests/test-command-template.t
> @@ -1348,7 +1348,8 @@
>  
>    >>> from datetime import datetime
>    >>> fp = open('a', 'w')
> -  >>> fp.write(str(datetime.now().year + 8) + '-01-01 00:00')
> +  >>> n = datetime.now()
> +  >>> fp.write('%d-%d-%d 00:00' % ((n.year + 7), n.month, n.day))

I think this will break on February 29th, because n.year+7 won't be a
leap year and you'll set an invalid date.

$ hg commit -m future -d '2013-02-29 00:00'
abort: invalid date: '2013-02-29 00:00'

Cheers,
Julien

>    >>> fp.close()
>    $ hg add a
>    $ hg commit -m future -d "`cat a`"
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -1348,7 +1348,8 @@ 
 
   >>> from datetime import datetime
   >>> fp = open('a', 'w')
-  >>> fp.write(str(datetime.now().year + 8) + '-01-01 00:00')
+  >>> n = datetime.now()
+  >>> fp.write('%d-%d-%d 00:00' % ((n.year + 7), n.month, n.day))
   >>> fp.close()
   $ hg add a
   $ hg commit -m future -d "`cat a`"