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

Method test_access_parameter

Lib/test/test_mmap.py:138–261  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

136 m.close()
137
138 def test_access_parameter(self):
139 # Test for "access" keyword parameter
140 mapsize = 10
141 with open(TESTFN, "wb") as fp:
142 fp.write(b"a"*mapsize)
143 with open(TESTFN, "rb") as f:
144 m = mmap.mmap(f.fileno(), mapsize, access=mmap.ACCESS_READ)
145 self.assertEqual(m[:], b'a'*mapsize, "Readonly memory map data incorrect.")
146
147 # Ensuring that readonly mmap can't be slice assigned
148 try:
149 m[:] = b'b'*mapsize
150 except TypeError:
151 pass
152 else:
153 self.fail("Able to write to readonly memory map")
154
155 # Ensuring that readonly mmap can't be item assigned
156 try:
157 m[0] = b'b'
158 except TypeError:
159 pass
160 else:
161 self.fail("Able to write to readonly memory map")
162
163 # Ensuring that readonly mmap can't be write() to
164 try:
165 m.seek(0,0)
166 m.write(b'abc')
167 except TypeError:
168 pass
169 else:
170 self.fail("Able to write to readonly memory map")
171
172 # Ensuring that readonly mmap can't be write_byte() to
173 try:
174 m.seek(0,0)
175 m.write_byte(b'd')
176 except TypeError:
177 pass
178 else:
179 self.fail("Able to write to readonly memory map")
180
181 # Ensuring that readonly mmap can't be resized
182 try:
183 m.resize(2*mapsize)
184 except SystemError: # resize is not universally supported
185 pass
186 except TypeError:
187 pass
188 else:
189 self.fail("Able to resize readonly memory map")
190 with open(TESTFN, "rb") as fp:
191 self.assertEqual(fp.read(), b'a'*mapsize,
192 "Readonly memory map data file was modified")
193
194 # Opening mmap with size too big
195 with open(TESTFN, "r+b") as f:

Callers

nothing calls this directly

Calls 15

getattrFunction · 0.85
write_byteMethod · 0.80
openFunction · 0.50
writeMethod · 0.45
filenoMethod · 0.45
assertEqualMethod · 0.45
failMethod · 0.45
seekMethod · 0.45
resizeMethod · 0.45
readMethod · 0.45
startswithMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected