Debian Codegraph @

rpython/rlib/test/test_rpath.py

raw symbols SCIP
1 import py
2 import os
3 from rpython.rlib import rpath
4
5 def test_rnormpath_posix():
6 assert rpath._posix_rnormpath('///foo') == '/foo'
7 assert rpath._posix_rnormpath("") == "."
8 assert rpath._posix_rnormpath("/") == "/"
9 assert rpath._posix_rnormpath("//") == "//"
10 assert rpath._posix_rnormpath("///") == "/"
11 assert rpath._posix_rnormpath("///foo/.//bar//") == "/foo/bar"
12 assert rpath._posix_rnormpath("///foo/.//bar//.//..//.//baz") == "/foo/baz"
13 assert rpath._posix_rnormpath("///..//./foo/.//bar") == "/foo/bar"
14
15 def test_rnormpath_nt():
16 assert rpath._nt_rnormpath('A//////././//.//B') == r'A\B'
17 assert rpath._nt_rnormpath('A/./B') == r'A\B'
18 assert rpath._nt_rnormpath('A/foo/../B') == r'A\B'
19 assert rpath._nt_rnormpath('C:A//B') == r'C:A\B'
20 assert rpath._nt_rnormpath('D:A/./B') == r'D:A\B'
21 assert rpath._nt_rnormpath('e:A/foo/../B') == r'e:A\B'
22 assert rpath._nt_rnormpath('C:///A//B') == r'C:\A\B'
23 assert rpath._nt_rnormpath('D:///A/./B') == r'D:\A\B'
24 assert rpath._nt_rnormpath('e:///A/foo/../B') == r'e:\A\B'
25 assert rpath._nt_rnormpath('..') == r'..'
26 assert rpath._nt_rnormpath('.') == r'.'
27 assert rpath._nt_rnormpath('') == r'.'
28 assert rpath._nt_rnormpath('/') == '\\'
29 assert rpath._nt_rnormpath('c:/') == 'c:\\'
30 assert rpath._nt_rnormpath('/../.././..') == '\\'
31 assert rpath._nt_rnormpath('c:/../../..') == 'c:\\'
32 assert rpath._nt_rnormpath('../.././..') == r'..\..\..'
33 assert rpath._nt_rnormpath('K:../.././..') == r'K:..\..\..'
34 assert rpath._nt_rnormpath('C:////a/b') == r'C:\a\b'
35 assert rpath._nt_rnormpath('//machine/share//a/b') == r'\\machine\share\a\b'
36 assert rpath._nt_rnormpath('\\\\.\\NUL') == r'\\.\NUL'
37 assert rpath._nt_rnormpath('\\\\?\\D:/XY\\Z') == r'\\?\D:/XY\Z'
38
39 def test_rabspath_relative(tmpdir):
40 tmpdir.chdir()
41 assert rpath.rabspath('foo') == os.path.realpath(str(tmpdir.join('foo')))
42
43 def test_rabspath_absolute_posix():
44 assert rpath._posix_rabspath('/foo') == '/foo'
45 assert rpath._posix_rabspath('/foo/bar/..') == '/foo'
46 assert rpath._posix_rabspath('/foo/bar/../x') == '/foo/x'
47
48 @py.test.mark.skipif("os.name == 'nt'")
49 def test_missing_current_dir(tmpdir):
50 tmpdir1 = str(tmpdir) + '/temporary_removed'
51 curdir1 = os.getcwd()
52 try:
53 os.mkdir(tmpdir1)
54 os.chdir(tmpdir1)
55 os.rmdir(tmpdir1)
56 result = rpath.rabspath('.')
57 finally:
58 os.chdir(curdir1)
59 assert result == '.'
60
61 def test_rsplitdrive_nt():
62 assert rpath._nt_rsplitdrive('D:\\FOO/BAR') == ('D:', '\\FOO/BAR')
63 assert rpath._nt_rsplitdrive('//') == ('', '//')
64
65 @py.test.mark.skipif("os.name != 'nt'")
66 def test_rabspath_absolute_nt():
67 assert rpath._nt_rabspath('d:\\foo') == 'd:\\foo'
68 assert rpath._nt_rabspath('d:\\foo\\bar\\..') == 'd:\\foo'
69 assert rpath._nt_rabspath('d:\\foo\\bar\\..\\x') == 'd:\\foo\\x'
70 curdrive = _ = rpath._nt_rsplitdrive(os.getcwd())
71 assert len(curdrive) == 2 and curdrive[0][1] == ':'
72 assert rpath.rabspath('\\foo') == '%s\\foo' % curdrive[0]
73
74 def test_risabs_posix():
75 assert rpath._posix_risabs('/foo/bar')
76 assert not rpath._posix_risabs('foo/bar')
77 assert not rpath._posix_risabs('\\foo\\bar')
78 assert not rpath._posix_risabs('C:\\foo\\bar')
79
80 def test_risabs_nt():
81 assert rpath._nt_risabs('/foo/bar')
82 assert not rpath._nt_risabs('foo/bar')
83 assert rpath._nt_risabs('\\foo\\bar')
84 assert rpath._nt_risabs('C:\\FOO')
85 assert not rpath._nt_risabs('C:FOO')
86
87 def test_risdir(tmpdir):
88 tmpdir = str(tmpdir)
89 assert rpath.risdir(tmpdir)
90 assert not rpath.risdir('_some_non_existant_file_')
91 assert not rpath.risdir(os.path.join(tmpdir, '_some_non_existant_file_'))