aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSix <unknown>2010-05-20 19:46:54 -0400
committerSix <unknown>2010-05-20 19:46:54 -0400
commitf005d4af39cb2c870b009b8b564748a348b80b40 (patch)
treefbf49967b3f1423d54d709e02d577ea2d71efc64 /test
parente1cd280724290c8354f510922f8b13d3896d0e89 (diff)
downloaddodai-macsupport-f005d4af39cb2c870b009b8b564748a348b80b40.tar.bz2
dodai-macsupport-f005d4af39cb2c870b009b8b564748a348b80b40.tar.xz
dodai-macsupport-f005d4af39cb2c870b009b8b564748a348b80b40.zip
prepared for next release.
Diffstat (limited to 'test')
-rw-r--r--test/test_config/test_files.py135
-rw-r--r--test/test_config/test_sections.py156
-rw-r--r--test/test_dodai.py13
-rw-r--r--test/test_tools/test_init.py97
4 files changed, 314 insertions, 87 deletions
diff --git a/test/test_config/test_files.py b/test/test_config/test_files.py
new file mode 100644
index 0000000..7d32a07
--- /dev/null
+++ b/test/test_config/test_files.py
@@ -0,0 +1,135 @@
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 sys
19import os
20import unittest
21path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..'))
22sys.path.append(path)
23from ConfigParser import ConfigParser
24from ConfigParser import MissingSectionHeaderError
25from dodai.config.files import ConfigFiles
26from dodai.tools.odict import OrderedDict
27from dodai.tools.himo import String2Himo
28from dodai.tools import Section
29from dodai.exception import InvalidConfigParser
30from dodai.exception import FileDoesNotExist
31from dodai.exception import FileIsDirectory
32
33
34class GoodParser(object):
35
36 DATA = OrderedDict()
37 DATA['sec_a'] = OrderedDict()
38 DATA['sec_a']['opt_a'] = 'foo'
39 DATA['sec_a']['opt_b'] = 'bar'
40 DATA['sec_a']['opt_c'] = '1'
41 DATA['sec_a']['opt_d'] = '22'
42
43 DATA['sec_b'] = OrderedDict()
44 DATA['sec_b']['opt_a'] = 'lt'
45 DATA['sec_b']['opt_b'] = 'el'
46 DATA['sec_b']['opt_c'] = 'mg'
47 DATA['sec_b']['opt_d'] = 'ds'
48
49 def sections(self):
50 return self.DATA.keys()
51
52 def options(self, section):
53 return self.DATA[section].keys()
54
55 def get(self, section, option):
56 return self.DATA[section][option]
57
58 def read(self, filename):
59 return [filename]
60
61class BadParser(object):
62
63 DATA = OrderedDict()
64 DATA['sec_a'] = OrderedDict()
65 DATA['sec_a']['opt_a'] = 'foo'
66 DATA['sec_a']['opt_b'] = 'bar'
67 DATA['sec_a']['opt_c'] = '1'
68 DATA['sec_a']['opt_d'] = '22'
69
70 DATA['sec_b'] = OrderedDict()
71 DATA['sec_b']['opt_a'] = 'lt'
72 DATA['sec_b']['opt_b'] = 'el'
73 DATA['sec_b']['opt_c'] = 'mg'
74 DATA['sec_b']['opt_d'] = 'ds'
75
76 def sections(self):
77 return self.DATA.keys()
78
79 def get(self, section, option):
80 return self.DATA[section][option]
81
82 def read(self, filename):
83 return [filename]
84
85class TestFiles(unittest.TestCase):
86
87 def setUp(self):
88 s2h = String2Himo()
89 self.obj = ConfigFiles(OrderedDict, Section, s2h)
90
91 def test_good_parser(self):
92 self.obj.register_parser_object(GoodParser)
93
94 def test_bad_parser(self):
95 self.failUnlessRaises(InvalidConfigParser,
96 self.obj.register_parser_object,
97 BadParser)
98
99 def test_add(self):
100 filename = os.path.realpath(__file__)
101 self.obj.add(filename)
102 self.assertTrue(filename in self.obj.files)
103
104 def test_add_bad_file(self):
105 filename = os.path.dirname(os.path.realpath(__file__))
106 filename = os.path.join(filename, 'no_way_jose.234dasf2345')
107 self.failUnlessRaises(FileDoesNotExist,
108 self.obj.add,
109 filename)
110
111 def test_add_directory(self):
112 filename = os.path.dirname(os.path.realpath(__file__))
113 self.failUnlessRaises(FileIsDirectory,
114 self.obj.add,
115 filename)
116
117 def file_test_read(self):
118 filename = os.path.realpath(__file__)
119 self.obj.register_parser_object(GoodParser)
120 self.obj.add(filename)
121 sec = self.obj.load()
122
123 def test_bad_read(self):
124 self.obj.register_parser_object(ConfigParser)
125 filename = os.path.realpath(__file__)
126 self.obj.add(filename)
127 self.failUnlessRaises(MissingSectionHeaderError, self.obj.load)
128
129 def test_good_read_with_multiple_parsers(self):
130 self.obj.register_parser_object(ConfigParser)
131 self.obj.register_parser_object(GoodParser)
132 filename = os.path.realpath(__file__)
133 self.obj.add(filename)
134 sec = self.obj.load()
135
diff --git a/test/test_config/test_sections.py b/test/test_config/test_sections.py
index 39b41a7..2ca7e4f 100644
--- a/test/test_config/test_sections.py
+++ b/test/test_config/test_sections.py
@@ -17,101 +17,91 @@
17 17
18import sys 18import sys
19import os 19import os
20import ConfigParser
21import unittest 20import unittest
22path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..')) 21path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..'))
23sys.path.append(path) 22sys.path.append(path)
23from dodai.config.sections import ConfigSections
24from dodai.tools.himo import Himo 24from dodai.tools.himo import Himo
25from dodai.tools.himo import String2Himo 25from dodai.tools.himo import String2Himo
26from dodai.config.sections import ConfigSections 26from dodai.tools.odict import OrderedDict
27from dodai.tools import Section
28
29class Parser(object):
30
31 DATA = OrderedDict()
32 DATA['sec_a'] = OrderedDict()
33 DATA['sec_a']['opt_a'] = 'foo'
34 DATA['sec_a']['opt_b'] = 'bar'
35 DATA['sec_a']['opt_c'] = '1'
36 DATA['sec_a']['opt_d'] = '22'
37
38 DATA['sec_b'] = OrderedDict()
39 DATA['sec_b']['opt_a'] = 'lt'
40 DATA['sec_b']['opt_b'] = 'el'
41 DATA['sec_b']['opt_c'] = 'mg'
42 DATA['sec_b']['opt_d'] = 'ds'
43
44 def sections(self):
45 return self.DATA.keys()
46
47 def options(self, section):
48 return self.DATA[section].keys()
49
50 def get(self, section, option):
51 return self.DATA[section][option]
27 52
28 53
29class TestSections(unittest.TestCase): 54class TestSections(unittest.TestCase):
30 55
31 def setUp(self): 56 def setUp(self):
32 path = os.path.dirname(__file__) 57 s2h = String2Himo()
33 filepath = os.path.join(path, 'config.cfg') 58 self.obj = ConfigSections(OrderedDict, Section, s2h)
34 self.parser = ConfigParser.ConfigParser() 59 self.parser = Parser()
35 self.parser.readfp(open(filepath))
36 self.sections = ConfigSections(String2Himo())
37 60
38 def test_call(self): 61 def test_call(self):
39 self.sections(self.parser) 62 self.obj(self.parser)
40 count = len(self.parser.sections()) 63
41 self.assertEqual(count, len(self.sections)) 64 def test_two(self):
42 65 self.obj(self.parser)
43 def test_iterator(self): 66 key = String2Himo('sec_a')
44 result = True 67 self.obj.__getitem__('sec_a')
45 for section in self.sections: 68 self.obj.sec_a
46 if not section.get_title() in self.parser.sections(): 69
47 result = False 70 def test_results_one(self):
48 self.assertTrue(result==True) 71 self.obj(self.parser)
49 72 for section in self.obj.keys():
50 def test_get_section(self): 73 self.assertTrue(section in self.parser.sections())
51 self.sections(self.parser) 74
52 self.sections(self.parser) 75 def test_results_two(self):
53 check = self.sections.get_section('test_db') 76 self.obj(self.parser)
54 self.assertEqual(check.get_title(), 'test_db') 77 for section, data in self.obj.items():
55 78 for key in data.keys():
56 def test_build_string_object(self): 79 self.assertTrue(key in self.parser.options(section))
57 sections = ConfigSections() 80
58 sections(self.parser) 81 def test_results_three(self):
59 count = len(self.parser.sections()) 82 self.obj(self.parser)
60 self.assertEqual(count, len(sections)) 83 for section, data in self.obj.items():
61 84 for option, val in data.items():
62 def test_getitem(self): 85 self.assertTrue(val, self.parser.get(section, option))
63 self.sections(self.parser) 86
64 title = self.sections['test_db'].get_title() 87 def test_results_four(self):
65 self.assertEqual(title, 'test_db') 88 self.obj(self.parser)
66 89 for section in self.parser.sections():
67 def test_getattr(self): 90 self.assertTrue(section in self.obj)
68 self.sections(self.parser) 91
69 title = self.sections.test_db.get_title() 92 def test_results_five(self):
70 self.assertEqual(title, 'test_db') 93 self.obj(self.parser)
71 94 for section in self.parser.sections():
72 def test_get_keys(self): 95 for option in self.parser.options(section):
73 self.sections(self.parser) 96 self.assertTrue(option in self.obj[section])
74 keys = self.sections.keys() 97
75 self.assertTrue(len(keys)) 98 def test_results_six(self):
76 99 self.obj(self.parser)
77 def test_section_object_one(self): 100 for section in self.parser.sections():
78 self.sections(self.parser) 101 for option in self.parser.options(section):
79 keys = self.sections.test_db.keys() 102 val = self.parser.get(section, option)
80 self.assertTrue(len(keys)) 103 self.assertEquals(val, self.obj[section][option])
81 104
82 def test_section_object_two(self):
83 self.sections(self.parser)
84 keys = self.sections.test_db.___options___.keys()
85 self.assertTrue(len(keys))
86
87 def test_section_object_three(self):
88 self.sections(self.parser)
89 self.sections.test_db.___blah___ = 'test'
90 val = self.sections.test_db.__getattr__('___blah___')
91 self.assertTrue(val == 'test')
92
93 def test_section_object_four(self):
94 self.sections(self.parser)
95 self.sections.test_db.foo = 'bar'
96 val = self.sections.test_db.__getattr__('foo')
97 self.assertTrue(val == 'bar')
98
99 def test_section_object_five(self):
100 self.sections(self.parser)
101 keys = []
102 for key in self.sections.test_db:
103 keys.append(key)
104 self.assertTrue(keys)
105
106 def test_section_object_six(self):
107 self.sections(self.parser)
108 self.sections.test_db.foo = 'bar'
109 val = self.sections.test_db['foo']
110 self.assertTrue(val == 'bar')
111
112 def test_section_object_seven(self):
113 self.sections(self.parser, 'unicode_escape')
114 self.assertEqual(self.sections.extra.name, u'\u8c61')
115 105
116 106
117if __name__ == '__main__': 107if __name__ == '__main__':
diff --git a/test/test_dodai.py b/test/test_dodai.py
index b95f71f..fbd4667 100644
--- a/test/test_dodai.py
+++ b/test/test_dodai.py
@@ -15,8 +15,11 @@
15# You should have received a copy of the GNU General Public License 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/>. 16# along with Dodai. If not, see <http://www.gnu.org/licenses/>.
17 17
18import unittest 18import sys
19import os 19import os
20import unittest
21path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
22sys.path.append(path)
20from dodai import Configure 23from dodai import Configure
21 24
22class TestConfigure(unittest.TestCase): 25class TestConfigure(unittest.TestCase):
@@ -29,11 +32,13 @@ class TestConfigure(unittest.TestCase):
29 self.obj = Configure('test472j02ju-sfgj', config_files=[filename]) 32 self.obj = Configure('test472j02ju-sfgj', config_files=[filename])
30 33
31 def test_results(self): 34 def test_results(self):
32 files = self.obj.files._files 35 files = self.obj.files.files
33 print files
34 self.assertTrue(len(files) == 1) 36 self.assertTrue(len(files) == 1)
35 37
36 def test_add_files(self): 38 def test_add_files(self):
37 self.obj._add_files(self.filename) 39 self.obj._add_files(self.filename)
38 files = self.obj.files._files 40 files = self.obj.files.files
39 self.assertTrue(len(files) == 1) 41 self.assertTrue(len(files) == 1)
42
43
44
diff --git a/test/test_tools/test_init.py b/test/test_tools/test_init.py
new file mode 100644
index 0000000..16d7dda
--- /dev/null
+++ b/test/test_tools/test_init.py
@@ -0,0 +1,97 @@
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 sys
19import os
20import unittest
21path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..'))
22sys.path.append(path)
23from dodai.tools import home_directory
24from dodai.tools import config_directory_system
25from dodai.tools import config_directory_user
26from dodai.tools import config_directory_project
27from dodai.tools import config_directories
28from dodai.tools import list_to_english
29from dodai.tools import Section
30from dodai.tools import normalize_unicode
31from dodai.tools import quote_list
32
33class TestTools(unittest.TestCase):
34
35 def setUp(self):
36 self.project_name = 'foo'
37
38 def test_home_directory(self):
39 try:
40 from win32com.shell import shellcon, shell
41 except ImportError:
42 dir = os.path.expanduser("~")
43 else:
44 dir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
45 self.assertEquals(dir, home_directory())
46
47 def test_config_directory_system(self):
48 config_directory_system()
49
50 def test_config_directory_user(self):
51 project_dir = '.{0}'.format(self.project_name)
52 project_dir = os.path.join(home_directory(), project_dir)
53 data = config_directory_user(self.project_name)
54 self.assertEquals(data, project_dir)
55
56 def test_config_directory_project(self):
57 config_directory_project()
58
59 def test_config_directories(self):
60 config_directories(self.project_name)
61
62 def test_list_to_english_one(self):
63 data = [1, 2, 3, 4, 5]
64 result = "1, 2, 3, 4 and 5"
65 self.assertEquals(result, list_to_english(data))
66
67 def test_list_to_english_two(self):
68 data = [1, 2]
69 result = "1 and 2"
70 self.assertEquals(result, list_to_english(data))
71
72 def test_section_one(self):
73 title = 'bar'
74 sec = Section(title)
75 self.assertEquals(title, sec.get_section_title())
76
77 def test_section_two(self):
78 title = 'bar'
79 sec = Section(title)
80 sec['el'] = 'hey'
81 self.assertEquals('hey', sec['el'])
82
83 def test_normalize_unicode(self):
84 a = u'\u212b'
85 b = u'\xc5'
86 a = normalize_unicode(a)
87 self.assertEquals(a, b)
88
89 def test_quote_list_one(self):
90 a = ['a', 'b', 'c']
91 b = ['"a"', '"b"', '"c"']
92 self.assertEquals(b, quote_list(a, True))
93
94 def test_quote_list_two(self):
95 a = ['a', 'b', 'c']
96 b = ["'a'", "'b'", "'c'"]
97 self.assertEquals(b, quote_list(a))