本文整理汇总了Python中test.support.can_symlink函数的典型用法代码示例。如果您正苦于以下问题:Python can_symlink函数的具体用法?Python can_symlink怎么用?Python can_symlink使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了can_symlink函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_recursive_glob
def test_recursive_glob(self):
eq = self.assertSequencesEqual_noorder
full = [('ZZZ',),
('a',), ('a', 'D'),
('a', 'bcd'),
('a', 'bcd', 'EF'),
('a', 'bcd', 'efg'),
('a', 'bcd', 'efg', 'ha'),
('aaa',), ('aaa', 'zzzF'),
('aab',), ('aab', 'F'),
]
if can_symlink():
full += [('sym1',), ('sym2',),
('sym3',),
('sym3', 'EF'),
('sym3', 'efg'),
('sym3', 'efg', 'ha'),
]
eq(self.rglob('**'), self.joins(('',), *full))
eq(self.rglob('.', '**'), self.joins(('.',''),
*(('.',) + i for i in full)))
dirs = [('a', ''), ('a', 'bcd', ''), ('a', 'bcd', 'efg', ''),
('aaa', ''), ('aab', '')]
if can_symlink():
dirs += [('sym3', ''), ('sym3', 'efg', '')]
eq(self.rglob('**', ''), self.joins(('',), *dirs))
eq(self.rglob('a', '**'), self.joins(
('a', ''), ('a', 'D'), ('a', 'bcd'), ('a', 'bcd', 'EF'),
('a', 'bcd', 'efg'), ('a', 'bcd', 'efg', 'ha')))
eq(self.rglob('a**'), self.joins(('a',), ('aaa',), ('aab',)))
expect = [('a', 'bcd', 'EF')]
if can_symlink():
expect += [('sym3', 'EF')]
eq(self.rglob('**', 'EF'), self.joins(*expect))
expect = [('a', 'bcd', 'EF'), ('aaa', 'zzzF'), ('aab', 'F')]
if can_symlink():
expect += [('sym3', 'EF')]
eq(self.rglob('**', '*F'), self.joins(*expect))
eq(self.rglob('**', '*F', ''), [])
eq(self.rglob('**', 'bcd', '*'), self.joins(
('a', 'bcd', 'EF'), ('a', 'bcd', 'efg')))
eq(self.rglob('a', '**', 'bcd'), self.joins(('a', 'bcd')))
predir = os.path.abspath(os.curdir)
try:
os.chdir(self.tempdir)
join = os.path.join
eq(glob.glob('**', recursive=True), [join(*i) for i in full])
eq(glob.glob(join('**', ''), recursive=True),
[join(*i) for i in dirs])
eq(glob.glob(join('**','zz*F'), recursive=True),
[join('aaa', 'zzzF')])
eq(glob.glob('**zz*F', recursive=True), [])
expect = [join('a', 'bcd', 'EF')]
if can_symlink():
expect += [join('sym3', 'EF')]
eq(glob.glob(join('**', 'EF'), recursive=True), expect)
finally:
os.chdir(predir)
示例2: test_recursive_glob
def test_recursive_glob(self):
eq = self.assertSequencesEqual_noorder
full = [
("ZZZ",),
("a",),
("a", "D"),
("a", "bcd"),
("a", "bcd", "EF"),
("a", "bcd", "efg"),
("a", "bcd", "efg", "ha"),
("aaa",),
("aaa", "zzzF"),
("aab",),
("aab", "F"),
]
if can_symlink():
full += [("sym1",), ("sym2",), ("sym3",), ("sym3", "EF"), ("sym3", "efg"), ("sym3", "efg", "ha")]
eq(self.rglob("**"), self.joins(("",), *full))
eq(self.rglob(".", "**"), self.joins((".", ""), *((".",) + i for i in full)))
dirs = [("a", ""), ("a", "bcd", ""), ("a", "bcd", "efg", ""), ("aaa", ""), ("aab", "")]
if can_symlink():
dirs += [("sym3", ""), ("sym3", "efg", "")]
eq(self.rglob("**", ""), self.joins(("",), *dirs))
eq(
self.rglob("a", "**"),
self.joins(
("a", ""), ("a", "D"), ("a", "bcd"), ("a", "bcd", "EF"), ("a", "bcd", "efg"), ("a", "bcd", "efg", "ha")
),
)
eq(self.rglob("a**"), self.joins(("a",), ("aaa",), ("aab",)))
expect = [("a", "bcd", "EF")]
if can_symlink():
expect += [("sym3", "EF")]
eq(self.rglob("**", "EF"), self.joins(*expect))
expect = [("a", "bcd", "EF"), ("aaa", "zzzF"), ("aab", "F")]
if can_symlink():
expect += [("sym3", "EF")]
eq(self.rglob("**", "*F"), self.joins(*expect))
eq(self.rglob("**", "*F", ""), [])
eq(self.rglob("**", "bcd", "*"), self.joins(("a", "bcd", "EF"), ("a", "bcd", "efg")))
eq(self.rglob("a", "**", "bcd"), self.joins(("a", "bcd")))
predir = os.path.abspath(os.curdir)
try:
os.chdir(self.tempdir)
join = os.path.join
eq(glob.glob("**", recursive=True), [join(*i) for i in full])
eq(glob.glob(join("**", ""), recursive=True), [join(*i) for i in dirs])
eq(glob.glob(join("**", "zz*F"), recursive=True), [join("aaa", "zzzF")])
eq(glob.glob("**zz*F", recursive=True), [])
expect = [join("a", "bcd", "EF")]
if can_symlink():
expect += [join("sym3", "EF")]
eq(glob.glob(join("**", "EF"), recursive=True), expect)
finally:
os.chdir(predir)
示例3: setUp
def setUp(self):
BaseTestCase.setUp(self)
self.cwd = os.getcwd()
self.parent_dir = tempfile.mkdtemp()
self.cgi_dir = os.path.join(self.parent_dir, 'cgi-bin')
self.cgi_child_dir = os.path.join(self.cgi_dir, 'child-dir')
os.mkdir(self.cgi_dir)
os.mkdir(self.cgi_child_dir)
self.nocgi_path = None
self.file1_path = None
self.file2_path = None
self.file3_path = None
self.file4_path = None
# The shebang line should be pure ASCII: use symlink if possible.
# See issue #7668.
if support.can_symlink():
self.pythonexe = os.path.join(self.parent_dir, 'python')
os.symlink(sys.executable, self.pythonexe)
else:
self.pythonexe = sys.executable
try:
# The python executable path is written as the first line of the
# CGI Python script. The encoding cookie cannot be used, and so the
# path should be encodable to the default script encoding (utf-8)
self.pythonexe.encode('utf-8')
except UnicodeEncodeError:
self.tearDown()
self.skipTest("Python executable path is not encodable to utf-8")
self.nocgi_path = os.path.join(self.parent_dir, 'nocgi.py')
with open(self.nocgi_path, 'w') as fp:
fp.write(cgi_file1 % self.pythonexe)
os.chmod(self.nocgi_path, 0o777)
self.file1_path = os.path.join(self.cgi_dir, 'file1.py')
with open(self.file1_path, 'w', encoding='utf-8') as file1:
file1.write(cgi_file1 % self.pythonexe)
os.chmod(self.file1_path, 0o777)
self.file2_path = os.path.join(self.cgi_dir, 'file2.py')
with open(self.file2_path, 'w', encoding='utf-8') as file2:
file2.write(cgi_file2 % self.pythonexe)
os.chmod(self.file2_path, 0o777)
self.file3_path = os.path.join(self.cgi_child_dir, 'file3.py')
with open(self.file3_path, 'w', encoding='utf-8') as file3:
file3.write(cgi_file1 % self.pythonexe)
os.chmod(self.file3_path, 0o777)
self.file4_path = os.path.join(self.cgi_dir, 'file4.py')
with open(self.file4_path, 'w', encoding='utf-8') as file4:
file4.write(cgi_file4 % (self.pythonexe, 'QUERY_STRING'))
os.chmod(self.file4_path, 0o777)
os.chdir(self.parent_dir)
示例4: setUp
def setUp(self):
self.tempdir = TESTFN+"_dir"
self.mktemp('a', 'D')
self.mktemp('aab', 'F')
self.mktemp('aaa', 'zzzF')
self.mktemp('ZZZ')
self.mktemp('a', 'bcd', 'EF')
self.mktemp('a', 'bcd', 'efg', 'ha')
if can_symlink():
os.symlink(self.norm('broken'), self.norm('sym1'))
os.symlink(self.norm('broken'), self.norm('sym2'))
示例5: setUp
def setUp(self):
self.tempdir = TESTFN + "_dir"
self.mktemp("a", "D")
self.mktemp("aab", "F")
self.mktemp("aaa", "zzzF")
self.mktemp("ZZZ")
self.mktemp("a", "bcd", "EF")
self.mktemp("a", "bcd", "efg", "ha")
if can_symlink():
os.symlink(self.norm("broken"), self.norm("sym1"))
os.symlink(self.norm("broken"), self.norm("sym2"))
示例6: test_islink
def test_islink(self):
self.assertIs(posixpath.islink(support.TESTFN + "1"), False)
self.assertIs(posixpath.lexists(support.TESTFN + "2"), False)
with open(support.TESTFN + "1", "wb") as f:
f.write(b"foo")
self.assertIs(posixpath.islink(support.TESTFN + "1"), False)
if support.can_symlink():
os.symlink(support.TESTFN + "1", support.TESTFN + "2")
self.assertIs(posixpath.islink(support.TESTFN + "2"), True)
os.remove(support.TESTFN + "1")
self.assertIs(posixpath.islink(support.TESTFN + "2"), True)
self.assertIs(posixpath.exists(support.TESTFN + "2"), False)
self.assertIs(posixpath.lexists(support.TESTFN + "2"), True)
示例7: test_islink
def test_islink(self):
self.assertIs(posixpath.islink(support.TESTFN + "1"), False)
f = open(support.TESTFN + "1", "wb")
try:
f.write(b"foo")
f.close()
self.assertIs(posixpath.islink(support.TESTFN + "1"), False)
if support.can_symlink():
os.symlink(support.TESTFN + "1", support.TESTFN + "2")
self.assertIs(posixpath.islink(support.TESTFN + "2"), True)
os.remove(support.TESTFN + "1")
self.assertIs(posixpath.islink(support.TESTFN + "2"), True)
self.assertIs(posixpath.exists(support.TESTFN + "2"), False)
self.assertIs(posixpath.lexists(support.TESTFN + "2"), True)
finally:
if not f.close():
f.close()
示例8: setUp
def setUp(self):
BaseTestCase.setUp(self)
self.cwd = os.getcwd()
self.parent_dir = tempfile.mkdtemp()
self.cgi_dir = os.path.join(self.parent_dir, "cgi-bin")
os.mkdir(self.cgi_dir)
self.file1_path = None
self.file2_path = None
# The shebang line should be pure ASCII: use symlink if possible.
# See issue #7668.
if support.can_symlink():
self.pythonexe = os.path.join(self.parent_dir, "python")
os.symlink(sys.executable, self.pythonexe)
else:
self.pythonexe = sys.executable
try:
# The python executable path is written as the first line of the
# CGI Python script. The encoding cookie cannot be used, and so the
# path should be encodable to the default script encoding (utf-8)
self.pythonexe.encode("utf-8")
except UnicodeEncodeError:
self.tearDown()
raise self.skipTest("Python executable path is not encodable to utf-8")
self.file1_path = os.path.join(self.cgi_dir, "file1.py")
with open(self.file1_path, "w", encoding="utf-8") as file1:
file1.write(cgi_file1 % self.pythonexe)
os.chmod(self.file1_path, 0o777)
self.file2_path = os.path.join(self.cgi_dir, "file2.py")
with open(self.file2_path, "w", encoding="utf-8") as file2:
file2.write(cgi_file2 % self.pythonexe)
os.chmod(self.file2_path, 0o777)
os.chdir(self.parent_dir)
示例9: test_traversal
def test_traversal(self):
import os
from os.path import join
# Build:
# TESTFN/
# TEST1/ a file kid and two directory kids
# tmp1
# SUB1/ a file kid and a directory kid
# tmp2
# SUB11/ no kids
# SUB2/ a file kid and a dirsymlink kid
# tmp3
# link/ a symlink to TESTFN.2
# TEST2/
# tmp4 a lone file
walk_path = join(support.TESTFN, "TEST1")
sub1_path = join(walk_path, "SUB1")
sub11_path = join(sub1_path, "SUB11")
sub2_path = join(walk_path, "SUB2")
tmp1_path = join(walk_path, "tmp1")
tmp2_path = join(sub1_path, "tmp2")
tmp3_path = join(sub2_path, "tmp3")
link_path = join(sub2_path, "link")
t2_path = join(support.TESTFN, "TEST2")
tmp4_path = join(support.TESTFN, "TEST2", "tmp4")
# Create stuff.
os.makedirs(sub11_path)
os.makedirs(sub2_path)
os.makedirs(t2_path)
for path in tmp1_path, tmp2_path, tmp3_path, tmp4_path:
f = open(path, "w")
f.write("I'm " + path + " and proud of it. Blame test_os.\n")
f.close()
if support.can_symlink():
os.symlink(os.path.abspath(t2_path), link_path)
sub2_tree = (sub2_path, ["link"], ["tmp3"])
else:
sub2_tree = (sub2_path, [], ["tmp3"])
# Walk top-down.
all = list(os.walk(walk_path))
self.assertEqual(len(all), 4)
# We can't know which order SUB1 and SUB2 will appear in.
# Not flipped: TESTFN, SUB1, SUB11, SUB2
# flipped: TESTFN, SUB2, SUB1, SUB11
flipped = all[0][1][0] != "SUB1"
all[0][1].sort()
self.assertEqual(all[0], (walk_path, ["SUB1", "SUB2"], ["tmp1"]))
self.assertEqual(all[1 + flipped], (sub1_path, ["SUB11"], ["tmp2"]))
self.assertEqual(all[2 + flipped], (sub11_path, [], []))
self.assertEqual(all[3 - 2 * flipped], sub2_tree)
# Prune the search.
all = []
for root, dirs, files in os.walk(walk_path):
all.append((root, dirs, files))
# Don't descend into SUB1.
if 'SUB1' in dirs:
# Note that this also mutates the dirs we appended to all!
dirs.remove('SUB1')
self.assertEqual(len(all), 2)
self.assertEqual(all[0], (walk_path, ["SUB2"], ["tmp1"]))
self.assertEqual(all[1], sub2_tree)
# Walk bottom-up.
all = list(os.walk(walk_path, topdown=False))
self.assertEqual(len(all), 4)
# We can't know which order SUB1 and SUB2 will appear in.
# Not flipped: SUB11, SUB1, SUB2, TESTFN
# flipped: SUB2, SUB11, SUB1, TESTFN
flipped = all[3][1][0] != "SUB1"
all[3][1].sort()
self.assertEqual(all[3], (walk_path, ["SUB1", "SUB2"], ["tmp1"]))
self.assertEqual(all[flipped], (sub11_path, [], []))
self.assertEqual(all[flipped + 1], (sub1_path, ["SUB11"], ["tmp2"]))
self.assertEqual(all[2 - 2 * flipped], sub2_tree)
if support.can_symlink():
# Walk, following symlinks.
for root, dirs, files in os.walk(walk_path, followlinks=True):
if root == link_path:
self.assertEqual(dirs, [])
self.assertEqual(files, ["tmp4"])
break
else:
self.fail("Didn't follow symlink with followlinks=True")
示例10: test_recursive_glob
def test_recursive_glob(self):
eq = self.assertSequencesEqual_noorder
full = [
("EF",),
("ZZZ",),
("a",),
("a", "D"),
("a", "bcd"),
("a", "bcd", "EF"),
("a", "bcd", "efg"),
("a", "bcd", "efg", "ha"),
("aaa",),
("aaa", "zzzF"),
("aab",),
("aab", "F"),
]
if can_symlink():
full += [("sym1",), ("sym2",), ("sym3",), ("sym3", "EF"), ("sym3", "efg"), ("sym3", "efg", "ha")]
eq(self.rglob("**"), self.joins(("",), *full))
eq(self.rglob(os.curdir, "**"), self.joins((os.curdir, ""), *((os.curdir,) + i for i in full)))
dirs = [("a", ""), ("a", "bcd", ""), ("a", "bcd", "efg", ""), ("aaa", ""), ("aab", "")]
if can_symlink():
dirs += [("sym3", ""), ("sym3", "efg", "")]
eq(self.rglob("**", ""), self.joins(("",), *dirs))
eq(
self.rglob("a", "**"),
self.joins(
("a", ""), ("a", "D"), ("a", "bcd"), ("a", "bcd", "EF"), ("a", "bcd", "efg"), ("a", "bcd", "efg", "ha")
),
)
eq(self.rglob("a**"), self.joins(("a",), ("aaa",), ("aab",)))
expect = [("a", "bcd", "EF"), ("EF",)]
if can_symlink():
expect += [("sym3", "EF")]
eq(self.rglob("**", "EF"), self.joins(*expect))
expect = [("a", "bcd", "EF"), ("aaa", "zzzF"), ("aab", "F"), ("EF",)]
if can_symlink():
expect += [("sym3", "EF")]
eq(self.rglob("**", "*F"), self.joins(*expect))
eq(self.rglob("**", "*F", ""), [])
eq(self.rglob("**", "bcd", "*"), self.joins(("a", "bcd", "EF"), ("a", "bcd", "efg")))
eq(self.rglob("a", "**", "bcd"), self.joins(("a", "bcd")))
with change_cwd(self.tempdir):
join = os.path.join
eq(glob.glob("**", recursive=True), [join(*i) for i in full])
eq(glob.glob(join("**", ""), recursive=True), [join(*i) for i in dirs])
eq(glob.glob(join("**", "*"), recursive=True), [join(*i) for i in full])
eq(
glob.glob(join(os.curdir, "**"), recursive=True),
[join(os.curdir, "")] + [join(os.curdir, *i) for i in full],
)
eq(
glob.glob(join(os.curdir, "**", ""), recursive=True),
[join(os.curdir, "")] + [join(os.curdir, *i) for i in dirs],
)
eq(glob.glob(join(os.curdir, "**", "*"), recursive=True), [join(os.curdir, *i) for i in full])
eq(glob.glob(join("**", "zz*F"), recursive=True), [join("aaa", "zzzF")])
eq(glob.glob("**zz*F", recursive=True), [])
expect = [join("a", "bcd", "EF"), "EF"]
if can_symlink():
expect += [join("sym3", "EF")]
eq(glob.glob(join("**", "EF"), recursive=True), expect)