Permalink
Browse files

TST: close open files

Fix 7 test errors on Windows of the following type: `PermissionError: [WinError 32] The process cannot access the file because it is being used by another process`
  • Loading branch information...
1 parent 78606f1 commit 98b992b816d006de6063cd7027278b243ca92fab @cgohlke cgohlke committed Oct 16, 2013
Showing with 58 additions and 58 deletions.
  1. +58 −58 la/tests/io_test.py
View
@@ -28,82 +28,82 @@ def tearDown(self):
def test_io_1(self):
"io_general"
- io = IO(self.filename)
- x = larry([1,2,3])
- io['x'] = x
- self.assertTrue('x' in io, 'key missing')
- self.assertTrue((x == io['x'][:]).all(), 'save and load difference')
- self.assertTrue(['x'] == io.keys(), 'keys are different')
- self.assertTrue(x.dtype == io['x'].dtype, 'dtype changed')
- del io['x']
- self.assertTrue(io.keys() == [], 'key still present')
+ with IO(self.filename) as io:
+ x = larry([1,2,3])
+ io['x'] = x
+ self.assertTrue('x' in io, 'key missing')
+ self.assertTrue((x == io['x'][:]).all(), 'save and load difference')
+ self.assertTrue(['x'] == list(io.keys()), 'keys are different')
+ self.assertTrue(x.dtype == io['x'].dtype, 'dtype changed')
+ del io['x']
+ self.assertTrue(list(io.keys()) == [], 'key still present')
def test_io_2(self):
"io_repack"
- io = IO(self.filename)
- io['larry'] = la.rand(100, 100)
- fs1 = io.freespace
- sp1 = io.space
- del io['larry']
- io.repack()
- fs2 = io.freespace
- sp2 = io.space
- self.assertTrue(fs2 < fs1, 'repack did not reduce freespace')
- self.assertTrue(sp2 < sp1, 'repack did not reduce space')
+ with IO(self.filename) as io:
+ io['larry'] = la.rand(100, 100)
+ fs1 = io.freespace
+ sp1 = io.space
+ del io['larry']
+ io.repack()
+ fs2 = io.freespace
+ sp2 = io.space
+ self.assertTrue(fs2 < fs1, 'repack did not reduce freespace')
+ self.assertTrue(sp2 < sp1, 'repack did not reduce space')
def test_io_3(self):
"io_keys"
- io = IO(self.filename)
- io['1'] = larry([1,2,3])
- io['2'] = larry([1,2,3])
- io.f['3'] = [1,2,3]
- io['1/2/3/4'] = larry([1,2,3])
- keys = io.keys()
- keys.sort()
- theory = ['1', '1/2/3/4', '2']
- self.assertTrue(keys == theory, 'keys do not match')
+ with IO(self.filename) as io:
+ io['1'] = larry([1,2,3])
+ io['2'] = larry([1,2,3])
+ io.f['3'] = [1,2,3]
+ io['1/2/3/4'] = larry([1,2,3])
+ keys = list(io.keys())
+ keys.sort()
+ theory = ['1', '1/2/3/4', '2']
+ self.assertTrue(keys == theory, 'keys do not match')
def test_io_4(self):
"io_dates"
- io = IO(self.filename)
- x = [1, 2]
- label = [[datetime.date(2010,3,1), datetime.date(2010,3,2)]]
- desired = larry(x, label)
- io['desired'] = desired
- actual = io['desired'][:]
- assert_larry_equal(actual, desired)
+ with IO(self.filename) as io:
+ x = [1, 2]
+ label = [[datetime.date(2010,3,1), datetime.date(2010,3,2)]]
+ desired = larry(x, label)
+ io['desired'] = desired
+ actual = io['desired'][:]
+ assert_larry_equal(actual, desired)
def test_io_5(self):
"io_datetimes"
- io = IO(self.filename)
- x = [1, 2]
- label = [[datetime.datetime(2010,3,1,13,15,59,9998),
- datetime.datetime(2010,3,2,11,23)]]
- desired = larry(x, label)
- io['desired'] = desired
- actual = io['desired'][:]
- assert_larry_equal(actual, desired)
+ with IO(self.filename) as io:
+ x = [1, 2]
+ label = [[datetime.datetime(2010,3,1,13,15,59,9998),
+ datetime.datetime(2010,3,2,11,23)]]
+ desired = larry(x, label)
+ io['desired'] = desired
+ actual = io['desired'][:]
+ assert_larry_equal(actual, desired)
def test_io_6(self):
"io_datetimes"
- io = IO(self.filename)
- x = [1, 2]
- label = [[datetime.time(13,15,59,9998),
- datetime.time(11,23)]]
- desired = larry(x, label)
- io['desired'] = desired
- actual = io['desired'][:]
- assert_larry_equal(actual, desired)
+ with IO(self.filename) as io:
+ x = [1, 2]
+ label = [[datetime.time(13,15,59,9998),
+ datetime.time(11,23)]]
+ desired = larry(x, label)
+ io['desired'] = desired
+ actual = io['desired'][:]
+ assert_larry_equal(actual, desired)
def test_io_7(self):
"io_empty (gh #68)"
- io = IO(self.filename)
- desired = larry([])
- io['desired'] = desired
- actual = io['desired']
- if actual.size == 0:
- actual = la.larry([])
- assert_larry_equal(actual, desired)
+ with IO(self.filename) as io:
+ desired = larry([])
+ io['desired'] = desired
+ actual = io['desired']
+ if actual.size == 0:
+ actual = la.larry([])
+ assert_larry_equal(actual, desired)
# nose tests ----------------------------------------------------------------

0 comments on commit 98b992b

Please sign in to comment.