-
Notifications
You must be signed in to change notification settings - Fork 2
/
reverse_path_test.py
45 lines (33 loc) · 1.09 KB
/
reverse_path_test.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
from __future__ import print_function
import os
import shutil
import tempfile
import unittest
from reverse_path import reverse_path
class TestReversePath(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
os.chdir(self.tmpdir)
def tearDown(self):
shutil.rmtree(self.tmpdir)
def test_absolute(self):
self.assertEqual(self.tmpdir, reverse_path('/out'))
def test_relative(self):
os.mkdir('a')
os.mkdir('b')
self.assertEqual('..', reverse_path('a'))
os.chdir('a')
self.assertEqual('a', reverse_path('..'))
self.assertEqual('.', reverse_path('../a'))
self.assertEqual('../a', reverse_path('../b'))
def test_symlink(self):
os.mkdir('b')
os.symlink('b', 'a')
os.mkdir('b/d')
os.symlink('b/d', 'c')
self.assertEqual('..', reverse_path('a'))
self.assertEqual('..', reverse_path('b'))
self.assertEqual(self.tmpdir, reverse_path('c'))
self.assertEqual('../..', reverse_path('b/d'))
if __name__ == '__main__':
unittest.main()