|
| 1 | +from algorithms.unix import ( |
| 2 | + join_with_slash, |
| 3 | + full_path, |
| 4 | + split |
| 5 | +) |
| 6 | +import os |
| 7 | +import unittest |
| 8 | +class TestUnixPath(unittest.TestCase): |
| 9 | + def test_join_with_slash(self): |
| 10 | + self.assertEqual("path/to/dir/file", join_with_slash("path/to/dir/", "file")) |
| 11 | + self.assertEqual("path/to/dir/file", join_with_slash("path/to/dir", "file")) |
| 12 | + self.assertEqual("http://algorithms/part", join_with_slash("http://algorithms", "part")) |
| 13 | + self.assertEqual("http://algorithms/part", join_with_slash("http://algorithms/", "part")) |
| 14 | + |
| 15 | + def test_full_path(self): |
| 16 | + file_name = "file_name" |
| 17 | + # Test full path relative |
| 18 | + expect_path = "{}/{}".format(os.getcwd(), file_name) |
| 19 | + self.assertEqual(expect_path, full_path(file_name)) |
| 20 | + # Test full path with expanding user |
| 21 | + # ~/file_name |
| 22 | + expect_path = "{}/{}".format(os.path.expanduser('~'), file_name) |
| 23 | + self.assertEqual(expect_path, full_path("~/{}".format(file_name))) |
| 24 | + |
| 25 | + def test_split(self): |
| 26 | + # Test url path |
| 27 | + path = "https://algorithms/unix/test.py" |
| 28 | + expect_result = split(path) |
| 29 | + self.assertEqual("https://algorithms/unix", expect_result[0]) |
| 30 | + self.assertEqual("test.py", expect_result[1]) |
| 31 | + # Test file path |
| 32 | + path = "algorithms/unix/test.py" |
| 33 | + expect_result = split(path) |
| 34 | + self.assertEqual("algorithms/unix", expect_result[0]) |
| 35 | + self.assertEqual("test.py", expect_result[1]) |
0 commit comments