Merge lp:~soren/surveilr/config into lp:surveilr

Proposed by Soren Hansen
Status: Merged
Approved by: Soren Hansen
Approved revision: 10
Merged at revision: 10
Proposed branch: lp:~soren/surveilr/config
Merge into: lp:surveilr
Diff against target: 93 lines (+39/-19)
3 files modified
setup.py (+1/-0)
surveilr/tests/__init__.py (+34/-0)
surveilr/tests/test_config.py (+4/-19)
To merge this branch: bzr merge lp:~soren/surveilr/config
Reviewer Review Type Date Requested Status
Soren Hansen Pending
Review via email: mp+83873@code.launchpad.net

Commit message

Move config override magic for tests into common test class.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'setup.py'
2--- setup.py 2011-11-16 09:15:46 +0000
3+++ setup.py 2011-11-29 23:26:26 +0000
4@@ -31,6 +31,7 @@
5 packages=['surveilr'],
6 install_requires=['riakalchemy'],
7 test_suite='nose.collector',
8+ install_package_data=True,
9 classifiers=[
10 'Development Status :: 2 - Pre-Alpha',
11 'Environment :: Console',
12
13=== modified file 'surveilr/tests/__init__.py'
14--- surveilr/tests/__init__.py 2011-11-22 08:51:25 +0000
15+++ surveilr/tests/__init__.py 2011-11-29 23:26:26 +0000
16@@ -17,3 +17,37 @@
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19 """
20+
21+import mock
22+import os.path
23+import unittest
24+
25+from surveilr import config
26+
27+class TestCase(unittest.TestCase):
28+ def config_files(self):
29+ module = self.__module__
30+ if not module.startswith('surveilr.tests'):
31+ return
32+
33+ cfg_file = '%s.cfg' % (os.path.join(os.path.dirname(__file__),
34+ *module.split('.')[2:]),)
35+ return [cfg_file]
36+
37+ def defaults_file(self):
38+ return os.path.join(os.path.dirname(__file__),
39+ os.path.pardir, 'defaults.cfg')
40+
41+ def setUp(self):
42+ super(TestCase, self).setUp()
43+ with mock.patch('surveilr.config.defaults_file') as defaults_file:
44+ with mock.patch('surveilr.config.config_files') as config_files:
45+ config_files.return_value = self.config_files()
46+ defaults_file.return_value = self.defaults_file()
47+
48+ config.load_default_config()
49+
50+ def tearDown(self):
51+ config.load_default_config()
52+
53+
54
55=== modified file 'surveilr/tests/test_config.py'
56--- surveilr/tests/test_config.py 2011-11-28 22:18:35 +0000
57+++ surveilr/tests/test_config.py 2011-11-29 23:26:26 +0000
58@@ -21,31 +21,16 @@
59 """
60
61 from surveilr import config
62+from surveilr import tests
63
64-import mock
65 import os.path
66-import unittest
67-
68-
69-class ConfigTest(unittest.TestCase):
70- def config_files(self):
71- return []
72-
73+
74+
75+class ConfigTest(tests.TestCase):
76 def defaults_file(self):
77 return os.path.join(os.path.dirname(__file__),
78 'test_config_defaults.cfg')
79
80- def setUp(self):
81- with mock.patch('surveilr.config.defaults_file') as defaults_file:
82- with mock.patch('surveilr.config.config_files') as config_files:
83- config_files.return_value = self.config_files()
84- defaults_file.return_value = self.defaults_file()
85-
86- config.load_default_config()
87-
88- def tearDown(self):
89- config.load_default_config()
90-
91
92 class ConfigCoercionTests(ConfigTest):
93 def test_str(self):

Subscribers

People subscribed via source and target branches

to all changes: