-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtest_path_helper.py
46 lines (41 loc) · 1.56 KB
/
test_path_helper.py
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
# -*- encoding: utf-8 -*-
import os
import sys
import unittest
from FileManager.libs.pathhelper import computer_friendly, user_friendly
class PathHelperTest(unittest.TestCase):
def test_computer_friendly(self):
home = os.path.expanduser("~")
tests = [
("~", home),
("~/", home + os.path.sep),
("~/hello/world", os.path.sep.join([home, "hello", "world"])),
(
"~/hello/world/",
os.path.sep.join([home, "hello", "world"]) + os.path.sep,
),
("C:/hello/~/hi", os.path.sep.join([home, "hi"])),
("C:/hello/~/hi/~/yep", os.path.sep.join([home, "yep"])),
("C:/hello/~/hi/C:/hello/yep", os.path.sep.join(["C:", "hello", "yep"])),
("/hello/C:/hi/~/hey", os.path.sep.join([home, "hey"])),
("\\\\shared\\folder", "\\\\shared\\folder"),
(
"C:/courses/sublime text 3/",
os.path.sep.join(["C:", "courses", "sublime text 3", ""]),
),
]
for base, result in tests:
if result is None:
result = base
self.assertEqual(computer_friendly(base), result)
def test_user_friendly(self):
home = os.path.expanduser("~")
tests = [
(home, "~"),
("C:/courses/sublime text 3/", None),
("C:/courses/sublime text 3/", None),
]
for base, result in tests:
if result is None:
result = base
self.assertEqual(user_friendly(base), result)