MCPcopy Create free account
hub / github.com/numpy/numpy / test_seq_repeat

Method test_seq_repeat

numpy/core/tests/test_scalarmath.py:668–698  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

666
667class TestMultiply:
668 def test_seq_repeat(self):
669 # Test that basic sequences get repeated when multiplied with
670 # numpy integers. And errors are raised when multiplied with others.
671 # Some of this behaviour may be controversial and could be open for
672 # change.
673 accepted_types = set(np.typecodes["AllInteger"])
674 deprecated_types = {'?'}
675 forbidden_types = (
676 set(np.typecodes["All"]) - accepted_types - deprecated_types)
677 forbidden_types -= {'V'} # can't default-construct void scalars
678
679 for seq_type in (list, tuple):
680 seq = seq_type([1, 2, 3])
681 for numpy_type in accepted_types:
682 i = np.dtype(numpy_type).type(2)
683 assert_equal(seq * i, seq * int(i))
684 assert_equal(i * seq, int(i) * seq)
685
686 for numpy_type in deprecated_types:
687 i = np.dtype(numpy_type).type()
688 assert_equal(
689 assert_warns(DeprecationWarning, operator.mul, seq, i),
690 seq * int(i))
691 assert_equal(
692 assert_warns(DeprecationWarning, operator.mul, i, seq),
693 int(i) * seq)
694
695 for numpy_type in forbidden_types:
696 i = np.dtype(numpy_type).type()
697 assert_raises(TypeError, operator.mul, seq, i)
698 assert_raises(TypeError, operator.mul, i, seq)
699
700 def test_no_seq_repeat_basic_array_like(self):
701 # Test that an array-like which does not know how to be multiplied

Callers

nothing calls this directly

Calls 4

assert_equalFunction · 0.90
assert_warnsFunction · 0.90
assert_raisesFunction · 0.90
dtypeMethod · 0.45

Tested by

no test coverage detected