aboutsummaryrefslogtreecommitdiff
path: root/test/test_config/test_file.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_config/test_file.py')
-rw-r--r--test/test_config/test_file.py101
1 files changed, 101 insertions, 0 deletions
diff --git a/test/test_config/test_file.py b/test/test_config/test_file.py
new file mode 100644
index 0000000..1ed014e
--- /dev/null
+++ b/test/test_config/test_file.py
@@ -0,0 +1,101 @@
1# Copyright (C) 2010 Leonard Thomas
2#
3# This file is part of Dodai.
4#
5# Dodai is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# Dodai is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with Dodai. If not, see <http://www.gnu.org/licenses/>.
17
18import unittest
19import os
20from dodai.config.file import ConfigFile
21from dodai.config.file import DirectoryDoesNotExistException
22from dodai.config.file import DirectoryNotSetException
23from dodai.config.file import InvalidDirectoryException
24from dodai.config.file import FileDoesNotExistException
25from dodai.config.file import NoFilesToLoadException
26import ConfigParser
27
28class TestConfigFile(unittest.TestCase):
29
30 def setUp(self):
31 self.obj = ConfigFile()
32 self.path = os.path.dirname(__file__)
33 self.filename = 'config'
34 self.filepath = os.path.join(self.path, self.filename)
35 next_file = os.path.join(self.path, 'config.cfg')
36 self.paths = [self.filepath, next_file]
37
38 def test_file_add(self):
39 self.obj.add_file(self.filepath)
40 paths = [self.filepath]
41 files = self.obj.get_files()
42 self.assertEqual(files, paths)
43
44 def test_double_file_add(self):
45 self.obj.add_file(self.filepath)
46 self.obj.add_file(self.filepath)
47 paths = [self.filepath]
48 files = self.obj.get_files()
49 self.assertEqual(files, paths)
50
51 def test_file_does_not_exist(self):
52 path = os.path.join(self.path, 'foo')
53 self.failUnlessRaises(FileDoesNotExistException,
54 self.obj.add_file, path)
55
56 def test_multiple_file_add(self):
57 self.obj.add_file(self.paths)
58 files = self.obj.get_files()
59 self.assertEqual(files, self.paths)
60
61 def test_empty_parser(self):
62 self.failUnlessRaises(Exception, self.obj.parser)
63
64 def test_parser(self):
65 self.obj.add_file(self.filepath)
66 parser = self.obj.parser()
67 self.assertTrue(isinstance(parser, ConfigParser.ConfigParser))
68
69 def test_parser_error(self):
70 self.failUnlessRaises(NoFilesToLoadException, self.obj.parser)
71
72 def test_set_directory(self):
73 self.obj.set_directory(self.path)
74 dir = self.obj.get_directory()
75 self.assertEqual(dir, self.path)
76
77 def test_invalid_directory(self):
78 self.failUnlessRaises(InvalidDirectoryException,
79 self.obj.set_directory, self.filepath)
80
81 def test_directory_does_not_exist(self):
82 path = os.path.join(self.path, 'nowayjose')
83 self.failUnlessRaises(DirectoryDoesNotExistException,
84 self.obj.set_directory, path)
85
86 def test_load(self):
87 self.obj.set_directory(self.path)
88 self.obj.load(self.filename)
89 check = [self.filepath]
90 self.assertEqual(check, self.obj.get_files())
91
92 def test_no_directory_set(self):
93 self.failUnlessRaises(DirectoryNotSetException,
94 self.obj.load, self.filename)
95
96 def test_reset_parser(self):
97 self.obj.add_file(self.filepath)
98 self.obj.parser()
99 self.obj.add_file(self.paths)
100 self.obj.parser()
101 self.assertEqual(self.obj.files_loaded, self.obj.get_files())