diff options
Diffstat (limited to 'test/test_tools/test_init.py')
-rw-r--r-- | test/test_tools/test_init.py | 97 |
1 files changed, 97 insertions, 0 deletions
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 | |||
18 | import sys | ||
19 | import os | ||
20 | import unittest | ||
21 | path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..')) | ||
22 | sys.path.append(path) | ||
23 | from dodai.tools import home_directory | ||
24 | from dodai.tools import config_directory_system | ||
25 | from dodai.tools import config_directory_user | ||
26 | from dodai.tools import config_directory_project | ||
27 | from dodai.tools import config_directories | ||
28 | from dodai.tools import list_to_english | ||
29 | from dodai.tools import Section | ||
30 | from dodai.tools import normalize_unicode | ||
31 | from dodai.tools import quote_list | ||
32 | |||
33 | class 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)) | ||