Skip to content

Commit

Permalink
Merge pull request #61529 from thoughtpolice/nixpkgs/pypy3-fix-funcsigs
Browse files Browse the repository at this point in the history
pythonPackages.funcsigs: fix tests on pypy3
  • Loading branch information
thoughtpolice authored May 15, 2019
2 parents b72daf7 + dd79d60 commit b0c2352
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkgs/development/python-modules/funcsigs/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ stdenv, buildPythonPackage, fetchPypi
, unittest2 }:
, isPyPy, isPy3k, unittest2
}:

buildPythonPackage rec {
pname = "funcsigs";
Expand All @@ -12,6 +13,9 @@ buildPythonPackage rec {

buildInputs = [ unittest2 ];

# https://github.com/testing-cabal/funcsigs/issues/10
patches = stdenv.lib.optional (isPyPy && isPy3k) [ ./fix-pypy3-tests.patch ];

meta = with stdenv.lib; {
description = "Python function signatures from PEP362 for Python 2.6, 2.7 and 3.2+";
homepage = https://github.com/aliles/funcsigs;
Expand Down
94 changes: 94 additions & 0 deletions pkgs/development/python-modules/funcsigs/fix-pypy3-tests.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
diff --git a/tests/test_inspect.py b/tests/test_inspect.py
index 98d6592..3a2a1f2 100644
--- a/tests/test_inspect.py
+++ b/tests/test_inspect.py
@@ -8,6 +8,7 @@ import unittest2 as unittest

import funcsigs as inspect

+import platform

class TestSignatureObject(unittest.TestCase):
@staticmethod
@@ -409,7 +410,7 @@ def test_signature_on_decorated(self):
Ellipsis))
""")

- if sys.version_info[0] > 2:
+ if sys.version_info[0] > 2 and platform.python_implementation() != "PyPy":
exec("""
def test_signature_on_class(self):
class C:
@@ -493,41 +494,44 @@ def test_signature_on_class(self):
Ellipsis))
""")

- def test_signature_on_callable_objects(self):
- class Foo(object):
- def __call__(self, a):
- pass
+ if platform.python_implementation() != "PyPy":
+ exec("""
+def test_signature_on_callable_objects(self):
+ class Foo(object):
+ def __call__(self, a):
+ pass

- self.assertEqual(self.signature(Foo()),
- ((('a', Ellipsis, Ellipsis, "positional_or_keyword"),),
- Ellipsis))
+ self.assertEqual(self.signature(Foo()),
+ ((('a', Ellipsis, Ellipsis, "positional_or_keyword"),),
+ Ellipsis))

- class Spam(object):
- pass
- with self.assertRaisesRegex(TypeError, "is not a callable object"):
- inspect.signature(Spam())
+ class Spam(object):
+ pass
+ with self.assertRaisesRegex(TypeError, "is not a callable object"):
+ inspect.signature(Spam())

- class Bar(Spam, Foo):
- pass
+ class Bar(Spam, Foo):
+ pass

- self.assertEqual(self.signature(Bar()),
- ((('a', Ellipsis, Ellipsis, "positional_or_keyword"),),
- Ellipsis))
+ self.assertEqual(self.signature(Bar()),
+ ((('a', Ellipsis, Ellipsis, "positional_or_keyword"),),
+ Ellipsis))

- class ToFail(object):
- __call__ = type
- with self.assertRaisesRegex(ValueError, "not supported by signature"):
- inspect.signature(ToFail())
+ class ToFail(object):
+ __call__ = type
+ with self.assertRaisesRegex(ValueError, "not supported by signature"):
+ inspect.signature(ToFail())

- if sys.version_info[0] < 3:
- return
+ if sys.version_info[0] < 3:
+ return

- class Wrapped(object):
- pass
- Wrapped.__wrapped__ = lambda a: None
- self.assertEqual(self.signature(Wrapped),
- ((('a', Ellipsis, Ellipsis, "positional_or_keyword"),),
- Ellipsis))
+ class Wrapped(object):
+ pass
+ Wrapped.__wrapped__ = lambda a: None
+ self.assertEqual(self.signature(Wrapped),
+ ((('a', Ellipsis, Ellipsis, "positional_or_keyword"),),
+ Ellipsis))
+""")

def test_signature_on_lambdas(self):
self.assertEqual(self.signature((lambda a=10: a)),

0 comments on commit b0c2352

Please sign in to comment.