Skip to content

Commit

Permalink
Merge pull request #543 from sebastic/tempfile-mktemp
Browse files Browse the repository at this point in the history
Use NamedTemporaryFile instead of deprecated mktemp.
  • Loading branch information
jswhit committed Mar 28, 2016
2 parents 5887242 + e387e6b commit 7d55bfe
Show file tree
Hide file tree
Showing 31 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion test/tst_atts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ordereddict import OrderedDict

# test attribute creation.
FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
VAR_NAME="dummy_var"
GROUP_NAME = "dummy_group"
DIM1_NAME="x"
Expand Down
2 changes: 1 addition & 1 deletion test/tst_cdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys, os, unittest, tempfile
from numpy.testing import assert_array_equal

FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
dimsize = np.iinfo(np.int64).max # max unsigned 64 bit integer
ndim = 100
arrdata = np.random.randint(np.iinfo(np.uint8).min,np.iinfo(np.uint8).max,size=ndim)
Expand Down
2 changes: 1 addition & 1 deletion test/tst_compound_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def string_to_bytes(xstring, size=-1, pad="\0"):
(396, 290, 65.71821594238281, -167.9770050048828, 3545, -10149, 8941, -16614, 9, 34164, 1, 0, 200, 526, 511, 301, 170, 65528, 35, 1480, 2350, 3029, 2645, 2928, 5907, 11842, 6208, 16528, 7384, 7988, 870, 527, 661, 3054, 2504, 3291, 3235, 2490, 3424, 354, 354, 10039, 10988, 7958, 7395, 7902, 8811, 14853, 16836, 17231, 20852, 13, 7, 6, 15, 15, 15, 15, 0, 10, 5, 8, 8, 4, 5, 4, 7, 0, 0, 12, 13, 15, 5, 12, 2, 2, 6, 3, 15, 15, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 6, 6, 6, 0, 6, 0, 0, 2, 0, 0, 0, 255, 255, [83, -97, 14, -111, 0, 0], [13, -128, -114, 4, 0, 0, 11, 3, 20, 1], [0, 0, 0, 0, 0])],
dtype=[('mxd03_granule_row', '<i2'), ('mxd03_granule_column', '<i2'), ('mxd03_latitude', '<f4'), ('mxd03_longitude', '<f4'), ('mxd03_sensor_zenith', '<i2'), ('mxd03_sensor_azimuth', '<i2'), ('mxd03_solar_zenith', '<i2'), ('mxd03_solar_azimuth', '<i2'), ('mxd03_height', '<i2'), ('mxd03_range', '<u2'), ('mxd03_land_sea_mask', '|u1'), ('mxd03_gflags', '|u1'), ('mxd02_band_1A', '<u2'), ('mxd02_band_2A', '<u2'), ('mxd02_band_3A', '<u2'), ('mxd02_band_4A', '<u2'), ('mxd02_band_5A', '<u2'), ('mxd02_band_6A', '<u2'), ('mxd02_band_7A', '<u2'), ('mxd02_band_8', '<u2'), ('mxd02_band_9', '<u2'), ('mxd02_band_10', '<u2'), ('mxd02_band_11', '<u2'), ('mxd02_band_12', '<u2'), ('mxd02_band_13lo', '<u2'), ('mxd02_band_13hi', '<u2'), ('mxd02_band_14lo', '<u2'), ('mxd02_band_14hi', '<u2'), ('mxd02_band_15', '<u2'), ('mxd02_band_16', '<u2'), ('mxd02_band_17', '<u2'), ('mxd02_band_18', '<u2'), ('mxd02_band_19', '<u2'), ('mxd02_band_20', '<u2'), ('mxd02_band_21', '<u2'), ('mxd02_band_22', '<u2'), ('mxd02_band_23', '<u2'), ('mxd02_band_24', '<u2'), ('mxd02_band_25', '<u2'), ('mxd02_band_26', '<u2'), ('mxd02_band_26B', '<u2'), ('mxd02_band_27', '<u2'), ('mxd02_band_28', '<u2'), ('mxd02_band_29', '<u2'), ('mxd02_band_30', '<u2'), ('mxd02_band_31', '<u2'), ('mxd02_band_32', '<u2'), ('mxd02_band_33', '<u2'), ('mxd02_band_34', '<u2'), ('mxd02_band_35', '<u2'), ('mxd02_band_36', '<u2'), ('mxd02_band_uncertainity_1A', '|u1'), ('mxd02_band_uncertainity_2A', '|u1'), ('mxd02_band_uncertainity_3A', '|u1'), ('mxd02_band_uncertainity_4A', '|u1'), ('mxd02_band_uncertainity_5A', '|u1'), ('mxd02_band_uncertainity_6A', '|u1'), ('mxd02_band_uncertainity_7A', '|u1'), ('mxd02_band_uncertainity_8', '|u1'), ('mxd02_band_uncertainity_9', '|u1'), ('mxd02_band_uncertainity_10', '|u1'), ('mxd02_band_uncertainity_11', '|u1'), ('mxd02_band_uncertainity_12', '|u1'), ('mxd02_band_uncertainity_13lo', '|u1'), ('mxd02_band_uncertainity_13hi', '|u1'), ('mxd02_band_uncertainity_14lo', '|u1'), ('mxd02_band_uncertainity_14hi', '|u1'), ('mxd02_band_uncertainity_15', '|u1'), ('mxd02_band_uncertainity_16', '|u1'), ('mxd02_band_uncertainity_17', '|u1'), ('mxd02_band_uncertainity_18', '|u1'), ('mxd02_band_uncertainity_19', '|u1'), ('mxd02_band_uncertainity_20', '|u1'), ('mxd02_band_uncertainity_21', '|u1'), ('mxd02_band_uncertainity_22', '|u1'), ('mxd02_band_uncertainity_23', '|u1'), ('mxd02_band_uncertainity_24', '|u1'), ('mxd02_band_uncertainity_25', '|u1'), ('mxd02_band_uncertainity_26', '|u1'), ('mxd02_band_uncertainity_26B', '|u1'), ('mxd02_band_uncertainity_27', '|u1'), ('mxd02_band_uncertainity_28', '|u1'), ('mxd02_band_uncertainity_29', '|u1'), ('mxd02_band_uncertainity_30', '|u1'), ('mxd02_band_uncertainity_31', '|u1'), ('mxd02_band_uncertainity_32', '|u1'), ('mxd02_band_uncertainity_33', '|u1'), ('mxd02_band_uncertainity_34', '|u1'), ('mxd02_band_uncertainity_35', '|u1'), ('mxd02_band_uncertainity_36', '|u1'), ('mxd02_band_nsamples_1A', '|i1'), ('mxd02_band_nsamples_2A', '|i1'), ('mxd02_band_nsamples_3A', '|i1'), ('mxd02_band_nsamples_4A', '|i1'), ('mxd02_band_nsamples_5A', '|i1'), ('mxd02_band_nsamples_6A', '|i1'), ('mxd02_band_nsamples_7A', '|i1'), ('reserved_20120221a', '|u1'), ('mxd11_lst', '<u2'), ('mxd11_qc', '<u2'), ('mxd11_error_lst', '<u2'), ('mxd11_emis31', '<u2'), ('mxd11_emis32', '<u2'), ('mxd11_view_angle', '|u1'), ('mxd11_view_time', '|u1'), ('mxd35_cloud_mask', '|i1', (6,)), ('mxd35_quality_assurance', '|i1', (10,)), ('reserved_20120221b', '|u1', (5,))])

FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name

class CompoundAlignTestCase(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion test/tst_compoundatt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# test compound attributes.

FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
DIM_NAME = 'time'
VAR_NAME = 'wind'
VAR_NAME2 = 'forecast_wind'
Expand Down
2 changes: 1 addition & 1 deletion test/tst_compoundvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# test compound data types.

FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
#FILE_NAME = 'test.nc'
DIM_NAME = 'phony_dim'
GROUP_NAME = 'phony_group'
Expand Down
2 changes: 1 addition & 1 deletion test/tst_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ndim2 = 100
chunk1 = 10; chunk2 = ndim2
nfiles = 7
files = [tempfile.mktemp(".nc") for nfile in range(nfiles)]
files = [tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name for nfile in range(nfiles)]
array = uniform(size=(ndim,))
array2 = uniform(size=(ndim,ndim2))
lsd = 3
Expand Down
2 changes: 1 addition & 1 deletion test/tst_dims.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from numpy.random.mtrand import uniform
import netCDF4

FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
LAT_NAME="lat"
LAT_LEN = 25
LAT_LENG = 50
Expand Down
4 changes: 2 additions & 2 deletions test/tst_diskless.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
n3dim = 144
ranarr = 100.*uniform(size=(n1dim,n2dim,n3dim))
ranarr2 = 100.*uniform(size=(n1dim,n2dim,n3dim))
FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME2 = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=True).name
FILE_NAME2 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name

class DisklessTestCase(unittest.TestCase):

Expand Down
4 changes: 2 additions & 2 deletions test/tst_endian.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from numpy.testing import assert_array_equal, assert_array_almost_equal

data = np.arange(12,dtype='f4').reshape(3,4)
FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME2 = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
FILE_NAME2 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name

def create_file(file,format,data):
import warnings
Expand Down
2 changes: 1 addition & 1 deletion test/tst_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from numpy.testing import assert_array_equal

FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
ENUM_NAME = 'cloud_t'
ENUM_BASETYPE = np.int8
VAR_NAME = 'primary_cloud'
Expand Down
2 changes: 1 addition & 1 deletion test/tst_fancyslicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
See test2unlim below for an example.
"""

file_name = tempfile.mktemp(".nc")
file_name = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
xdim=9; ydim=10; zdim=11
i = np.array([2,5,7],'i4')
i2 = np.array([0,8],'i4')
Expand Down
4 changes: 2 additions & 2 deletions test/tst_grps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

# test group creation.

FILE_NAME1 = tempfile.mktemp(".nc")
FILE_NAME2 = tempfile.mktemp(".nc")
FILE_NAME1 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
FILE_NAME2 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
DYNASTY=u"Tudor"
HENRY_VII=u"Henry_VII"
MARGARET=u"Margaret"
Expand Down
2 changes: 1 addition & 1 deletion test/tst_grps2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# in createVariable and createGroups (added in 1.1.8).
# also test Dataset.__getitem__, also added in 1.1.8.

FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name

class Groups2TestCase(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion test/tst_masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# packing/unpacking of short ints.

# create an n1dim by n2dim random ranarr.
FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
ndim = 10
ranarr = 100.*uniform(size=(ndim))
ranarr2 = 100.*uniform(size=(ndim))
Expand Down
6 changes: 3 additions & 3 deletions test/tst_masked2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# test automatic conversion of masked arrays, and
# packing/unpacking of short ints.

FILE_NAME1 = tempfile.mktemp(".nc")
FILE_NAME2 = tempfile.mktemp(".nc")
FILE_NAME3 = tempfile.mktemp(".nc")
FILE_NAME1 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
FILE_NAME2 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
FILE_NAME3 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
datacheck1 =\
ma.array([0,5000.0,4000.0,0],dtype=np.float,mask=[True,False,False,True])
datacheck2 =\
Expand Down
4 changes: 2 additions & 2 deletions test/tst_masked3.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SetAutoMaskTestBase(unittest.TestCase):

def setUp(self):

self.testfile = tempfile.mktemp(".nc")
self.testfile = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name

self.fillval = default_fillvals["i2"]
self.v = np.array([self.fillval, 5, 4, -9999], dtype = "i2")
Expand Down Expand Up @@ -137,7 +137,7 @@ class GlobalSetAutoMaskTest(unittest.TestCase):

def setUp(self):

self.testfile = tempfile.mktemp(".nc")
self.testfile = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name

f = Dataset(self.testfile, 'w')

Expand Down
4 changes: 2 additions & 2 deletions test/tst_multifile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
nx=100; ydim=5; zdim=1
nfiles = 10
ninc = nx/nfiles
files = [tempfile.mktemp(".nc") for nfile in range(nfiles)]
files = [tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name for nfile in range(nfiles)]
data = randint(0,10,size=(nx,ydim,zdim))
missval = 99
data[::10] = missval
Expand Down Expand Up @@ -66,7 +66,7 @@ class NonuniformTimeTestCase(unittest.TestCase):
ninc = 365
def setUp(self):

self.files = [tempfile.mktemp(".nc") for nfile in range(2)]
self.files = [tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name for nfile in range(2)]
for nfile,file in enumerate(self.files):
f = Dataset(file,'w',format='NETCDF4_CLASSIC')
f.createDimension('time',None)
Expand Down
4 changes: 2 additions & 2 deletions test/tst_multifile2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
nx=100; ydim=5; zdim=1
nfiles = 10
ninc = nx/nfiles
files = [tempfile.mktemp(".nc") for nfile in range(nfiles)]
files = [tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name for nfile in range(nfiles)]
data = randint(0,10,size=(nx,ydim,zdim))
missval = 99
data[::10] = missval
Expand Down Expand Up @@ -68,7 +68,7 @@ class NonuniformTimeTestCase(unittest.TestCase):
ninc = 365
def setUp(self):

self.files = [tempfile.mktemp(".nc") for nfile in range(2)]
self.files = [tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name for nfile in range(2)]
for nfile,file in enumerate(self.files):
f = Dataset(file,'w',format='NETCDF4_CLASSIC')
f.createDimension('time',None)
Expand Down
2 changes: 1 addition & 1 deletion test/tst_netcdftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def setUp(self):
self.standardtime = self.TestTime(datetime(1950, 1, 1), 366, 24,
'hours since 1900-01-01', 'standard')

self.file = tempfile.mktemp(".nc")
self.file = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
f = Dataset(self.file, 'w')
f.createDimension('time', None)
time = f.createVariable('time', float, ('time',))
Expand Down
2 changes: 1 addition & 1 deletion test/tst_refcount.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest, netCDF4, tempfile, os

file_name = tempfile.mktemp(".nc")
file_name = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name

class RefCountTestCase(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion test/tst_rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# test changing dimension, variable names
# and deleting attributes.

FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
LAT_NAME="lat"
LON_NAME="lon"
LON_NAME2 = "longitude"
Expand Down
2 changes: 1 addition & 1 deletion test/tst_scalarvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
VAR_NAME='temp'
VAR_TYPE='f4'
VAR_VAL=math.pi
FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
GROUP_NAME = 'subgroup'

# test scalar variable creation and retrieval.
Expand Down
4 changes: 2 additions & 2 deletions test/tst_scaled.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SetAutoScaleTestBase(unittest.TestCase):

def setUp(self):

self.testfile = tempfile.mktemp(".nc")
self.testfile = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name

self.fillval = default_fillvals["i2"]
self.missing_value = -9999
Expand Down Expand Up @@ -184,7 +184,7 @@ class GlobalSetAutoScaleTest(unittest.TestCase):

def setUp(self):

self.testfile = tempfile.mktemp(".nc")
self.testfile = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name

f = Dataset(self.testfile, 'w')

Expand Down
2 changes: 1 addition & 1 deletion test/tst_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import tempfile, unittest, os
import numpy as np

file_name = tempfile.mktemp(".nc")
file_name = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
xdim=None; ydim=121; zdim=169
datashape = (ydim,zdim)
data = np.ones(datashape,dtype=np.float)
Expand Down
2 changes: 1 addition & 1 deletion test/tst_slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import tempfile, unittest, os, random
import numpy as np

file_name = tempfile.mktemp(".nc")
file_name = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
xdim=9; ydim=10; zdim=11
#seed(9) # fix seed
data = randint(0,10,size=(xdim,ydim,zdim)).astype('u1')
Expand Down
2 changes: 1 addition & 1 deletion test/tst_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# test primitive data types.

# create an n1dim by n2dim random ranarr.
FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
n1dim = 5
n2dim = 10
ranarr = 100.*uniform(size=(n1dim,n2dim))
Expand Down
2 changes: 1 addition & 1 deletion test/tst_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

netCDF4.default_encoding = 'utf-8'

FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
ATT1 = u'\u03a0\u03a3\u03a9'
ATT2 = u'x\xb0'
ATT3 = [u'\u03a0',u'\u03a3',u'\u03a9']
Expand Down
2 changes: 1 addition & 1 deletion test/tst_unicode3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

netCDF4.default_encoding = 'utf-8'

FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
ATT1 = '\u03a0\u03a3\u03a9'
ATT2 = 'x\xb0'
ATT3 = ['\u03a0','\u03a3','\u03a9']
Expand Down
2 changes: 1 addition & 1 deletion test/tst_unlimdim.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
n2dim = 10
n3dim = 8
ranarr = 100.*uniform(size=(n1dim,n2dim,n3dim))
FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name

class UnlimdimTestCase(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion test/tst_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# test variable creation.

FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
VAR_DOUBLE_NAME="dummy_var"
VAR_SHORT_NAME='dummy_var_short'
VARNAMES = sorted([VAR_DOUBLE_NAME,VAR_SHORT_NAME])
Expand Down
2 changes: 1 addition & 1 deletion test/tst_vlen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from numpy.testing import assert_array_equal

FILE_NAME = tempfile.mktemp(".nc")
FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
VL_NAME = 'vlen_type'
VL_BASETYPE = np.int16
DIM1_NAME = 'lon'
Expand Down

0 comments on commit 7d55bfe

Please sign in to comment.