forked from keon/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_unix.py
42 lines (39 loc) · 1.74 KB
/
test_unix.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
from algorithms.unix import (
join_with_slash,
full_path,
split,
simplify_path_v1, simplify_path_v2
)
import os
import unittest
class TestUnixPath(unittest.TestCase):
def test_join_with_slash(self):
self.assertEqual("path/to/dir/file", join_with_slash("path/to/dir/", "file"))
self.assertEqual("path/to/dir/file", join_with_slash("path/to/dir", "file"))
self.assertEqual("http://algorithms/part", join_with_slash("http://algorithms", "part"))
self.assertEqual("http://algorithms/part", join_with_slash("http://algorithms/", "part"))
def test_full_path(self):
file_name = "file_name"
# Test full path relative
expect_path = "{}/{}".format(os.getcwd(), file_name)
self.assertEqual(expect_path, full_path(file_name))
# Test full path with expanding user
# ~/file_name
expect_path = "{}/{}".format(os.path.expanduser('~'), file_name)
self.assertEqual(expect_path, full_path("~/{}".format(file_name)))
def test_split(self):
# Test url path
path = "https://algorithms/unix/test.py"
expect_result = split(path)
self.assertEqual("https://algorithms/unix", expect_result[0])
self.assertEqual("test.py", expect_result[1])
# Test file path
path = "algorithms/unix/test.py"
expect_result = split(path)
self.assertEqual("algorithms/unix", expect_result[0])
self.assertEqual("test.py", expect_result[1])
def test_simplify_path(self):
self.assertEqual("/", simplify_path_v1("/../"))
self.assertEqual("/home/foo", simplify_path_v1("/home//foo/"))
self.assertEqual("/", simplify_path_v2("/../"))
self.assertEqual("/home/foo", simplify_path_v2("/home//foo/"))