2 new commits in pytest:

https://bitbucket.org/hpk42/pytest/commits/8a8be3def6c7/
Changeset:   8a8be3def6c7
User:        pfctdayelise
Date:        2013-05-29 04:59:47
Summary:     A couple of improvements to parametrize
- When not specifying ids, let None and bools use their native string form 
(like str, int, float) rather than obfuscated form used for objects
- When specifying ids, explicitly raise a ValueError if a different number of 
ids are specified compared to the test cases
- Add tests for both these items.
Affected #:  2 files

diff -r 5d0b6123d6541ad497cc592d72b9ed50a7c26915 -r 
8a8be3def6c70aecaca71b7dae05b14aa73eda59 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -2,6 +2,7 @@
 import py
 import inspect
 import sys
+from types import NoneType
 import pytest
 from _pytest.main import getfslineno
 from _pytest.mark import MarkDecorator, MarkInfo
@@ -705,6 +706,9 @@
                     raise ValueError("%r uses no fixture %r" %(
                                      self.function, arg))
         valtype = indirect and "params" or "funcargs"
+        if ids and len(ids) != len(argvalues):
+            raise ValueError('%d tests specified with %d ids' %(
+                             len(argvalues), len(ids)))
         if not ids:
             ids = idmaker(argnames, argvalues)
         newcalls = []
@@ -758,7 +762,7 @@
     for valindex, valset in enumerate(argvalues):
         this_id = []
         for nameindex, val in enumerate(valset):
-            if not isinstance(val, (float, int, str)):
+            if not isinstance(val, (float, int, str, bool, NoneType)):
                 this_id.append(str(argnames[nameindex])+str(valindex))
             else:
                 this_id.append(str(val))

diff -r 5d0b6123d6541ad497cc592d72b9ed50a7c26915 -r 
8a8be3def6c70aecaca71b7dae05b14aa73eda59 testing/python/metafunc.py
--- a/testing/python/metafunc.py
+++ b/testing/python/metafunc.py
@@ -95,6 +95,17 @@
         ids = [x.id for x in metafunc._calls]
         assert ids == ["basic-abc", "basic-def", "advanced-abc", 
"advanced-def"]
 
+    def test_parametrize_with_wrong_number_of_ids(self, testdir):
+        def func(x, y): pass
+        metafunc = self.Metafunc(func)
+
+        with pytest.raises(ValueError):
+            metafunc.parametrize("x", [1,2], ids=['basic'])
+
+        with pytest.raises(ValueError):
+            metafunc.parametrize(("x","y"), [("abc", "def"),
+                                             ("ghi", "jkl")], ids=["one"])
+
     def test_parametrize_with_userobjects(self):
         def func(x, y): pass
         metafunc = self.Metafunc(func)
@@ -121,6 +132,25 @@
         result = idmaker((py.builtin._totext("a"), "b"), [({}, '\xc3\xb4')])
         assert result == ['a0-\xc3\xb4']
 
+    def test_idmaker_native_strings(self):
+        from _pytest.python import idmaker
+        result = idmaker(("a", "b"), [(1.0, -1.1),
+                                      (2, -202),
+                                      ("three", "three hundred"),
+                                      (True, False),
+                                      (None, None),
+                                      (list("six"), [66, 66]),
+                                      ({7}, set("seven")),
+                                      (tuple("eight"), (8, -8, 8))
+        ])
+        assert result == ["1.0--1.1",
+                          "2--202",
+                          "three-three hundred",
+                          "True-False",
+                          "None-None",
+                          "a5-b5",
+                          "a6-b6",
+                          "a7-b7"]
 
     def test_addcall_and_parametrize(self):
         def func(x, y): pass
