(self)
| 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: |
nothing calls this directly
no test coverage detected