This repository was archived by the owner on Apr 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTestSettings.py
More file actions
62 lines (52 loc) · 2.01 KB
/
TestSettings.py
File metadata and controls
62 lines (52 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Unit tests for buttonManager
import mock
from mock import call
from mock import Mock
from mock import patch
import os
from os import sys, path
import unittest
sys.path.append(os.path.realpath('..'))
import settings
class TestWriteSettingsThread(unittest.TestCase):
def setUp(self):
settings.CONFIG_FILE = "Test/shotmanager.conf"
settings.CONFIG_FILE_BACKUP = "Test/shotmanager.back"
self.lock = Mock()
settings.settingsLock = self.lock
def testLocks(self):
""" Make sure we lock/unlock """
settings.writeSettingsThread("a", "b")
self.lock.acquire.assert_called_with()
self.lock.release.assert_called_with()
def testValueSet(self):
""" Make sure we are setting the correct value """
with patch('ConfigParser.SafeConfigParser') as patchedParser:
parser = Mock()
patchedParser.return_value = parser
settings.writeSettingsThread("aaa", "bbb")
parser.read.assert_called_with("Test/shotmanager.conf")
parser.set.assert_called_with("shotManager", "aaa", "bbb")
class TestReadSetting(unittest.TestCase):
def setUp(self):
mockParser = patch('ConfigParser.SafeConfigParser')
self.addCleanup(mockParser.stop)
mock = mockParser.start()
self.parser = Mock()
settings.CONFIG_FILE = "Test/shotmanager.conf"
mock.return_value = self.parser
def testReadSetting(self):
""" Test that we attempt to read the correct thing """
self.parser.get = Mock(return_value = "foo")
value = settings.readSetting("bleh")
self.parser.get.assert_called_with("shotManager", "bleh")
self.assertEqual(value, "foo")
def testReadBadSetting(self):
""" Test that we get an exception from a failed get """
self.parser.get = Mock(return_value = "foo", side_effect=KeyError("Boo"))
try:
value = settings.readSetting("bleh")
except:
pass
else:
self.assertFalse(True)