@@ -530,8 +560,6 @@
             *test_function*1.3-b1*
         """)
 
-
-
     @pytest.mark.parametrize(("scope", "length"),
                              [("module", 2), ("function", 4)])
     def test_parametrize_scope_overrides(self, testdir, scope, length):


https://bitbucket.org/hpk42/pytest/commits/7fd344f34e08/
Changeset:   7fd344f34e08
User:        hpk42
Date:        2013-07-16 15:30:48
Summary:     Merged in pfctdayelise/pytest (pull request #38)

A couple of improvements to parametrize
Affected #:  2 files

diff -r 5eca54d508b406369a0836f8f6422fd80a1836db -r 
7fd344f34e088e3d4a6aa47f93901c4d78153c64 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -2,6 +2,7 @@
 import py
 import inspect
 import sys
+from types import NoneType
 import pytest
 from _pytest.main import getfslineno
 from _pytest.mark import MarkDecorator, MarkInfo
@@ -709,6 +710,9 @@
                     raise ValueError("%r uses no fixture %r" %(
                                      self.function, arg))
         valtype = indirect and "params" or "funcargs"
+        if ids and len(ids) != len(argvalues):
+            raise ValueError('%d tests specified with %d ids' %(
+                             len(argvalues), len(ids)))
         if not ids:
             ids = idmaker(argnames, argvalues)
         newcalls = []
@@ -762,7 +766,7 @@
     for valindex, valset in enumerate(argvalues):
         this_id = []
         for nameindex, val in enumerate(valset):
-            if not isinstance(val, (float, int, str)):
+            if not isinstance(val, (float, int, str, bool, NoneType)):
                 this_id.append(str(argnames[nameindex])+str(valindex))
             else:
                 this_id.append(str(val))

diff -r 5eca54d508b406369a0836f8f6422fd80a1836db -r 
7fd344f34e088e3d4a6aa47f93901c4d78153c64 testing/python/metafunc.py
--- a/testing/python/metafunc.py
+++ b/testing/python/metafunc.py
@@ -95,6 +95,17 @@
         ids = [x.id for x in metafunc._calls]
         assert ids == ["basic-abc", "basic-def", "advanced-abc", 
"advanced-def"]
 
+    def test_parametrize_with_wrong_number_of_ids(self, testdir):
+        def func(x, y): pass
+        metafunc = self.Metafunc(func)
+
+        with pytest.raises(ValueError):
+            metafunc.parametrize("x", [1,2], ids=['basic'])
+
+        with pytest.raises(ValueError):
+            metafunc.parametrize(("x","y"), [("abc", "def"),
+                                             ("ghi", "jkl")], ids=["one"])
+
     def test_parametrize_with_userobjects(self):
         def func(x, y): pass
         metafunc = self.Metafunc(func)
@@ -121,6 +132,25 @@
         result = idmaker((py.builtin._totext("a"), "b"), [({}, '\xc3\xb4')])
         assert result == ['a0-\xc3\xb4']
 
+    def test_idmaker_native_strings(self):
+        from _pytest.python import idmaker
+        result = idmaker(("a", "b"), [(1.0, -1.1),
+                                      (2, -202),
+                                      ("three", "three hundred"),
+                                      (True, False),
+                                      (None, None),
+                                      (list("six"), [66, 66]),
+                                      ({7}, set("seven")),
+                                      (tuple("eight"), (8, -8, 8))
+        ])
+        assert result == ["1.0--1.1",
+                          "2--202",
+                          "three-three hundred",
+                          "True-False",
+                          "None-None",
+                          "a5-b5",
+                          "a6-b6",
+                          "a7-b7"]
 
     def test_addcall_and_parametrize(self):
         def func(x, y): pass
@@ -530,8 +560,6 @@
             *test_function*1.3-b1*
         """)
 
-
-
     @pytest.mark.parametrize(("scope", "length"),
                              [("module", 2), ("function", 4)])
     def test_parametrize_scope_overrides(self, testdir, scope, length):

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
_______________________________________________
pytest-commit mailing list
pytest-commit@python.org
http://mail.python.org/mailman/listinfo/pytest-commit

Reply via email to