()
| 570 | |
| 571 | |
| 572 | def test_writeable(): |
| 573 | # broadcast_to should return a readonly array |
| 574 | original = np.array([1, 2, 3]) |
| 575 | result = broadcast_to(original, (2, 3)) |
| 576 | assert_equal(result.flags.writeable, False) |
| 577 | assert_raises(ValueError, result.__setitem__, slice(None), 0) |
| 578 | |
| 579 | # but the result of broadcast_arrays needs to be writeable, to |
| 580 | # preserve backwards compatibility |
| 581 | for is_broadcast, results in [(False, broadcast_arrays(original,)), |
| 582 | (True, broadcast_arrays(0, original))]: |
| 583 | for result in results: |
| 584 | # This will change to False in a future version |
| 585 | if is_broadcast: |
| 586 | with assert_warns(FutureWarning): |
| 587 | assert_equal(result.flags.writeable, True) |
| 588 | with assert_warns(DeprecationWarning): |
| 589 | result[:] = 0 |
| 590 | # Warning not emitted, writing to the array resets it |
| 591 | assert_equal(result.flags.writeable, True) |
| 592 | else: |
| 593 | # No warning: |
| 594 | assert_equal(result.flags.writeable, True) |
| 595 | |
| 596 | for results in [broadcast_arrays(original), |
| 597 | broadcast_arrays(0, original)]: |
| 598 | for result in results: |
| 599 | # resets the warn_on_write DeprecationWarning |
| 600 | result.flags.writeable = True |
| 601 | # check: no warning emitted |
| 602 | assert_equal(result.flags.writeable, True) |
| 603 | result[:] = 0 |
| 604 | |
| 605 | # keep readonly input readonly |
| 606 | original.flags.writeable = False |
| 607 | _, result = broadcast_arrays(0, original) |
| 608 | assert_equal(result.flags.writeable, False) |
| 609 | |
| 610 | # regression test for GH6491 |
| 611 | shape = (2,) |
| 612 | strides = [0] |
| 613 | tricky_array = as_strided(np.array(0), shape, strides) |
| 614 | other = np.zeros((1,)) |
| 615 | first, second = broadcast_arrays(tricky_array, other) |
| 616 | assert_(first.shape == second.shape) |
| 617 | |
| 618 | |
| 619 | def test_writeable_memoryview(): |
nothing calls this directly
no test coverage detected