MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_constructor

Method test_constructor

Lib/test/test_complex.py:463–635  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

461
462 @unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: DeprecationWarning not triggered
463 def test_constructor(self):
464 def check(z, x, y):
465 self.assertIs(type(z), complex)
466 self.assertFloatsAreIdentical(z.real, x)
467 self.assertFloatsAreIdentical(z.imag, y)
468
469 check(complex(), 0.0, 0.0)
470 check(complex(10), 10.0, 0.0)
471 check(complex(4.25), 4.25, 0.0)
472 check(complex(4.25+0j), 4.25, 0.0)
473 check(complex(4.25+0.5j), 4.25, 0.5)
474 check(complex(ComplexSubclass(4.25+0.5j)), 4.25, 0.5)
475 check(complex(WithComplex(4.25+0.5j)), 4.25, 0.5)
476
477 check(complex(1, 10), 1.0, 10.0)
478 check(complex(1, 10.0), 1.0, 10.0)
479 check(complex(1, 4.25), 1.0, 4.25)
480 check(complex(1.0, 10), 1.0, 10.0)
481 check(complex(4.25, 10), 4.25, 10.0)
482 check(complex(1.0, 10.0), 1.0, 10.0)
483 check(complex(4.25, 0.5), 4.25, 0.5)
484
485 with self.assertWarnsRegex(DeprecationWarning,
486 "argument 'real' must be a real number, not complex"):
487 check(complex(4.25+0j, 0), 4.25, 0.0)
488 with self.assertWarnsRegex(DeprecationWarning,
489 "argument 'real' must be a real number, not .*ComplexSubclass"):
490 check(complex(ComplexSubclass(4.25+0j), 0), 4.25, 0.0)
491 with self.assertWarnsRegex(DeprecationWarning,
492 "argument 'real' must be a real number, not .*WithComplex"):
493 check(complex(WithComplex(4.25+0j), 0), 4.25, 0.0)
494 with self.assertWarnsRegex(DeprecationWarning,
495 "argument 'real' must be a real number, not complex"):
496 check(complex(4.25j, 0), 0.0, 4.25)
497 with self.assertWarnsRegex(DeprecationWarning,
498 "argument 'real' must be a real number, not complex"):
499 check(complex(0j, 4.25), 0.0, 4.25)
500 with self.assertWarnsRegex(DeprecationWarning,
501 "argument 'imag' must be a real number, not complex"):
502 check(complex(0, 4.25+0j), 0.0, 4.25)
503 with self.assertWarnsRegex(DeprecationWarning,
504 "argument 'imag' must be a real number, not .*ComplexSubclass"):
505 check(complex(0, ComplexSubclass(4.25+0j)), 0.0, 4.25)
506 with self.assertRaisesRegex(TypeError,
507 "argument 'imag' must be a real number, not .*WithComplex"):
508 complex(0, WithComplex(4.25+0j))
509 with self.assertWarnsRegex(DeprecationWarning,
510 "argument 'imag' must be a real number, not complex"):
511 check(complex(0.0, 4.25j), -4.25, 0.0)
512 with self.assertWarnsRegex(DeprecationWarning,
513 "argument 'real' must be a real number, not complex"):
514 check(complex(4.25+0j, 0j), 4.25, 0.0)
515 with self.assertWarnsRegex(DeprecationWarning,
516 "argument 'real' must be a real number, not complex"):
517 check(complex(4.25j, 0j), 0.0, 4.25)
518 with self.assertWarnsRegex(DeprecationWarning,
519 "argument 'real' must be a real number, not complex"):
520 check(complex(0j, 4.25+0j), 0.0, 4.25)

Callers

nothing calls this directly

Calls 15

ComplexSubclassClass · 0.85
WithComplexClass · 0.85
evilcomplexClass · 0.85
WithFloatClass · 0.85
WithIndexClass · 0.85
complex0Class · 0.85
complex1Class · 0.85
complex2Class · 0.85
assertWarnsRegexMethod · 0.80
assertRaisesRegexMethod · 0.80
assertWarnsMethod · 0.80
checkFunction · 0.70

Tested by

no test coverage detected