1# test slice assignment to memoryview
2
3try:
4    memoryview(bytearray(1))[:] = memoryview(bytearray(1))
5except (NameError, TypeError):
6    print("SKIP")
7    raise SystemExit
8
9try:
10    import uarray as array
11except ImportError:
12    try:
13        import array
14    except ImportError:
15        print("SKIP")
16        raise SystemExit
17
18# test slice assignment between memoryviews
19b1 = bytearray(b'1234')
20b2 = bytearray(b'5678')
21b3 = bytearray(b'5678')
22m1 = memoryview(b1)
23m2 = memoryview(b2)
24m3 = memoryview(b3)
25m2[1:3] = m1[0:2]
26print(b2)
27b3[1:3] = m1[0:2]
28print(b3)
29m1[2:4] = b3[1:3]
30print(b1)
31
32# invalid slice assignments
33try:
34    m2[1:3] = b1[0:4]
35except ValueError:
36    print("ValueError")
37try:
38    m2[1:3] = m1[0:4]
39except ValueError:
40    print("ValueError")
41try:
42    m2[0:4] = m1[1:3]
43except ValueError:
44    print("ValueError")
45
46# test memoryview of arrays with items sized larger than 1
47a1 = array.array('i', [0]*5)
48m4 = memoryview(a1)
49a2 = array.array('i', [3]*5)
50m5 = memoryview(a2)
51m4[1:3] = m5[1:3]
52print(a1)
53
54try:
55    m4[1:3] = m2[1:3]
56except ValueError:
57    print("ValueError")
58
59# invalid assignment on RHS
60try:
61    memoryview(array.array('i'))[0:2] = b'1234'
62except ValueError:
63    print('ValueError')
64
65# test shift left of bytearray
66b = bytearray(range(10))
67mv = memoryview(b)
68mv[1:] = mv[:-1]
69print(b)
70
71# test shift right of bytearray
72b = bytearray(range(10))
73mv = memoryview(b)
74mv[:-1] = mv[1:]
75print(b)
76
77# test shift left of array
78a = array.array('I', range(10))
79mv = memoryview(a)
80mv[1:] = mv[:-1]
81print(a)
82
83# test shift right of array
84a = array.array('I', range(10))
85mv = memoryview(a)
86mv[:-1] = mv[1:]
87print(a)
88