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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# Copyright (C) 2010 Leonard Thomas
#
# This file is part of Dodai.
#
# Dodai is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Dodai is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Dodai. If not, see <http://www.gnu.org/licenses/>.
import sys
import os
import unittest
path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..'))
sys.path.append(path)
from dodai.tools import home_directory
from dodai.tools import config_directory_system
from dodai.tools import config_directory_user
from dodai.tools import config_directory_project
from dodai.tools import config_directories
from dodai.tools import list_to_english
from dodai.tools import Section
from dodai.tools import normalize_unicode
from dodai.tools import quote_list
class TestTools(unittest.TestCase):
def setUp(self):
self.project_name = 'foo'
def test_home_directory(self):
try:
from win32com.shell import shellcon, shell
except ImportError:
dir = os.path.expanduser("~")
else:
dir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
self.assertEquals(dir, home_directory())
def test_config_directory_system(self):
config_directory_system()
def test_config_directory_user(self):
project_dir = '.{0}'.format(self.project_name)
project_dir = os.path.join(home_directory(), project_dir)
data = config_directory_user(self.project_name)
self.assertEquals(data, project_dir)
def test_config_directory_project(self):
config_directory_project()
def test_config_directories(self):
config_directories(self.project_name)
def test_list_to_english_one(self):
data = [1, 2, 3, 4, 5]
result = "1, 2, 3, 4 and 5"
self.assertEquals(result, list_to_english(data))
def test_list_to_english_two(self):
data = [1, 2]
result = "1 and 2"
self.assertEquals(result, list_to_english(data))
def test_section_one(self):
title = 'bar'
sec = Section(title)
self.assertEquals(title, sec.get_section_title())
def test_section_two(self):
title = 'bar'
sec = Section(title)
sec['el'] = 'hey'
self.assertEquals('hey', sec['el'])
def test_normalize_unicode(self):
a = u'\u212b'
b = u'\xc5'
a = normalize_unicode(a)
self.assertEquals(a, b)
def test_quote_list_one(self):
a = ['a', 'b', 'c']
b = ['"a"', '"b"', '"c"']
self.assertEquals(b, quote_list(a, True))
def test_quote_list_two(self):
a = ['a', 'b', 'c']
b = ["'a'", "'b'", "'c'"]
self.assertEquals(b, quote_list(a))
|