Skip to content

Commit

Permalink
Addressed test concern about shared temporary directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
pelson committed Oct 24, 2017
1 parent d963263 commit 2a765b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion lib/iris/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def expand_filespecs(file_specs):
file_list = '\n - {}'.format(', '.join(expanded))
else:
file_list = ''
msg += '\n - "{}" matched {} file(s){}'.format(pattern, len(expanded), file_list)
msg += '\n - "{}" matched {} file(s){}'.format(
pattern, len(expanded), file_list)
raise IOError(msg)

return [fname for fnames in all_expanded for fname in fnames]
Expand Down
26 changes: 16 additions & 10 deletions lib/iris/tests/unit/io/test_expand_filespecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class TestExpandFilespecs(tests.IrisTest):
def setUp(self):
tests.IrisTest.setUp(self)
self.tmpdir = tempfile.mkdtemp()
self.tmpdir = os.path.realpath(tempfile.mkdtemp())
self.fnames = ['a.foo', 'b.txt']
for fname in self.fnames:
with open(os.path.join(self.tmpdir, fname), 'w') as fh:
Expand All @@ -54,10 +54,15 @@ def test_double_slash(self):
self.assertEqual(product, predicted)

def test_relative_path(self):
os.chdir(self.tmpdir)
item_out = iio.expand_filespecs(['*'])
item_in = [os.path.join(self.tmpdir, fname) for fname in self.fnames]
self.assertEqual(item_out, item_in)
cwd = os.getcwd()
try:
os.chdir(self.tmpdir)
item_out = iio.expand_filespecs(['*'])
item_in = [os.path.join(self.tmpdir, fname)
for fname in self.fnames]
self.assertEqual(item_out, item_in)
finally:
os.chdir(cwd)

def test_return_order(self):
# It is really quite important what order we return the
Expand All @@ -75,17 +80,18 @@ def test_return_order(self):
self.assertEqual(result, expected[::-1])

def test_no_files_found(self):
msg = r'_b\" matched 0 file\(s\)'
msg = r'\/no_exist.txt\" matched 0 file\(s\)'
with self.assertRaisesRegexp(IOError, msg):
iio.expand_filespecs([self.tmpdir + '_b'])
iio.expand_filespecs([os.path.join(self.tmpdir, 'no_exist.txt')])

def test_files_and_none(self):
with self.assertRaises(IOError) as err:
iio.expand_filespecs([self.tmpdir + '_b',
os.path.join(self.tmpdir, '*')])
iio.expand_filespecs(
[os.path.join(self.tmpdir, 'does_not_exist.txt'),
os.path.join(self.tmpdir, '*')])
expected = textwrap.dedent("""
One or more of the files specified did not exist:
- "{0}_b" matched 0 file(s)
- "{0}/does_not_exist.txt" matched 0 file(s)
- "{0}/*" matched 2 file(s)
- {0}/a.foo, {0}/b.txt
""").strip().format(self.tmpdir)
Expand Down

0 comments on commit 2a765b5

Please sign in to comment.