Patchwork ui: fix configwith doctest

login
register
mail settings
Submitter Jun Wu
Date Feb. 14, 2017, 5:05 a.m.
Message ID <ba4d509ef528627871e2.1487048743@localhost.localdomain>
Download mbox | patch
Permalink /patch/18468/
State Accepted
Headers show

Comments

Jun Wu - Feb. 14, 2017, 5:05 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1487048450 28800
#      Mon Feb 13 21:00:50 2017 -0800
# Node ID ba4d509ef528627871e26172fcf9cfd71c2195c4
# Parent  f2ad0d8047009e6e58ab1fa34ae7107714f5dc30
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r ba4d509ef528
ui: fix configwith doctest

4.2 cannot be expressed with IEEE floating point losslessly, and could
cause test failure on some platform:

    File ".../mercurial/ui.py", line 414, in mercurial.ui.ui.configwith
    Failed example:
        u.configwith(float, s, 'float2')
    Expected:
        -4.2
    Got:
        -4.2000000000000002

This patch fixes that by changing the number to 4.25, which can be expressed
by the binary number 100.01.
Augie Fackler - Feb. 14, 2017, 3:40 p.m.
On Mon, Feb 13, 2017 at 09:05:43PM -0800, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1487048450 28800
> #      Mon Feb 13 21:00:50 2017 -0800
> # Node ID ba4d509ef528627871e26172fcf9cfd71c2195c4
> # Parent  f2ad0d8047009e6e58ab1fa34ae7107714f5dc30
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r ba4d509ef528
> ui: fix configwith doctest

IEEE784'd! Queued, thanks.

>
> 4.2 cannot be expressed with IEEE floating point losslessly, and could
> cause test failure on some platform:
>
>     File ".../mercurial/ui.py", line 414, in mercurial.ui.ui.configwith
>     Failed example:
>         u.configwith(float, s, 'float2')
>     Expected:
>         -4.2
>     Got:
>         -4.2000000000000002
>
> This patch fixes that by changing the number to 4.25, which can be expressed
> by the binary number 100.01.
>
> diff --git a/mercurial/ui.py b/mercurial/ui.py
> --- a/mercurial/ui.py
> +++ b/mercurial/ui.py
> @@ -411,7 +411,7 @@ class ui(object):
>          >>> u.configwith(float, s, 'float1')
>          42.0
> -        >>> u.setconfig(s, 'float2', '-4.2')
> +        >>> u.setconfig(s, 'float2', '-4.25')
>          >>> u.configwith(float, s, 'float2')
> -        -4.2
> +        -4.25
>          >>> u.configwith(float, s, 'unknown', 7)
>          7
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -411,7 +411,7 @@  class ui(object):
         >>> u.configwith(float, s, 'float1')
         42.0
-        >>> u.setconfig(s, 'float2', '-4.2')
+        >>> u.setconfig(s, 'float2', '-4.25')
         >>> u.configwith(float, s, 'float2')
-        -4.2
+        -4.25
         >>> u.configwith(float, s, 'unknown', 7)
         7