|
| 1 | +from __future__ import with_statement |
1 | 2 | import os
|
2 | 3 | from os.path import join as pjoin
|
| 4 | +import getpass |
3 | 5 | import time
|
4 |
| -import tempfile |
| 6 | + |
| 7 | +from nibabel.tmpdirs import InTemporaryDirectory |
5 | 8 |
|
6 | 9 | from nose.tools import assert_true
|
7 | 10 | import numpy as np
|
@@ -40,21 +43,16 @@ def test_geometry():
|
40 | 43 |
|
41 | 44 | # Test equivalence of freesurfer- and nibabel-generated triangular files
|
42 | 45 | # with respect to read_geometry()
|
43 |
| - ntf = tempfile.NamedTemporaryFile(delete=False) |
44 |
| - ntf.close() |
45 |
| - |
46 |
| - surf_path = ntf.name |
47 |
| - create_stamp = "created by %s on %s" % (os.getlogin(), time.ctime()) |
48 |
| - write_geometry(surf_path, coords, faces, create_stamp) |
49 |
| - |
50 |
| - coords2, faces2 = read_geometry(surf_path) |
| 46 | + with InTemporaryDirectory(): |
| 47 | + surf_path = 'test' |
| 48 | + create_stamp = "created by %s on %s" % (getpass.getuser(), time.ctime()) |
| 49 | + write_geometry(surf_path, coords, faces, create_stamp) |
51 | 50 |
|
52 |
| - with open(surf_path,'rb') as fobj: |
53 |
| - magic = np.fromfile(fobj, ">u1", 3) |
54 |
| - read_create_stamp = fobj.readline().rstrip('\n') |
| 51 | + coords2, faces2 = read_geometry(surf_path) |
55 | 52 |
|
56 |
| - # Remove temporary file |
57 |
| - os.unlink(surf_path) |
| 53 | + with open(surf_path,'rb') as fobj: |
| 54 | + magic = np.fromfile(fobj, ">u1", 3) |
| 55 | + read_create_stamp = fobj.readline().rstrip('\n') |
58 | 56 |
|
59 | 57 | assert_equal(create_stamp, read_create_stamp)
|
60 | 58 |
|
|
0 commit comments