Skip to content
Snippets Groups Projects
Commit 51a50880 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

makedirs raises OSError, not IOError

parent 6e7e48c0
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,7 @@ try: ...@@ -18,7 +18,7 @@ try:
# python 2 # python 2
except: except:
import mock import mock
import pytest import pytest
import tests import tests
...@@ -42,7 +42,7 @@ def test_initialise(): ...@@ -42,7 +42,7 @@ def test_initialise():
settings.clear() settings.clear()
with tests.testdir() as testdir: with tests.testdir() as testdir:
settings.initialise(cfgid='test', cfgdir=testdir, writeOnExit=False) settings.initialise(cfgid='test', cfgdir=testdir, writeOnExit=False)
assert settings.settings.configID == 'test' assert settings.settings.configID == 'test'
...@@ -56,7 +56,7 @@ def test_initialise(): ...@@ -56,7 +56,7 @@ def test_initialise():
def test_init_configDir(): def test_init_configDir():
# config dir on linux # config dir on linux
with tests.testdir() as testdir, \ with tests.testdir() as testdir, \
mock.patch('fsl.utils.settings.platform.system', return_value='linux'), \ mock.patch('fsl.utils.settings.platform.system', return_value='linux'), \
mock.patch('fsl.utils.settings.op.expanduser', return_value=testdir): mock.patch('fsl.utils.settings.op.expanduser', return_value=testdir):
...@@ -96,7 +96,7 @@ def test_init_configDir(): ...@@ -96,7 +96,7 @@ def test_init_configDir():
s = settings.Settings(cfgid='test', writeOnExit=False) s = settings.Settings(cfgid='test', writeOnExit=False)
assert s.configDir == expected assert s.configDir == expected
def test_init_configDir_tempdir(): def test_init_configDir_tempdir():
atexit_funcs = [] atexit_funcs = []
...@@ -105,8 +105,8 @@ def test_init_configDir_tempdir(): ...@@ -105,8 +105,8 @@ def test_init_configDir_tempdir():
atexit_funcs.append((func, args, kwargs)) atexit_funcs.append((func, args, kwargs))
with mock.patch('fsl.utils.settings.atexit.register', mock_atexit_register), \ with mock.patch('fsl.utils.settings.atexit.register', mock_atexit_register), \
mock.patch('fsl.utils.settings.os.makedirs', side_effect=IOError): mock.patch('fsl.utils.settings.os.makedirs', side_effect=OSError):
s = settings.Settings('test', writeOnExit=False) s = settings.Settings('test', writeOnExit=False)
cfgdir = s.configDir cfgdir = s.configDir
...@@ -119,7 +119,7 @@ def test_init_configDir_tempdir(): ...@@ -119,7 +119,7 @@ def test_init_configDir_tempdir():
f(*a, **kwa) f(*a, **kwa)
assert not op.exists(cfgdir) assert not op.exists(cfgdir)
def test_init_writeOnExit(): def test_init_writeOnExit():
...@@ -167,7 +167,7 @@ def test_init_not_writeOnExit(): ...@@ -167,7 +167,7 @@ def test_init_not_writeOnExit():
assert len(atexit_funcs) == 0 assert len(atexit_funcs) == 0
def test_readConfigFile(): def test_readConfigFile():
...@@ -187,7 +187,7 @@ def test_readConfigFile(): ...@@ -187,7 +187,7 @@ def test_readConfigFile():
for k, v in testdata.items(): for k, v in testdata.items():
assert s.read(k) == v assert s.read(k) == v
def test_readwrite(): def test_readwrite():
...@@ -210,15 +210,15 @@ def test_readwrite(): ...@@ -210,15 +210,15 @@ def test_readwrite():
assert s.read('non-existent') is None assert s.read('non-existent') is None
assert s.read('non-existent', 'default') == 'default' assert s.read('non-existent', 'default') == 'default'
def test_readdefault(): def test_readdefault():
with tests.testdir() as testdir: with tests.testdir() as testdir:
s = settings.Settings(cfgid='test', cfgdir=testdir, writeOnExit=False) s = settings.Settings(cfgid='test', cfgdir=testdir, writeOnExit=False)
assert s.read('non-existent') is None assert s.read('non-existent') is None
assert s.read('non-existent', 'default') == 'default' assert s.read('non-existent', 'default') == 'default'
def test_delete(): def test_delete():
...@@ -226,7 +226,7 @@ def test_delete(): ...@@ -226,7 +226,7 @@ def test_delete():
with tests.testdir() as testdir: with tests.testdir() as testdir:
s = settings.Settings(cfgid='test', cfgdir=testdir, writeOnExit=False) s = settings.Settings(cfgid='test', cfgdir=testdir, writeOnExit=False)
s.delete('non-existent') s.delete('non-existent')
assert s.read('non-existent') is None assert s.read('non-existent') is None
...@@ -284,13 +284,13 @@ def test_deleteFile(): ...@@ -284,13 +284,13 @@ def test_deleteFile():
f.write(contents) f.write(contents)
assert s.readFile(path) == contents assert s.readFile(path) == contents
s.deleteFile(path) s.deleteFile(path)
assert s.read(path) is None assert s.read(path) is None
def test_readall(): def test_readall():
testsettings = [('namespace1.setting1', '1'), testsettings = [('namespace1.setting1', '1'),
('namespace1.setting2', '2'), ('namespace1.setting2', '2'),
('namespace1.setting3', '3'), ('namespace1.setting3', '3'),
...@@ -311,7 +311,7 @@ def test_readall(): ...@@ -311,7 +311,7 @@ def test_readall():
ns1 = [(k, v) for k, v in testsettings if k.startswith('namespace1')] ns1 = [(k, v) for k, v in testsettings if k.startswith('namespace1')]
ns2 = [(k, v) for k, v in testsettings if k.startswith('namespace2')] ns2 = [(k, v) for k, v in testsettings if k.startswith('namespace2')]
assert s.readAll('namespace1.*') == dict(ns1) assert s.readAll('namespace1.*') == dict(ns1)
assert s.readAll('namespace2.*') == dict(ns2) assert s.readAll('namespace2.*') == dict(ns2)
assert s.readAll('*setting*') == dict(testsettings) assert s.readAll('*setting*') == dict(testsettings)
...@@ -324,7 +324,7 @@ def test_listFiles(): ...@@ -324,7 +324,7 @@ def test_listFiles():
'namespace1/setting3.txt'] 'namespace1/setting3.txt']
ns2files = ['namespace2/setting1.txt', ns2files = ['namespace2/setting1.txt',
'namespace2/setting2.txt', 'namespace2/setting2.txt',
'namespace2/setting3.txt'] 'namespace2/setting3.txt']
with tests.testdir() as testdir: with tests.testdir() as testdir:
...@@ -400,7 +400,7 @@ def test_clear(): ...@@ -400,7 +400,7 @@ def test_clear():
for k, v in testsettings: for k, v in testsettings:
assert s.read(k) is None assert s.read(k) is None
for p, c in testfiles: for p, c in testfiles:
assert s.readFile(p) is None assert s.readFile(p) is None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment