Patchwork [2,of,2] test-encoding: rewrite utf8b fuzz testing as python inlines

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 9, 2015, 2:41 p.m.
Message ID <67bc69088f4fd921e9bc.1447080080@mimosa>
Download mbox | patch
Permalink /patch/11335/
State Rejected
Delegated to: Pierre-Yves David
Headers show

Comments

Yuya Nishihara - Nov. 9, 2015, 2:41 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1447076944 -32400
#      Mon Nov 09 22:49:04 2015 +0900
# Node ID 67bc69088f4fd921e9bc2353524ec0b2c61eb4bd
# Parent  a7e586cc8587d3e4a0bbf607d5b902a988cb5bc8
test-encoding: rewrite utf8b fuzz testing as python inlines

We generally prefer putting a test code and its result in the same file.
Pierre-Yves David - Nov. 16, 2015, 9:56 p.m.
On 11/09/2015 06:41 AM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1447076944 -32400
> #      Mon Nov 09 22:49:04 2015 +0900
> # Node ID 67bc69088f4fd921e9bc2353524ec0b2c61eb4bd
> # Parent  a7e586cc8587d3e4a0bbf607d5b902a988cb5bc8
> test-encoding: rewrite utf8b fuzz testing as python inlines
>
> We generally prefer putting a test code and its result in the same file.

I'm not sure about this patch, the idea is to make it easy to do 
roundtrip testing in other tests. Sure the code is small but it still 
seems to make sense to factorize the function for maintainance purpose.

What do you think?
Yuya Nishihara - Nov. 17, 2015, 1:38 p.m.
On Mon, 16 Nov 2015 13:56:39 -0800, Pierre-Yves David wrote:
> On 11/09/2015 06:41 AM, Yuya Nishihara wrote:
> > # HG changeset patch
> > # User Yuya Nishihara <yuya@tcha.org>
> > # Date 1447076944 -32400
> > #      Mon Nov 09 22:49:04 2015 +0900
> > # Node ID 67bc69088f4fd921e9bc2353524ec0b2c61eb4bd
> > # Parent  a7e586cc8587d3e4a0bbf607d5b902a988cb5bc8
> > test-encoding: rewrite utf8b fuzz testing as python inlines
> >
> > We generally prefer putting a test code and its result in the same file.
> 
> I'm not sure about this patch, the idea is to make it easy to do 
> roundtrip testing in other tests. Sure the code is small but it still 
> seems to make sense to factorize the function for maintainance purpose.
> 
> What do you think?

Got it. Please disregard this.

Patch

diff --git a/tests/hypothesishelpers.py b/tests/hypothesishelpers.py
--- a/tests/hypothesishelpers.py
+++ b/tests/hypothesishelpers.py
@@ -32,29 +32,6 @@  def check(*args, **kwargs):
             sys.exit(1)
     return accept
 
-
-def roundtrips(data, decode, encode):
-    """helper to tests function that must do proper encode/decode roundtripping
-    """
-    @given(data)
-    def testroundtrips(value):
-        encoded = encode(value)
-        decoded = decode(encoded)
-        if decoded != value:
-            raise ValueError(
-                "Round trip failed: %s(%r) -> %s(%r) -> %r" % (
-                    encode.__name__, value, decode.__name__, encoded,
-                    decoded
-                ))
-    try:
-        testroundtrips()
-    except Exception:
-        # heredoc swallow traceback, we work around it
-        traceback.print_exc(file=sys.stdout)
-        raise
-    print("Round trip OK")
-
-
 # strategy for generating bytestring that might be an issue for Mercurial
 bytestrings = (
     st.builds(lambda s, e: s.encode(e), st.text(), st.sampled_from([
diff --git a/tests/test-encoding.t b/tests/test-encoding.t
--- a/tests/test-encoding.t
+++ b/tests/test-encoding.t
@@ -279,7 +279,11 @@  Test roundtrip encoding/decoding of utf8
 
   >>> from hypothesishelpers import *
   >>> from mercurial import encoding
-  >>> roundtrips(st.binary(), encoding.fromutf8b, encoding.toutf8b)
-  Round trip OK
+  >>> @check(st.binary())
+  ... def roundtrips(val):
+  ...     enc = encoding.toutf8b(val)
+  ...     dec = encoding.fromutf8b(enc)
+  ...     assert dec == val, ('round trip failed: %r -> %r -> %r'
+  ...                         % (val, enc, dec))
 
 #endif