Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add missing coverage tests
  • Loading branch information
skirpichev committed Nov 2, 2023
commit 6ead74be9ab94e89adaff85cc571126b5af60d49
9 changes: 9 additions & 0 deletions Lib/test/test_capi/test_complex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import warnings

from test.test_capi.test_getargs import (BadComplex, BadComplex2, Complex,
FloatSubclass, Float, BadFloat,
Expand Down Expand Up @@ -102,6 +103,10 @@ def test_asccomplex(self):
# Test PyComplex_AsCComplex()
asccomplex = _testcapi.complex_asccomplex

class BadComplex3:
def __complex__(self):
raise RuntimeError

self.assertEqual(asccomplex(1+2j), 1.0+2.0j)
self.assertEqual(asccomplex(1), 1.0+0.0j)
self.assertEqual(asccomplex(-1), -1.0+0.0j)
Expand All @@ -111,9 +116,13 @@ def test_asccomplex(self):
self.assertEqual(asccomplex(Float()), 4.25+0.0j)
with self.assertWarns(DeprecationWarning):
self.assertEqual(asccomplex(BadComplex2()), 4.25+0.5j)
with warnings.catch_warnings():
warnings.simplefilter("error", DeprecationWarning)
self.assertRaises(DeprecationWarning, asccomplex, BadComplex2())
with self.assertWarns(DeprecationWarning):
self.assertEqual(asccomplex(BadFloat2()), 4.25+0.0j)
self.assertRaises(TypeError, asccomplex, BadComplex())
self.assertRaises(RuntimeError, asccomplex, BadComplex3())
self.assertRaises(TypeError, asccomplex, BadFloat())
self.assertRaises(TypeError, asccomplex, object())
Comment thread
skirpichev marked this conversation as resolved.

Expand Down