From bf7d644ee99b0d4a2aaadd2cf5b44058e2b7c207 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Thu, 20 Apr 2017 16:39:13 +0100
Subject: [PATCH] Updates to settings unit tests

---
 tests/test_settings.py | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/tests/test_settings.py b/tests/test_settings.py
index dfbaa38f5..5cd1fdd29 100644
--- a/tests/test_settings.py
+++ b/tests/test_settings.py
@@ -29,8 +29,14 @@ def test_initialise():
 
     # Assuming that initialise()
     # has not yet been called
-    with pytest.raises(AttributeError):
-        settings.read('nothing')
+    assert settings.read('nothing') is None
+    assert settings.read('nothing', 'default') == 'default'
+    settings.write('nothing', 'nothing')
+    settings.delete('nothing')
+    assert settings.readFile('nothing') is None
+    settings.writeFile('nothing', 'nothing')
+    settings.deleteFile('nothing')
+    settings.clear()
 
     with tests.testdir() as testdir:
         
@@ -143,8 +149,20 @@ def test_init_writeOnExit():
             readback = pickle.load(f)
             assert testdata == readback
 
+def test_init_not_writeOnExit():
 
-        
+
+    atexit_funcs = []
+
+    def mock_atexit_register(func, *args, **kwargs):
+        atexit_funcs.append((func, args, kwargs))
+
+    with tests.testdir() as testdir, \
+         mock.patch('fsl.utils.settings.atexit.register', mock_atexit_register):
+
+        s = settings.Settings('test', cfgdir=testdir, writeOnExit=False)
+
+        assert len(atexit_funcs) == 0
 
             
 
-- 
GitLab