| 240 | |
| 241 | |
| 242 | def setUpModule(): |
| 243 | try: |
| 244 | import signal |
| 245 | # The default handler for SIGXFSZ is to abort the process. |
| 246 | # By ignoring it, system calls exceeding the file size resource |
| 247 | # limit will raise OSError instead of crashing the interpreter. |
| 248 | signal.signal(signal.SIGXFSZ, signal.SIG_IGN) |
| 249 | except (ImportError, AttributeError): |
| 250 | pass |
| 251 | |
| 252 | # On Windows and Mac OSX this test consumes large resources; It |
| 253 | # takes a long time to build the >2 GiB file and takes >2 GiB of disk |
| 254 | # space therefore the resource must be enabled to run this test. |
| 255 | # If not, nothing after this line stanza will be executed. |
| 256 | if sys.platform[:3] == 'win' or sys.platform == 'darwin': |
| 257 | requires('largefile', |
| 258 | 'test requires %s bytes and a long time to run' % str(size)) |
| 259 | else: |
| 260 | # Only run if the current filesystem supports large files. |
| 261 | # (Skip this test on Windows, since we now always support |
| 262 | # large files.) |
| 263 | f = open(TESTFN, 'wb', buffering=0) |
| 264 | try: |
| 265 | # 2**31 == 2147483648 |
| 266 | f.seek(2147483649) |
| 267 | # Seeking is not enough of a test: you must write and flush, too! |
| 268 | f.write(b'x') |
| 269 | f.flush() |
| 270 | except (OSError, OverflowError): |
| 271 | raise unittest.SkipTest("filesystem does not have " |
| 272 | "largefile support") |
| 273 | finally: |
| 274 | f.close() |
| 275 | unlink(TESTFN) |
| 276 | |
| 277 | |
| 278 | class CLargeFileTest(TestFileMethods, unittest.TestCase): |