| 1 |
import inspect |
| 2 |
import os |
| 3 |
import posixpath |
| 4 |
import random |
| 5 |
import sys |
| 6 |
import unittest |
| 7 |
from functools import partial |
| 8 |
from posixpath import realpath, abspath, dirname, basename, ALLOW_MISSING |
| 9 |
from test import support |
| 10 |
from test import test_genericpath |
| 11 |
from test.support import import_helper |
| 12 |
from test.support import os_helper |
| 13 |
from test.support.os_helper import FakePath, TESTFN |
| 14 |
from unittest import mock |
| 15 |
|
| 16 |
try: |
| 17 |
import posix |
| 18 |
except ImportError: |
| 19 |
posix = None |
| 20 |
|
| 21 |
|
| 22 |
# An absolute path to a temporary filename for testing. We can't rely on TESTFN |
| 23 |
# being an absolute path, so we need this. |
| 24 |
|
| 25 |
ABSTFN = abspath(TESTFN) |
| 26 |
|
| 27 |
def skip_if_ABSTFN_contains_backslash(test): |
| 28 |
""" |
| 29 |
On Windows, posixpath.abspath still returns paths with backslashes |
| 30 |
instead of posix forward slashes. If this is the case, several tests |
| 31 |
fail, so skip them. |
| 32 |
""" |
| 33 |
found_backslash = '\\' in ABSTFN |
| 34 |
msg = "ABSTFN is not a posix path - tests fail" |
| 35 |
return [test, unittest.skip(msg)(test)][found_backslash] |
| 36 |
|
| 37 |
|
| 38 |
def _parameterize(*parameters): |
| 39 |
return support.subTests('kwargs', parameters) |
| 40 |
|
| 41 |
|
| 42 |
class PosixPathTest(unittest.TestCase): |
| 43 |
|
| 44 |
def setUp(self): |
| 45 |
for suffix in ["", "1", "2"]: |
| 46 |
self.assertFalse(posixpath.lexists(ABSTFN + suffix)) |
| 47 |
|
| 48 |
def test_join(self): |
| 49 |
fn = posixpath.join |
| 50 |
self.assertEqual(fn("/foo", "bar", "/bar", "baz"), "/bar/baz") |
| 51 |
self.assertEqual(fn("/foo", "bar", "baz"), "/foo/bar/baz") |
| 52 |
self.assertEqual(fn("/foo/", "bar/", "baz/"), "/foo/bar/baz/") |
| 53 |
|
| 54 |
self.assertEqual(fn(b"/foo", b"bar", b"/bar", b"baz"), b"/bar/baz") |
| 55 |
self.assertEqual(fn(b"/foo", b"bar", b"baz"), b"/foo/bar/baz") |
| 56 |
self.assertEqual(fn(b"/foo/", b"bar/", b"baz/"), b"/foo/bar/baz/") |
| 57 |
|
| 58 |
self.assertEqual(fn("a", ""), "a/") |
| 59 |
self.assertEqual(fn("a", "", ""), "a/") |
| 60 |
self.assertEqual(fn("a", "b"), "a/b") |
| 61 |
self.assertEqual(fn("a", "b/"), "a/b/") |
| 62 |
self.assertEqual(fn("a/", "b"), "a/b") |
| 63 |
self.assertEqual(fn("a/", "b/"), "a/b/") |
| 64 |
self.assertEqual(fn("a", "b/c", "d"), "a/b/c/d") |
| 65 |
self.assertEqual(fn("a", "b//c", "d"), "a/b//c/d") |
| 66 |
self.assertEqual(fn("a", "b/c/", "d"), "a/b/c/d") |
| 67 |
self.assertEqual(fn("/a", "b"), "/a/b") |
| 68 |
self.assertEqual(fn("/a/", "b"), "/a/b") |
| 69 |
self.assertEqual(fn("a", "/b", "c"), "/b/c") |
| 70 |
self.assertEqual(fn("a", "/b", "/c"), "/c") |
| 71 |
|
| 72 |
def test_split(self): |
| 73 |
self.assertEqual(posixpath.split("/foo/bar"), ("/foo", "bar")) |
| 74 |
self.assertEqual(posixpath.split("/"), ("/", "")) |
| 75 |
self.assertEqual(posixpath.split("foo"), ("", "foo")) |
| 76 |
self.assertEqual(posixpath.split("////foo"), ("////", "foo")) |
| 77 |
self.assertEqual(posixpath.split("//foo//bar"), ("//foo", "bar")) |
| 78 |
|
| 79 |
self.assertEqual(posixpath.split(b"/foo/bar"), (b"/foo", b"bar")) |
| 80 |
self.assertEqual(posixpath.split(b"/"), (b"/", b"")) |
| 81 |
self.assertEqual(posixpath.split(b"foo"), (b"", b"foo")) |
| 82 |
self.assertEqual(posixpath.split(b"////foo"), (b"////", b"foo")) |
| 83 |
self.assertEqual(posixpath.split(b"//foo//bar"), (b"//foo", b"bar")) |
| 84 |
|
| 85 |
def splitextTest(self, path, filename, ext): |
| 86 |
self.assertEqual(posixpath.splitext(path), (filename, ext)) |
| 87 |
self.assertEqual(posixpath.splitext("/" + path), ("/" + filename, ext)) |
| 88 |
self.assertEqual(posixpath.splitext("abc/" + path), |
| 89 |
("abc/" + filename, ext)) |
| 90 |
self.assertEqual(posixpath.splitext("abc.def/" + path), |
| 91 |
("abc.def/" + filename, ext)) |
| 92 |
self.assertEqual(posixpath.splitext("/abc.def/" + path), |
| 93 |
("/abc.def/" + filename, ext)) |
| 94 |
self.assertEqual(posixpath.splitext(path + "/"), |
| 95 |
(filename + ext + "/", "")) |
| 96 |
|
| 97 |
path = bytes(path, "ASCII") |
| 98 |
filename = bytes(filename, "ASCII") |
| 99 |
ext = bytes(ext, "ASCII") |
| 100 |
|
| 101 |
self.assertEqual(posixpath.splitext(path), (filename, ext)) |
| 102 |
self.assertEqual(posixpath.splitext(b"/" + path), |
| 103 |
(b"/" + filename, ext)) |
| 104 |
self.assertEqual(posixpath.splitext(b"abc/" + path), |
| 105 |
(b"abc/" + filename, ext)) |
| 106 |
self.assertEqual(posixpath.splitext(b"abc.def/" + path), |
| 107 |
(b"abc.def/" + filename, ext)) |
| 108 |
self.assertEqual(posixpath.splitext(b"/abc.def/" + path), |
| 109 |
(b"/abc.def/" + filename, ext)) |
| 110 |
self.assertEqual(posixpath.splitext(path + b"/"), |
| 111 |
(filename + ext + b"/", b"")) |
| 112 |
|
| 113 |
def test_splitext(self): |
| 114 |
self.splitextTest("foo.bar", "foo", ".bar") |
| 115 |
self.splitextTest("foo.boo.bar", "foo.boo", ".bar") |
| 116 |
self.splitextTest("foo.boo.biff.bar", "foo.boo.biff", ".bar") |
| 117 |
self.splitextTest(".csh.rc", ".csh", ".rc") |
| 118 |
self.splitextTest("nodots", "nodots", "") |
| 119 |
self.splitextTest(".cshrc", ".cshrc", "") |
| 120 |
self.splitextTest("...manydots", "...manydots", "") |
| 121 |
self.splitextTest("...manydots.ext", "...manydots", ".ext") |
| 122 |
self.splitextTest(".", ".", "") |
| 123 |
self.splitextTest("..", "..", "") |
| 124 |
self.splitextTest("........", "........", "") |
| 125 |
self.splitextTest("", "", "") |
| 126 |
|
| 127 |
def test_splitroot(self): |
| 128 |
f = posixpath.splitroot |
| 129 |
self.assertEqual(f(''), ('', '', '')) |
| 130 |
self.assertEqual(f('a'), ('', '', 'a')) |
| 131 |
self.assertEqual(f('a/b'), ('', '', 'a/b')) |
| 132 |
self.assertEqual(f('a/b/'), ('', '', 'a/b/')) |
| 133 |
self.assertEqual(f('/a'), ('', '/', 'a')) |
| 134 |
self.assertEqual(f('/a/b'), ('', '/', 'a/b')) |
| 135 |
self.assertEqual(f('/a/b/'), ('', '/', 'a/b/')) |
| 136 |
# The root is collapsed when there are redundant slashes |
| 137 |
# except when there are exactly two leading slashes, which |
| 138 |
# is a special case in POSIX. |
| 139 |
self.assertEqual(f('//a'), ('', '//', 'a')) |
| 140 |
self.assertEqual(f('///a'), ('', '/', '//a')) |
| 141 |
self.assertEqual(f('///a/b'), ('', '/', '//a/b')) |
| 142 |
# Paths which look like NT paths aren't treated specially. |
| 143 |
self.assertEqual(f('c:/a/b'), ('', '', 'c:/a/b')) |
| 144 |
self.assertEqual(f('\\/a/b'), ('', '', '\\/a/b')) |
| 145 |
self.assertEqual(f('\\a\\b'), ('', '', '\\a\\b')) |
| 146 |
# Byte paths are supported |
| 147 |
self.assertEqual(f(b''), (b'', b'', b'')) |
| 148 |
self.assertEqual(f(b'a'), (b'', b'', b'a')) |
| 149 |
self.assertEqual(f(b'/a'), (b'', b'/', b'a')) |
| 150 |
self.assertEqual(f(b'//a'), (b'', b'//', b'a')) |
| 151 |
self.assertEqual(f(b'///a'), (b'', b'/', b'//a')) |
| 152 |
|
| 153 |
def test_isabs(self): |
| 154 |
self.assertIs(posixpath.isabs(""), False) |
| 155 |
self.assertIs(posixpath.isabs("/"), True) |
| 156 |
self.assertIs(posixpath.isabs("/foo"), True) |
| 157 |
self.assertIs(posixpath.isabs("/foo/bar"), True) |
| 158 |
self.assertIs(posixpath.isabs("foo/bar"), False) |
| 159 |
|
| 160 |
self.assertIs(posixpath.isabs(b""), False) |
| 161 |
self.assertIs(posixpath.isabs(b"/"), True) |
| 162 |
self.assertIs(posixpath.isabs(b"/foo"), True) |
| 163 |
self.assertIs(posixpath.isabs(b"/foo/bar"), True) |
| 164 |
self.assertIs(posixpath.isabs(b"foo/bar"), False) |
| 165 |
|
| 166 |
def test_basename(self): |
| 167 |
self.assertEqual(posixpath.basename("/foo/bar"), "bar") |
| 168 |
self.assertEqual(posixpath.basename("/"), "") |
| 169 |
self.assertEqual(posixpath.basename("foo"), "foo") |
| 170 |
self.assertEqual(posixpath.basename("////foo"), "foo") |
| 171 |
self.assertEqual(posixpath.basename("//foo//bar"), "bar") |
| 172 |
|
| 173 |
self.assertEqual(posixpath.basename(b"/foo/bar"), b"bar") |
| 174 |
self.assertEqual(posixpath.basename(b"/"), b"") |
| 175 |
self.assertEqual(posixpath.basename(b"foo"), b"foo") |
| 176 |
self.assertEqual(posixpath.basename(b"////foo"), b"foo") |
| 177 |
self.assertEqual(posixpath.basename(b"//foo//bar"), b"bar") |
| 178 |
|
| 179 |
def test_dirname(self): |
| 180 |
self.assertEqual(posixpath.dirname("/foo/bar"), "/foo") |
| 181 |
self.assertEqual(posixpath.dirname("/"), "/") |
| 182 |
self.assertEqual(posixpath.dirname("foo"), "") |
| 183 |
self.assertEqual(posixpath.dirname("////foo"), "////") |
| 184 |
self.assertEqual(posixpath.dirname("//foo//bar"), "//foo") |
| 185 |
|
| 186 |
self.assertEqual(posixpath.dirname(b"/foo/bar"), b"/foo") |
| 187 |
self.assertEqual(posixpath.dirname(b"/"), b"/") |
| 188 |
self.assertEqual(posixpath.dirname(b"foo"), b"") |
| 189 |
self.assertEqual(posixpath.dirname(b"////foo"), b"////") |
| 190 |
self.assertEqual(posixpath.dirname(b"//foo//bar"), b"//foo") |
| 191 |
|
| 192 |
def test_islink(self): |
| 193 |
self.assertIs(posixpath.islink(TESTFN + "1"), False) |
| 194 |
self.assertIs(posixpath.lexists(TESTFN + "2"), False) |
| 195 |
|
| 196 |
self.addCleanup(os_helper.unlink, TESTFN + "1") |
| 197 |
with open(TESTFN + "1", "wb") as f: |
| 198 |
f.write(b"foo") |
| 199 |
self.assertIs(posixpath.islink(TESTFN + "1"), False) |
| 200 |
|
| 201 |
if os_helper.can_symlink(): |
| 202 |
self.addCleanup(os_helper.unlink, TESTFN + "2") |
| 203 |
os.symlink(TESTFN + "1", TESTFN + "2") |
| 204 |
self.assertIs(posixpath.islink(TESTFN + "2"), True) |
| 205 |
os.remove(TESTFN + "1") |
| 206 |
self.assertIs(posixpath.islink(TESTFN + "2"), True) |
| 207 |
self.assertIs(posixpath.exists(TESTFN + "2"), False) |
| 208 |
self.assertIs(posixpath.lexists(TESTFN + "2"), True) |
| 209 |
|
| 210 |
def test_islink_invalid_paths(self): |
| 211 |
self.assertIs(posixpath.islink(TESTFN + "\udfff"), False) |
| 212 |
self.assertIs(posixpath.islink(os.fsencode(TESTFN) + b"\xff"), False) |
| 213 |
self.assertIs(posixpath.islink(TESTFN + "\x00"), False) |
| 214 |
self.assertIs(posixpath.islink(os.fsencode(TESTFN) + b"\x00"), False) |
| 215 |
|
| 216 |
def test_ismount(self): |
| 217 |
self.assertIs(posixpath.ismount("/"), True) |
| 218 |
self.assertIs(posixpath.ismount(b"/"), True) |
| 219 |
self.assertIs(posixpath.ismount(FakePath("/")), True) |
| 220 |
self.assertIs(posixpath.ismount(FakePath(b"/")), True) |
| 221 |
|
| 222 |
def test_ismount_non_existent(self): |
| 223 |
# Non-existent mountpoint. |
| 224 |
self.assertIs(posixpath.ismount(ABSTFN), False) |
| 225 |
try: |
| 226 |
os.mkdir(ABSTFN) |
| 227 |
self.assertIs(posixpath.ismount(ABSTFN), False) |
| 228 |
finally: |
| 229 |
os_helper.rmdir(ABSTFN) |
| 230 |
|
| 231 |
def test_ismount_invalid_paths(self): |
| 232 |
self.assertIs(posixpath.ismount('/\udfff'), False) |
| 233 |
self.assertIs(posixpath.ismount(b'/\xff'), False) |
| 234 |
self.assertIs(posixpath.ismount('/\x00'), False) |
| 235 |
self.assertIs(posixpath.ismount(b'/\x00'), False) |
| 236 |
|
| 237 |
@os_helper.skip_unless_symlink |
| 238 |
def test_ismount_symlinks(self): |
| 239 |
# Symlinks are never mountpoints. |
| 240 |
try: |
| 241 |
os.symlink("/", ABSTFN) |
| 242 |
self.assertIs(posixpath.ismount(ABSTFN), False) |
| 243 |
finally: |
| 244 |
os_helper.unlink(ABSTFN) |
| 245 |
|
| 246 |
@unittest.skipIf(posix is None, "Test requires posix module") |
| 247 |
def test_ismount_different_device(self): |
| 248 |
# Simulate the path being on a different device from its parent by |
| 249 |
# mocking out st_dev. |
| 250 |
save_lstat = os.lstat |
| 251 |
def fake_lstat(path): |
| 252 |
st_ino = 0 |
| 253 |
st_dev = 0 |
| 254 |
if path == ABSTFN: |
| 255 |
st_dev = 1 |
| 256 |
st_ino = 1 |
| 257 |
return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0)) |
| 258 |
try: |
| 259 |
os.lstat = fake_lstat |
| 260 |
self.assertIs(posixpath.ismount(ABSTFN), True) |
| 261 |
finally: |
| 262 |
os.lstat = save_lstat |
| 263 |
|
| 264 |
@unittest.skipIf(posix is None, "Test requires posix module") |
| 265 |
def test_ismount_directory_not_readable(self): |
| 266 |
# issue #2466: Simulate ismount run on a directory that is not |
| 267 |
# readable, which used to return False. |
| 268 |
save_lstat = os.lstat |
| 269 |
def fake_lstat(path): |
| 270 |
st_ino = 0 |
| 271 |
st_dev = 0 |
| 272 |
if path.startswith(ABSTFN) and path != ABSTFN: |
| 273 |
# ismount tries to read something inside the ABSTFN directory; |
| 274 |
# simulate this being forbidden (no read permission). |
| 275 |
raise OSError("Fake [Errno 13] Permission denied") |
| 276 |
if path == ABSTFN: |
| 277 |
st_dev = 1 |
| 278 |
st_ino = 1 |
| 279 |
return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0)) |
| 280 |
try: |
| 281 |
os.lstat = fake_lstat |
| 282 |
self.assertIs(posixpath.ismount(ABSTFN), True) |
| 283 |
finally: |
| 284 |
os.lstat = save_lstat |
| 285 |
|
| 286 |
def test_isjunction(self): |
| 287 |
self.assertFalse(posixpath.isjunction(ABSTFN)) |
| 288 |
|
| 289 |
@unittest.skipIf(sys.platform == 'win32', "Fast paths are not for win32") |
| 290 |
@support.cpython_only |
| 291 |
def test_fast_paths_in_use(self): |
| 292 |
# There are fast paths of these functions implemented in posixmodule.c. |
| 293 |
# Confirm that they are being used, and not the Python fallbacks |
| 294 |
self.assertTrue(os.path.splitroot is posix._path_splitroot_ex) |
| 295 |
self.assertFalse(inspect.isfunction(os.path.splitroot)) |
| 296 |
self.assertTrue(os.path.normpath is posix._path_normpath) |
| 297 |
self.assertFalse(inspect.isfunction(os.path.normpath)) |
| 298 |
|
| 299 |
def test_expanduser(self): |
| 300 |
self.assertEqual(posixpath.expanduser("foo"), "foo") |
| 301 |
self.assertEqual(posixpath.expanduser(b"foo"), b"foo") |
| 302 |
|
| 303 |
def test_expanduser_home_envvar(self): |
| 304 |
with os_helper.EnvironmentVarGuard() as env: |
| 305 |
env['HOME'] = '/home/victor' |
| 306 |
self.assertEqual(posixpath.expanduser("~"), "/home/victor") |
| 307 |
|
| 308 |
# expanduser() strips trailing slash |
| 309 |
env['HOME'] = '/home/victor/' |
| 310 |
self.assertEqual(posixpath.expanduser("~"), "/home/victor") |
| 311 |
|
| 312 |
for home in '/', '', '//', '///': |
| 313 |
with self.subTest(home=home): |
| 314 |
env['HOME'] = home |
| 315 |
self.assertEqual(posixpath.expanduser("~"), "/") |
| 316 |
self.assertEqual(posixpath.expanduser("~/"), "/") |
| 317 |
self.assertEqual(posixpath.expanduser("~/foo"), "/foo") |
| 318 |
|
| 319 |
@unittest.skipIf(sys.platform == "vxworks", |
| 320 |
"no home directory on VxWorks") |
| 321 |
def test_expanduser_pwd(self): |
| 322 |
pwd = import_helper.import_module('pwd') |
| 323 |
|
| 324 |
self.assertIsInstance(posixpath.expanduser("~/"), str) |
| 325 |
self.assertIsInstance(posixpath.expanduser(b"~/"), bytes) |
| 326 |
|
| 327 |
# if home directory == root directory, this test makes no sense |
| 328 |
if posixpath.expanduser("~") != '/': |
| 329 |
self.assertEqual( |
| 330 |
posixpath.expanduser("~") + "/", |
| 331 |
posixpath.expanduser("~/") |
| 332 |
) |
| 333 |
self.assertEqual( |
| 334 |
posixpath.expanduser(b"~") + b"/", |
| 335 |
posixpath.expanduser(b"~/") |
| 336 |
) |
| 337 |
self.assertIsInstance(posixpath.expanduser("~root/"), str) |
| 338 |
self.assertIsInstance(posixpath.expanduser("~foo/"), str) |
| 339 |
self.assertIsInstance(posixpath.expanduser(b"~root/"), bytes) |
| 340 |
self.assertIsInstance(posixpath.expanduser(b"~foo/"), bytes) |
| 341 |
|
| 342 |
with os_helper.EnvironmentVarGuard() as env: |
| 343 |
# expanduser should fall back to using the password database |
| 344 |
del env['HOME'] |
| 345 |
|
| 346 |
home = pwd.getpwuid(os.getuid()).pw_dir |
| 347 |
# $HOME can end with a trailing /, so strip it (see #17809) |
| 348 |
home = home.rstrip("/") or '/' |
| 349 |
self.assertEqual(posixpath.expanduser("~"), home) |
| 350 |
|
| 351 |
# bpo-10496: If the HOME environment variable is not set and the |
| 352 |
# user (current identifier or name in the path) doesn't exist in |
| 353 |
# the password database (pwd.getuid() or pwd.getpwnam() fail), |
| 354 |
# expanduser() must return the path unchanged. |
| 355 |
with mock.patch.object(pwd, 'getpwuid', side_effect=KeyError), \ |
| 356 |
mock.patch.object(pwd, 'getpwnam', side_effect=KeyError): |
| 357 |
for path in ('~', '~/.local', '~vstinner/'): |
| 358 |
self.assertEqual(posixpath.expanduser(path), path) |
| 359 |
|
| 360 |
@unittest.skipIf(sys.platform == "vxworks", |
| 361 |
"no home directory on VxWorks") |
| 362 |
def test_expanduser_pwd2(self): |
| 363 |
pwd = import_helper.import_module('pwd') |
| 364 |
getpwall = support.get_attribute(pwd, 'getpwall') |
| 365 |
names = [entry.pw_name for entry in getpwall()] |
| 366 |
maxusers = 1000 if support.is_resource_enabled('cpu') else 100 |
| 367 |
if len(names) > maxusers: |
| 368 |
# Select random names, half of them with non-ASCII name, |
| 369 |
# if available. |
| 370 |
random.shuffle(names) |
| 371 |
names.sort(key=lambda name: name.isascii()) |
| 372 |
del names[maxusers//2:-maxusers//2] |
| 373 |
for name in names: |
| 374 |
# gh-121200: pw_dir can be different between getpwall() and |
| 375 |
# getpwnam(), so use getpwnam() pw_dir as expanduser() does. |
| 376 |
entry = pwd.getpwnam(name) |
| 377 |
home = entry.pw_dir |
| 378 |
home = home.rstrip('/') or '/' |
| 379 |
|
| 380 |
with self.subTest(name=name, pw_dir=entry.pw_dir): |
| 381 |
self.assertEqual(posixpath.expanduser('~' + name), home) |
| 382 |
self.assertEqual(posixpath.expanduser(os.fsencode('~' + name)), |
| 383 |
os.fsencode(home)) |
| 384 |
|
| 385 |
NORMPATH_CASES = [ |
| 386 |
("", "."), |
| 387 |
("/", "/"), |
| 388 |
("/.", "/"), |
| 389 |
("/./", "/"), |
| 390 |
("/.//.", "/"), |
| 391 |
("/./foo/bar", "/foo/bar"), |
| 392 |
("/foo", "/foo"), |
| 393 |
("/foo/bar", "/foo/bar"), |
| 394 |
("//", "//"), |
| 395 |
("///", "/"), |
| 396 |
("///foo/.//bar//", "/foo/bar"), |
| 397 |
("///foo/.//bar//.//..//.//baz///", "/foo/baz"), |
| 398 |
("///..//./foo/.//bar", "/foo/bar"), |
| 399 |
(".", "."), |
| 400 |
(".//.", "."), |
| 401 |
("./foo/bar", "foo/bar"), |
| 402 |
("..", ".."), |
| 403 |
("../", ".."), |
| 404 |
("../foo", "../foo"), |
| 405 |
("../../foo", "../../foo"), |
| 406 |
("../foo/../bar", "../bar"), |
| 407 |
("../../foo/../bar/./baz/boom/..", "../../bar/baz"), |
| 408 |
("/..", "/"), |
| 409 |
("/..", "/"), |
| 410 |
("/../", "/"), |
| 411 |
("/..//", "/"), |
| 412 |
("//.", "//"), |
| 413 |
("//..", "//"), |
| 414 |
("//...", "//..."), |
| 415 |
("//../foo", "//foo"), |
| 416 |
("//../../foo", "//foo"), |
| 417 |
("/../foo", "/foo"), |
| 418 |
("/../../foo", "/foo"), |
| 419 |
("/../foo/../", "/"), |
| 420 |
("/../foo/../bar", "/bar"), |
| 421 |
("/../../foo/../bar/./baz/boom/..", "/bar/baz"), |
| 422 |
("/../../foo/../bar/./baz/boom/.", "/bar/baz/boom"), |
| 423 |
("foo/../bar/baz", "bar/baz"), |
| 424 |
("foo/../../bar/baz", "../bar/baz"), |
| 425 |
("foo/../../../bar/baz", "../../bar/baz"), |
| 426 |
("foo///../bar/.././../baz/boom", "../baz/boom"), |
| 427 |
("foo/bar/../..///../../baz/boom", "../../baz/boom"), |
| 428 |
("/foo/..", "/"), |
| 429 |
("/foo/../..", "/"), |
| 430 |
("//foo/..", "//"), |
| 431 |
("//foo/../..", "//"), |
| 432 |
("///foo/..", "/"), |
| 433 |
("///foo/../..", "/"), |
| 434 |
("////foo/..", "/"), |
| 435 |
("/////foo/..", "/"), |
| 436 |
] |
| 437 |
|
| 438 |
def test_normpath(self): |
| 439 |
for path, expected in self.NORMPATH_CASES: |
| 440 |
with self.subTest(path): |
| 441 |
result = posixpath.normpath(path) |
| 442 |
self.assertEqual(result, expected) |
| 443 |
|
| 444 |
path = path.encode('utf-8') |
| 445 |
expected = expected.encode('utf-8') |
| 446 |
with self.subTest(path, type=bytes): |
| 447 |
result = posixpath.normpath(path) |
| 448 |
self.assertEqual(result, expected) |
| 449 |
|
| 450 |
@skip_if_ABSTFN_contains_backslash |
| 451 |
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING}) |
| 452 |
def test_realpath_curdir(self, kwargs): |
| 453 |
self.assertEqual(realpath('.', **kwargs), os.getcwd()) |
| 454 |
self.assertEqual(realpath('./.', **kwargs), os.getcwd()) |
| 455 |
self.assertEqual(realpath('/'.join(['.'] * 100), **kwargs), os.getcwd()) |
| 456 |
|
| 457 |
self.assertEqual(realpath(b'.', **kwargs), os.getcwdb()) |
| 458 |
self.assertEqual(realpath(b'./.', **kwargs), os.getcwdb()) |
| 459 |
self.assertEqual(realpath(b'/'.join([b'.'] * 100), **kwargs), os.getcwdb()) |
| 460 |
|
| 461 |
@skip_if_ABSTFN_contains_backslash |
| 462 |
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING}) |
| 463 |
def test_realpath_pardir(self, kwargs): |
| 464 |
self.assertEqual(realpath('..', **kwargs), dirname(os.getcwd())) |
| 465 |
self.assertEqual(realpath('../..', **kwargs), dirname(dirname(os.getcwd()))) |
| 466 |
self.assertEqual(realpath('/'.join(['..'] * 100), **kwargs), '/') |
| 467 |
|
| 468 |
self.assertEqual(realpath(b'..', **kwargs), dirname(os.getcwdb())) |
| 469 |
self.assertEqual(realpath(b'../..', **kwargs), dirname(dirname(os.getcwdb()))) |
| 470 |
self.assertEqual(realpath(b'/'.join([b'..'] * 100), **kwargs), b'/') |
| 471 |
|
| 472 |
@os_helper.skip_unless_symlink |
| 473 |
@skip_if_ABSTFN_contains_backslash |
| 474 |
@_parameterize({}, {'strict': ALLOW_MISSING}) |
| 475 |
def test_realpath_basic(self, kwargs): |
| 476 |
# Basic operation. |
| 477 |
try: |
| 478 |
os.symlink(ABSTFN+"1", ABSTFN) |
| 479 |
self.assertEqual(realpath(ABSTFN, **kwargs), ABSTFN+"1") |
| 480 |
finally: |
| 481 |
os_helper.unlink(ABSTFN) |
| 482 |
|
| 483 |
@os_helper.skip_unless_symlink |
| 484 |
@skip_if_ABSTFN_contains_backslash |
| 485 |
def test_realpath_strict(self): |
| 486 |
# Bug #43757: raise FileNotFoundError in strict mode if we encounter |
| 487 |
# a path that does not exist. |
| 488 |
try: |
| 489 |
os.symlink(ABSTFN+"1", ABSTFN) |
| 490 |
self.assertRaises(FileNotFoundError, realpath, ABSTFN, strict=True) |
| 491 |
self.assertRaises(FileNotFoundError, realpath, ABSTFN + "2", strict=True) |
| 492 |
finally: |
| 493 |
os_helper.unlink(ABSTFN) |
| 494 |
|
| 495 |
def test_realpath_invalid_paths(self): |
| 496 |
path = '/\x00' |
| 497 |
self.assertRaises(ValueError, realpath, path, strict=False) |
| 498 |
self.assertRaises(ValueError, realpath, path, strict=True) |
| 499 |
self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING) |
| 500 |
path = b'/\x00' |
| 501 |
self.assertRaises(ValueError, realpath, path, strict=False) |
| 502 |
self.assertRaises(ValueError, realpath, path, strict=True) |
| 503 |
self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING) |
| 504 |
path = '/nonexistent/x\x00' |
| 505 |
self.assertRaises(ValueError, realpath, path, strict=False) |
| 506 |
self.assertRaises(FileNotFoundError, realpath, path, strict=True) |
| 507 |
self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING) |
| 508 |
path = b'/nonexistent/x\x00' |
| 509 |
self.assertRaises(ValueError, realpath, path, strict=False) |
| 510 |
self.assertRaises(FileNotFoundError, realpath, path, strict=True) |
| 511 |
self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING) |
| 512 |
path = '/\x00/..' |
| 513 |
self.assertRaises(ValueError, realpath, path, strict=False) |
| 514 |
self.assertRaises(ValueError, realpath, path, strict=True) |
| 515 |
self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING) |
| 516 |
path = b'/\x00/..' |
| 517 |
self.assertRaises(ValueError, realpath, path, strict=False) |
| 518 |
self.assertRaises(ValueError, realpath, path, strict=True) |
| 519 |
self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING) |
| 520 |
|
| 521 |
path = '/nonexistent/x\x00/..' |
| 522 |
self.assertRaises(ValueError, realpath, path, strict=False) |
| 523 |
self.assertRaises(FileNotFoundError, realpath, path, strict=True) |
| 524 |
self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING) |
| 525 |
path = b'/nonexistent/x\x00/..' |
| 526 |
self.assertRaises(ValueError, realpath, path, strict=False) |
| 527 |
self.assertRaises(FileNotFoundError, realpath, path, strict=True) |
| 528 |
self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING) |
| 529 |
|
| 530 |
path = '/\udfff' |
| 531 |
if sys.platform == 'win32': |
| 532 |
self.assertEqual(realpath(path, strict=False), path) |
| 533 |
self.assertRaises(FileNotFoundError, realpath, path, strict=True) |
| 534 |
self.assertEqual(realpath(path, strict=ALLOW_MISSING), path) |
| 535 |
else: |
| 536 |
self.assertRaises(UnicodeEncodeError, realpath, path, strict=False) |
| 537 |
self.assertRaises(UnicodeEncodeError, realpath, path, strict=True) |
| 538 |
self.assertRaises(UnicodeEncodeError, realpath, path, strict=ALLOW_MISSING) |
| 539 |
path = '/nonexistent/\udfff' |
| 540 |
if sys.platform == 'win32': |
| 541 |
self.assertEqual(realpath(path, strict=False), path) |
| 542 |
self.assertEqual(realpath(path, strict=ALLOW_MISSING), path) |
| 543 |
else: |
| 544 |
self.assertRaises(UnicodeEncodeError, realpath, path, strict=False) |
| 545 |
self.assertRaises(UnicodeEncodeError, realpath, path, strict=ALLOW_MISSING) |
| 546 |
self.assertRaises(FileNotFoundError, realpath, path, strict=True) |
| 547 |
path = '/\udfff/..' |
| 548 |
if sys.platform == 'win32': |
| 549 |
self.assertEqual(realpath(path, strict=False), '/') |
| 550 |
self.assertRaises(FileNotFoundError, realpath, path, strict=True) |
| 551 |
self.assertEqual(realpath(path, strict=ALLOW_MISSING), '/') |
| 552 |
else: |
| 553 |
self.assertRaises(UnicodeEncodeError, realpath, path, strict=False) |
| 554 |
self.assertRaises(UnicodeEncodeError, realpath, path, strict=True) |
| 555 |
self.assertRaises(UnicodeEncodeError, realpath, path, strict=ALLOW_MISSING) |
| 556 |
path = '/nonexistent/\udfff/..' |
| 557 |
if sys.platform == 'win32': |
| 558 |
self.assertEqual(realpath(path, strict=False), '/nonexistent') |
| 559 |
self.assertEqual(realpath(path, strict=ALLOW_MISSING), '/nonexistent') |
| 560 |
else: |
| 561 |
self.assertRaises(UnicodeEncodeError, realpath, path, strict=False) |
| 562 |
self.assertRaises(UnicodeEncodeError, realpath, path, strict=ALLOW_MISSING) |
| 563 |
self.assertRaises(FileNotFoundError, realpath, path, strict=True) |
| 564 |
|
| 565 |
path = b'/\xff' |
| 566 |
if sys.platform == 'win32': |
| 567 |
self.assertRaises(UnicodeDecodeError, realpath, path, strict=False) |
| 568 |
self.assertRaises(UnicodeDecodeError, realpath, path, strict=True) |
| 569 |
self.assertRaises(UnicodeDecodeError, realpath, path, strict=ALLOW_MISSING) |
| 570 |
else: |
| 571 |
self.assertEqual(realpath(path, strict=False), path) |
| 572 |
if support.is_wasi: |
| 573 |
self.assertRaises(OSError, realpath, path, strict=True) |
| 574 |
self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING) |
| 575 |
else: |
| 576 |
self.assertRaises(FileNotFoundError, realpath, path, strict=True) |
| 577 |
self.assertEqual(realpath(path, strict=ALLOW_MISSING), path) |
| 578 |
path = b'/nonexistent/\xff' |
| 579 |
if sys.platform == 'win32': |
| 580 |
self.assertRaises(UnicodeDecodeError, realpath, path, strict=False) |
| 581 |
self.assertRaises(UnicodeDecodeError, realpath, path, strict=ALLOW_MISSING) |
| 582 |
else: |
| 583 |
self.assertEqual(realpath(path, strict=False), path) |
| 584 |
if support.is_wasi: |
| 585 |
self.assertRaises(OSError, realpath, path, strict=True) |
| 586 |
self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING) |
| 587 |
else: |
| 588 |
self.assertRaises(FileNotFoundError, realpath, path, strict=True) |
| 589 |
|
| 590 |
@os_helper.skip_unless_symlink |
| 591 |
@skip_if_ABSTFN_contains_backslash |
| 592 |
@_parameterize({}, {'strict': ALLOW_MISSING}) |
| 593 |
def test_realpath_relative(self, kwargs): |
| 594 |
try: |
| 595 |
os.symlink(posixpath.relpath(ABSTFN+"1"), ABSTFN) |
| 596 |
self.assertEqual(realpath(ABSTFN, **kwargs), ABSTFN+"1") |
| 597 |
finally: |
| 598 |
os_helper.unlink(ABSTFN) |
| 599 |
|
| 600 |
@os_helper.skip_unless_symlink |
| 601 |
@skip_if_ABSTFN_contains_backslash |
| 602 |
@_parameterize({}, {'strict': ALLOW_MISSING}) |
| 603 |
def test_realpath_missing_pardir(self, kwargs): |
| 604 |
try: |
| 605 |
os.symlink(TESTFN + "1", TESTFN) |
| 606 |
self.assertEqual( |
| 607 |
realpath("nonexistent/../" + TESTFN, **kwargs), ABSTFN + "1") |
| 608 |
finally: |
| 609 |
os_helper.unlink(TESTFN) |
| 610 |
|
| 611 |
@os_helper.skip_unless_symlink |
| 612 |
@skip_if_ABSTFN_contains_backslash |
| 613 |
def test_realpath_symlink_loops(self): |
| 614 |
# Bug #930024, return the path unchanged if we get into an infinite |
| 615 |
# symlink loop in non-strict mode (default). |
| 616 |
try: |
| 617 |
os.symlink(ABSTFN, ABSTFN) |
| 618 |
self.assertEqual(realpath(ABSTFN), ABSTFN) |
| 619 |
|
| 620 |
os.symlink(ABSTFN+"1", ABSTFN+"2") |
| 621 |
os.symlink(ABSTFN+"2", ABSTFN+"1") |
| 622 |
self.assertEqual(realpath(ABSTFN+"1"), ABSTFN+"1") |
| 623 |
self.assertEqual(realpath(ABSTFN+"2"), ABSTFN+"2") |
| 624 |
|
| 625 |
self.assertEqual(realpath(ABSTFN+"1/x"), ABSTFN+"1/x") |
| 626 |
self.assertEqual(realpath(ABSTFN+"1/.."), dirname(ABSTFN)) |
| 627 |
self.assertEqual(realpath(ABSTFN+"1/../x"), dirname(ABSTFN) + "/x") |
| 628 |
os.symlink(ABSTFN+"x", ABSTFN+"y") |
| 629 |
self.assertEqual(realpath(ABSTFN+"1/../" + basename(ABSTFN) + "y"), |
| 630 |
ABSTFN + "x") |
| 631 |
self.assertEqual(realpath(ABSTFN+"1/../" + basename(ABSTFN) + "1"), |
| 632 |
ABSTFN + "1") |
| 633 |
|
| 634 |
os.symlink(basename(ABSTFN) + "a/b", ABSTFN+"a") |
| 635 |
self.assertEqual(realpath(ABSTFN+"a"), ABSTFN+"a/b") |
| 636 |
|
| 637 |
os.symlink("../" + basename(dirname(ABSTFN)) + "/" + |
| 638 |
basename(ABSTFN) + "c", ABSTFN+"c") |
| 639 |
self.assertEqual(realpath(ABSTFN+"c"), ABSTFN+"c") |
| 640 |
|
| 641 |
# Test using relative path as well. |
| 642 |
with os_helper.change_cwd(dirname(ABSTFN)): |
| 643 |
self.assertEqual(realpath(basename(ABSTFN)), ABSTFN) |
| 644 |
finally: |
| 645 |
os_helper.unlink(ABSTFN) |
| 646 |
os_helper.unlink(ABSTFN+"1") |
| 647 |
os_helper.unlink(ABSTFN+"2") |
| 648 |
os_helper.unlink(ABSTFN+"y") |
| 649 |
os_helper.unlink(ABSTFN+"c") |
| 650 |
os_helper.unlink(ABSTFN+"a") |
| 651 |
|
| 652 |
@os_helper.skip_unless_symlink |
| 653 |
@skip_if_ABSTFN_contains_backslash |
| 654 |
@_parameterize({'strict': True}, {'strict': ALLOW_MISSING}) |
| 655 |
def test_realpath_symlink_loops_strict(self, kwargs): |
| 656 |
# Bug #43757, raise OSError if we get into an infinite symlink loop in |
| 657 |
# the strict modes. |
| 658 |
try: |
| 659 |
os.symlink(ABSTFN, ABSTFN) |
| 660 |
self.assertRaises(OSError, realpath, ABSTFN, **kwargs) |
| 661 |
|
| 662 |
os.symlink(ABSTFN+"1", ABSTFN+"2") |
| 663 |
os.symlink(ABSTFN+"2", ABSTFN+"1") |
| 664 |
self.assertRaises(OSError, realpath, ABSTFN+"1", **kwargs) |
| 665 |
self.assertRaises(OSError, realpath, ABSTFN+"2", **kwargs) |
| 666 |
|
| 667 |
self.assertRaises(OSError, realpath, ABSTFN+"1/x", **kwargs) |
| 668 |
self.assertRaises(OSError, realpath, ABSTFN+"1/..", **kwargs) |
| 669 |
self.assertRaises(OSError, realpath, ABSTFN+"1/../x", **kwargs) |
| 670 |
os.symlink(ABSTFN+"x", ABSTFN+"y") |
| 671 |
self.assertRaises(OSError, realpath, |
| 672 |
ABSTFN+"1/../" + basename(ABSTFN) + "y", **kwargs) |
| 673 |
self.assertRaises(OSError, realpath, |
| 674 |
ABSTFN+"1/../" + basename(ABSTFN) + "1", **kwargs) |
| 675 |
|
| 676 |
os.symlink(basename(ABSTFN) + "a/b", ABSTFN+"a") |
| 677 |
self.assertRaises(OSError, realpath, ABSTFN+"a", **kwargs) |
| 678 |
|
| 679 |
os.symlink("../" + basename(dirname(ABSTFN)) + "/" + |
| 680 |
basename(ABSTFN) + "c", ABSTFN+"c") |
| 681 |
self.assertRaises(OSError, realpath, ABSTFN+"c", **kwargs) |
| 682 |
|
| 683 |
# Test using relative path as well. |
| 684 |
with os_helper.change_cwd(dirname(ABSTFN)): |
| 685 |
self.assertRaises(OSError, realpath, basename(ABSTFN), **kwargs) |
| 686 |
finally: |
| 687 |
os_helper.unlink(ABSTFN) |
| 688 |
os_helper.unlink(ABSTFN+"1") |
| 689 |
os_helper.unlink(ABSTFN+"2") |
| 690 |
os_helper.unlink(ABSTFN+"y") |
| 691 |
os_helper.unlink(ABSTFN+"c") |
| 692 |
os_helper.unlink(ABSTFN+"a") |
| 693 |
|
| 694 |
@os_helper.skip_unless_symlink |
| 695 |
@skip_if_ABSTFN_contains_backslash |
| 696 |
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING}) |
| 697 |
def test_realpath_repeated_indirect_symlinks(self, kwargs): |
| 698 |
# Issue #6975. |
| 699 |
try: |
| 700 |
os.mkdir(ABSTFN) |
| 701 |
os.symlink('../' + basename(ABSTFN), ABSTFN + '/self') |
| 702 |
os.symlink('self/self/self', ABSTFN + '/link') |
| 703 |
self.assertEqual(realpath(ABSTFN + '/link', **kwargs), ABSTFN) |
| 704 |
finally: |
| 705 |
os_helper.unlink(ABSTFN + '/self') |
| 706 |
os_helper.unlink(ABSTFN + '/link') |
| 707 |
os_helper.rmdir(ABSTFN) |
| 708 |
|
| 709 |
@os_helper.skip_unless_symlink |
| 710 |
@skip_if_ABSTFN_contains_backslash |
| 711 |
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING}) |
| 712 |
def test_realpath_deep_recursion(self, kwargs): |
| 713 |
depth = 10 |
| 714 |
try: |
| 715 |
os.mkdir(ABSTFN) |
| 716 |
for i in range(depth): |
| 717 |
os.symlink('/'.join(['%d' % i] * 10), ABSTFN + '/%d' % (i + 1)) |
| 718 |
os.symlink('.', ABSTFN + '/0') |
| 719 |
self.assertEqual(realpath(ABSTFN + '/%d' % depth, **kwargs), ABSTFN) |
| 720 |
|
| 721 |
# Test using relative path as well. |
| 722 |
with os_helper.change_cwd(ABSTFN): |
| 723 |
self.assertEqual(realpath('%d' % depth), ABSTFN) |
| 724 |
finally: |
| 725 |
for i in range(depth + 1): |
| 726 |
os_helper.unlink(ABSTFN + '/%d' % i) |
| 727 |
os_helper.rmdir(ABSTFN) |
| 728 |
|
| 729 |
@os_helper.skip_unless_symlink |
| 730 |
@skip_if_ABSTFN_contains_backslash |
| 731 |
@_parameterize({}, {'strict': ALLOW_MISSING}) |
| 732 |
def test_realpath_resolve_parents(self, kwargs): |
| 733 |
# We also need to resolve any symlinks in the parents of a relative |
| 734 |
# path passed to realpath. E.g.: current working directory is |
| 735 |
# /usr/doc with 'doc' being a symlink to /usr/share/doc. We call |
| 736 |
# realpath("a"). This should return /usr/share/doc/a/. |
| 737 |
try: |
| 738 |
os.mkdir(ABSTFN) |
| 739 |
os.mkdir(ABSTFN + "/y") |
| 740 |
os.symlink(ABSTFN + "/y", ABSTFN + "/k") |
| 741 |
|
| 742 |
with os_helper.change_cwd(ABSTFN + "/k"): |
| 743 |
self.assertEqual(realpath("a", **kwargs), |
| 744 |
ABSTFN + "/y/a") |
| 745 |
finally: |
| 746 |
os_helper.unlink(ABSTFN + "/k") |
| 747 |
os_helper.rmdir(ABSTFN + "/y") |
| 748 |
os_helper.rmdir(ABSTFN) |
| 749 |
|
| 750 |
@os_helper.skip_unless_symlink |
| 751 |
@skip_if_ABSTFN_contains_backslash |
| 752 |
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING}) |
| 753 |
def test_realpath_resolve_before_normalizing(self, kwargs): |
| 754 |
# Bug #990669: Symbolic links should be resolved before we |
| 755 |
# normalize the path. E.g.: if we have directories 'a', 'k' and 'y' |
| 756 |
# in the following hierarchy: |
| 757 |
# a/k/y |
| 758 |
# |
| 759 |
# and a symbolic link 'link-y' pointing to 'y' in directory 'a', |
| 760 |
# then realpath("link-y/..") should return 'k', not 'a'. |
| 761 |
try: |
| 762 |
os.mkdir(ABSTFN) |
| 763 |
os.mkdir(ABSTFN + "/k") |
| 764 |
os.mkdir(ABSTFN + "/k/y") |
| 765 |
os.symlink(ABSTFN + "/k/y", ABSTFN + "/link-y") |
| 766 |
|
| 767 |
# Absolute path. |
| 768 |
self.assertEqual(realpath(ABSTFN + "/link-y/..", **kwargs), ABSTFN + "/k") |
| 769 |
# Relative path. |
| 770 |
with os_helper.change_cwd(dirname(ABSTFN)): |
| 771 |
self.assertEqual(realpath(basename(ABSTFN) + "/link-y/..", **kwargs), |
| 772 |
ABSTFN + "/k") |
| 773 |
finally: |
| 774 |
os_helper.unlink(ABSTFN + "/link-y") |
| 775 |
os_helper.rmdir(ABSTFN + "/k/y") |
| 776 |
os_helper.rmdir(ABSTFN + "/k") |
| 777 |
os_helper.rmdir(ABSTFN) |
| 778 |
|
| 779 |
@os_helper.skip_unless_symlink |
| 780 |
@skip_if_ABSTFN_contains_backslash |
| 781 |
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING}) |
| 782 |
def test_realpath_resolve_first(self, kwargs): |
| 783 |
# Bug #1213894: The first component of the path, if not absolute, |
| 784 |
# must be resolved too. |
| 785 |
|
| 786 |
try: |
| 787 |
os.mkdir(ABSTFN) |
| 788 |
os.mkdir(ABSTFN + "/k") |
| 789 |
os.symlink(ABSTFN, ABSTFN + "link") |
| 790 |
with os_helper.change_cwd(dirname(ABSTFN)): |
| 791 |
base = basename(ABSTFN) |
| 792 |
self.assertEqual(realpath(base + "link", **kwargs), ABSTFN) |
| 793 |
self.assertEqual(realpath(base + "link/k", **kwargs), ABSTFN + "/k") |
| 794 |
finally: |
| 795 |
os_helper.unlink(ABSTFN + "link") |
| 796 |
os_helper.rmdir(ABSTFN + "/k") |
| 797 |
os_helper.rmdir(ABSTFN) |
| 798 |
|
| 799 |
@os_helper.skip_unless_symlink |
| 800 |
@skip_if_ABSTFN_contains_backslash |
| 801 |
@unittest.skipIf(os.chmod not in os.supports_follow_symlinks, "Can't set symlink permissions") |
| 802 |
@unittest.skipIf(sys.platform != "darwin", "only macOS requires read permission to readlink()") |
| 803 |
def test_realpath_unreadable_symlink(self): |
| 804 |
try: |
| 805 |
os.symlink(ABSTFN+"1", ABSTFN) |
| 806 |
os.chmod(ABSTFN, 0o000, follow_symlinks=False) |
| 807 |
self.assertEqual(realpath(ABSTFN), ABSTFN) |
| 808 |
self.assertEqual(realpath(ABSTFN + '/foo'), ABSTFN + '/foo') |
| 809 |
self.assertEqual(realpath(ABSTFN + '/../foo'), dirname(ABSTFN) + '/foo') |
| 810 |
self.assertEqual(realpath(ABSTFN + '/foo/..'), ABSTFN) |
| 811 |
finally: |
| 812 |
os.chmod(ABSTFN, 0o755, follow_symlinks=False) |
| 813 |
os_helper.unlink(ABSTFN) |
| 814 |
|
| 815 |
@os_helper.skip_unless_symlink |
| 816 |
@skip_if_ABSTFN_contains_backslash |
| 817 |
@unittest.skipIf(os.chmod not in os.supports_follow_symlinks, "Can't set symlink permissions") |
| 818 |
@unittest.skipIf(sys.platform != "darwin", "only macOS requires read permission to readlink()") |
| 819 |
@_parameterize({'strict': True}, {'strict': ALLOW_MISSING}) |
| 820 |
def test_realpath_unreadable_symlink_strict(self, kwargs): |
| 821 |
try: |
| 822 |
os.symlink(ABSTFN+"1", ABSTFN) |
| 823 |
os.chmod(ABSTFN, 0o000, follow_symlinks=False) |
| 824 |
with self.assertRaises(PermissionError): |
| 825 |
realpath(ABSTFN, **kwargs) |
| 826 |
with self.assertRaises(PermissionError): |
| 827 |
realpath(ABSTFN + '/foo', **kwargs), |
| 828 |
with self.assertRaises(PermissionError): |
| 829 |
realpath(ABSTFN + '/../foo', **kwargs) |
| 830 |
with self.assertRaises(PermissionError): |
| 831 |
realpath(ABSTFN + '/foo/..', **kwargs) |
| 832 |
finally: |
| 833 |
os.chmod(ABSTFN, 0o755, follow_symlinks=False) |
| 834 |
os.unlink(ABSTFN) |
| 835 |
|
| 836 |
@skip_if_ABSTFN_contains_backslash |
| 837 |
@os_helper.skip_unless_symlink |
| 838 |
def test_realpath_unreadable_directory(self): |
| 839 |
try: |
| 840 |
os.mkdir(ABSTFN) |
| 841 |
os.mkdir(ABSTFN + '/k') |
| 842 |
os.chmod(ABSTFN, 0o000) |
| 843 |
self.assertEqual(realpath(ABSTFN, strict=False), ABSTFN) |
| 844 |
self.assertEqual(realpath(ABSTFN, strict=True), ABSTFN) |
| 845 |
self.assertEqual(realpath(ABSTFN, strict=ALLOW_MISSING), ABSTFN) |
| 846 |
|
| 847 |
try: |
| 848 |
os.stat(ABSTFN) |
| 849 |
except PermissionError: |
| 850 |
pass |
| 851 |
else: |
| 852 |
self.skipTest('Cannot block permissions') |
| 853 |
|
| 854 |
self.assertEqual(realpath(ABSTFN + '/k', strict=False), |
| 855 |
ABSTFN + '/k') |
| 856 |
self.assertRaises(PermissionError, realpath, ABSTFN + '/k', |
| 857 |
strict=True) |
| 858 |
self.assertRaises(PermissionError, realpath, ABSTFN + '/k', |
| 859 |
strict=ALLOW_MISSING) |
| 860 |
|
| 861 |
self.assertEqual(realpath(ABSTFN + '/missing', strict=False), |
| 862 |
ABSTFN + '/missing') |
| 863 |
self.assertRaises(PermissionError, realpath, ABSTFN + '/missing', |
| 864 |
strict=True) |
| 865 |
self.assertRaises(PermissionError, realpath, ABSTFN + '/missing', |
| 866 |
strict=ALLOW_MISSING) |
| 867 |
finally: |
| 868 |
os.chmod(ABSTFN, 0o755) |
| 869 |
os_helper.rmdir(ABSTFN + '/k') |
| 870 |
os_helper.rmdir(ABSTFN) |
| 871 |
|
| 872 |
@skip_if_ABSTFN_contains_backslash |
| 873 |
def test_realpath_nonterminal_file(self): |
| 874 |
try: |
| 875 |
with open(ABSTFN, 'w') as f: |
| 876 |
f.write('test_posixpath wuz ere') |
| 877 |
self.assertEqual(realpath(ABSTFN, strict=False), ABSTFN) |
| 878 |
self.assertEqual(realpath(ABSTFN, strict=True), ABSTFN) |
| 879 |
self.assertEqual(realpath(ABSTFN, strict=ALLOW_MISSING), ABSTFN) |
| 880 |
|
| 881 |
self.assertEqual(realpath(ABSTFN + "/", strict=False), ABSTFN) |
| 882 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/", strict=True) |
| 883 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/", |
| 884 |
strict=ALLOW_MISSING) |
| 885 |
|
| 886 |
self.assertEqual(realpath(ABSTFN + "/.", strict=False), ABSTFN) |
| 887 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/.", strict=True) |
| 888 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/.", |
| 889 |
strict=ALLOW_MISSING) |
| 890 |
|
| 891 |
self.assertEqual(realpath(ABSTFN + "/..", strict=False), dirname(ABSTFN)) |
| 892 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/..", strict=True) |
| 893 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/..", |
| 894 |
strict=ALLOW_MISSING) |
| 895 |
|
| 896 |
self.assertEqual(realpath(ABSTFN + "/subdir", strict=False), ABSTFN + "/subdir") |
| 897 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/subdir", strict=True) |
| 898 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/subdir", |
| 899 |
strict=ALLOW_MISSING) |
| 900 |
finally: |
| 901 |
os_helper.unlink(ABSTFN) |
| 902 |
|
| 903 |
@os_helper.skip_unless_symlink |
| 904 |
@skip_if_ABSTFN_contains_backslash |
| 905 |
def test_realpath_nonterminal_symlink_to_file(self): |
| 906 |
try: |
| 907 |
with open(ABSTFN + "1", 'w') as f: |
| 908 |
f.write('test_posixpath wuz ere') |
| 909 |
os.symlink(ABSTFN + "1", ABSTFN) |
| 910 |
self.assertEqual(realpath(ABSTFN, strict=False), ABSTFN + "1") |
| 911 |
self.assertEqual(realpath(ABSTFN, strict=True), ABSTFN + "1") |
| 912 |
self.assertEqual(realpath(ABSTFN, strict=ALLOW_MISSING), ABSTFN + "1") |
| 913 |
|
| 914 |
self.assertEqual(realpath(ABSTFN + "/", strict=False), ABSTFN + "1") |
| 915 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/", strict=True) |
| 916 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/", |
| 917 |
strict=ALLOW_MISSING) |
| 918 |
|
| 919 |
self.assertEqual(realpath(ABSTFN + "/.", strict=False), ABSTFN + "1") |
| 920 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/.", strict=True) |
| 921 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/.", |
| 922 |
strict=ALLOW_MISSING) |
| 923 |
|
| 924 |
self.assertEqual(realpath(ABSTFN + "/..", strict=False), dirname(ABSTFN)) |
| 925 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/..", strict=True) |
| 926 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/..", |
| 927 |
strict=ALLOW_MISSING) |
| 928 |
|
| 929 |
self.assertEqual(realpath(ABSTFN + "/subdir", strict=False), ABSTFN + "1/subdir") |
| 930 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/subdir", strict=True) |
| 931 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/subdir", |
| 932 |
strict=ALLOW_MISSING) |
| 933 |
finally: |
| 934 |
os_helper.unlink(ABSTFN) |
| 935 |
os_helper.unlink(ABSTFN + "1") |
| 936 |
|
| 937 |
@os_helper.skip_unless_symlink |
| 938 |
@skip_if_ABSTFN_contains_backslash |
| 939 |
def test_realpath_nonterminal_symlink_to_symlinks_to_file(self): |
| 940 |
try: |
| 941 |
with open(ABSTFN + "2", 'w') as f: |
| 942 |
f.write('test_posixpath wuz ere') |
| 943 |
os.symlink(ABSTFN + "2", ABSTFN + "1") |
| 944 |
os.symlink(ABSTFN + "1", ABSTFN) |
| 945 |
self.assertEqual(realpath(ABSTFN, strict=False), ABSTFN + "2") |
| 946 |
self.assertEqual(realpath(ABSTFN, strict=True), ABSTFN + "2") |
| 947 |
self.assertEqual(realpath(ABSTFN, strict=True), ABSTFN + "2") |
| 948 |
|
| 949 |
self.assertEqual(realpath(ABSTFN + "/", strict=False), ABSTFN + "2") |
| 950 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/", strict=True) |
| 951 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/", |
| 952 |
strict=ALLOW_MISSING) |
| 953 |
|
| 954 |
self.assertEqual(realpath(ABSTFN + "/.", strict=False), ABSTFN + "2") |
| 955 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/.", strict=True) |
| 956 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/.", |
| 957 |
strict=ALLOW_MISSING) |
| 958 |
|
| 959 |
self.assertEqual(realpath(ABSTFN + "/..", strict=False), dirname(ABSTFN)) |
| 960 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/..", strict=True) |
| 961 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/..", |
| 962 |
strict=ALLOW_MISSING) |
| 963 |
|
| 964 |
self.assertEqual(realpath(ABSTFN + "/subdir", strict=False), ABSTFN + "2/subdir") |
| 965 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/subdir", strict=True) |
| 966 |
self.assertRaises(NotADirectoryError, realpath, ABSTFN + "/subdir", |
| 967 |
strict=ALLOW_MISSING) |
| 968 |
finally: |
| 969 |
os_helper.unlink(ABSTFN) |
| 970 |
os_helper.unlink(ABSTFN + "1") |
| 971 |
os_helper.unlink(ABSTFN + "2") |
| 972 |
|
| 973 |
def test_relpath(self): |
| 974 |
(real_getcwd, os.getcwd) = (os.getcwd, lambda: r"/home/user/bar") |
| 975 |
try: |
| 976 |
curdir = os.path.split(os.getcwd())[-1] |
| 977 |
self.assertRaises(TypeError, posixpath.relpath, None) |
| 978 |
self.assertRaises(ValueError, posixpath.relpath, "") |
| 979 |
self.assertEqual(posixpath.relpath("a"), "a") |
| 980 |
self.assertEqual(posixpath.relpath(posixpath.abspath("a")), "a") |
| 981 |
self.assertEqual(posixpath.relpath("a/b"), "a/b") |
| 982 |
self.assertEqual(posixpath.relpath("../a/b"), "../a/b") |
| 983 |
self.assertEqual(posixpath.relpath("a", "../b"), "../"+curdir+"/a") |
| 984 |
self.assertEqual(posixpath.relpath("a/b", "../c"), |
| 985 |
"../"+curdir+"/a/b") |
| 986 |
self.assertEqual(posixpath.relpath("a", "b/c"), "../../a") |
| 987 |
self.assertEqual(posixpath.relpath("a", "a"), ".") |
| 988 |
self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x/y/z"), '../../../foo/bar/bat') |
| 989 |
self.assertEqual(posixpath.relpath("/foo/bar/bat", "/foo/bar"), 'bat') |
| 990 |
self.assertEqual(posixpath.relpath("/foo/bar/bat", "/"), 'foo/bar/bat') |
| 991 |
self.assertEqual(posixpath.relpath("/", "/foo/bar/bat"), '../../..') |
| 992 |
self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x"), '../foo/bar/bat') |
| 993 |
self.assertEqual(posixpath.relpath("/x", "/foo/bar/bat"), '../../../x') |
| 994 |
self.assertEqual(posixpath.relpath("/", "/"), '.') |
| 995 |
self.assertEqual(posixpath.relpath("/a", "/a"), '.') |
| 996 |
self.assertEqual(posixpath.relpath("/a/b", "/a/b"), '.') |
| 997 |
finally: |
| 998 |
os.getcwd = real_getcwd |
| 999 |
|
| 1000 |
def test_relpath_bytes(self): |
| 1001 |
(real_getcwdb, os.getcwdb) = (os.getcwdb, lambda: br"/home/user/bar") |
| 1002 |
try: |
| 1003 |
curdir = os.path.split(os.getcwdb())[-1] |
| 1004 |
self.assertRaises(ValueError, posixpath.relpath, b"") |
| 1005 |
self.assertEqual(posixpath.relpath(b"a"), b"a") |
| 1006 |
self.assertEqual(posixpath.relpath(posixpath.abspath(b"a")), b"a") |
| 1007 |
self.assertEqual(posixpath.relpath(b"a/b"), b"a/b") |
| 1008 |
self.assertEqual(posixpath.relpath(b"../a/b"), b"../a/b") |
| 1009 |
self.assertEqual(posixpath.relpath(b"a", b"../b"), |
| 1010 |
b"../"+curdir+b"/a") |
| 1011 |
self.assertEqual(posixpath.relpath(b"a/b", b"../c"), |
| 1012 |
b"../"+curdir+b"/a/b") |
| 1013 |
self.assertEqual(posixpath.relpath(b"a", b"b/c"), b"../../a") |
| 1014 |
self.assertEqual(posixpath.relpath(b"a", b"a"), b".") |
| 1015 |
self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/x/y/z"), b'../../../foo/bar/bat') |
| 1016 |
self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/foo/bar"), b'bat') |
| 1017 |
self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/"), b'foo/bar/bat') |
| 1018 |
self.assertEqual(posixpath.relpath(b"/", b"/foo/bar/bat"), b'../../..') |
| 1019 |
self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/x"), b'../foo/bar/bat') |
| 1020 |
self.assertEqual(posixpath.relpath(b"/x", b"/foo/bar/bat"), b'../../../x') |
| 1021 |
self.assertEqual(posixpath.relpath(b"/", b"/"), b'.') |
| 1022 |
self.assertEqual(posixpath.relpath(b"/a", b"/a"), b'.') |
| 1023 |
self.assertEqual(posixpath.relpath(b"/a/b", b"/a/b"), b'.') |
| 1024 |
|
| 1025 |
self.assertRaises(TypeError, posixpath.relpath, b"bytes", "str") |
| 1026 |
self.assertRaises(TypeError, posixpath.relpath, "str", b"bytes") |
| 1027 |
finally: |
| 1028 |
os.getcwdb = real_getcwdb |
| 1029 |
|
| 1030 |
def test_commonpath(self): |
| 1031 |
def check(paths, expected): |
| 1032 |
self.assertEqual(posixpath.commonpath(paths), expected) |
| 1033 |
self.assertEqual(posixpath.commonpath([os.fsencode(p) for p in paths]), |
| 1034 |
os.fsencode(expected)) |
| 1035 |
def check_error(exc, paths): |
| 1036 |
self.assertRaises(exc, posixpath.commonpath, paths) |
| 1037 |
self.assertRaises(exc, posixpath.commonpath, |
| 1038 |
[os.fsencode(p) for p in paths]) |
| 1039 |
|
| 1040 |
self.assertRaises(TypeError, posixpath.commonpath, None) |
| 1041 |
self.assertRaises(ValueError, posixpath.commonpath, []) |
| 1042 |
self.assertRaises(ValueError, posixpath.commonpath, iter([])) |
| 1043 |
check_error(ValueError, ['/usr', 'usr']) |
| 1044 |
check_error(ValueError, ['usr', '/usr']) |
| 1045 |
|
| 1046 |
check(['/usr/local'], '/usr/local') |
| 1047 |
check(['/usr/local', '/usr/local'], '/usr/local') |
| 1048 |
check(['/usr/local/', '/usr/local'], '/usr/local') |
| 1049 |
check(['/usr/local/', '/usr/local/'], '/usr/local') |
| 1050 |
check(['/usr//local', '//usr/local'], '/usr/local') |
| 1051 |
check(['/usr/./local', '/./usr/local'], '/usr/local') |
| 1052 |
check(['/', '/dev'], '/') |
| 1053 |
check(['/usr', '/dev'], '/') |
| 1054 |
check(['/usr/lib/', '/usr/lib/python3'], '/usr/lib') |
| 1055 |
check(['/usr/lib/', '/usr/lib64/'], '/usr') |
| 1056 |
|
| 1057 |
check(['/usr/lib', '/usr/lib64'], '/usr') |
| 1058 |
check(['/usr/lib/', '/usr/lib64'], '/usr') |
| 1059 |
|
| 1060 |
check(['spam'], 'spam') |
| 1061 |
check(['spam', 'spam'], 'spam') |
| 1062 |
check(['spam', 'alot'], '') |
| 1063 |
check(['and/jam', 'and/spam'], 'and') |
| 1064 |
check(['and//jam', 'and/spam//'], 'and') |
| 1065 |
check(['and/./jam', './and/spam'], 'and') |
| 1066 |
check(['and/jam', 'and/spam', 'alot'], '') |
| 1067 |
check(['and/jam', 'and/spam', 'and'], 'and') |
| 1068 |
|
| 1069 |
check([''], '') |
| 1070 |
check(['', 'spam/alot'], '') |
| 1071 |
check_error(ValueError, ['', '/spam/alot']) |
| 1072 |
|
| 1073 |
self.assertRaises(TypeError, posixpath.commonpath, |
| 1074 |
[b'/usr/lib/', '/usr/lib/python3']) |
| 1075 |
self.assertRaises(TypeError, posixpath.commonpath, |
| 1076 |
[b'/usr/lib/', 'usr/lib/python3']) |
| 1077 |
self.assertRaises(TypeError, posixpath.commonpath, |
| 1078 |
[b'usr/lib/', '/usr/lib/python3']) |
| 1079 |
self.assertRaises(TypeError, posixpath.commonpath, |
| 1080 |
['/usr/lib/', b'/usr/lib/python3']) |
| 1081 |
self.assertRaises(TypeError, posixpath.commonpath, |
| 1082 |
['/usr/lib/', b'usr/lib/python3']) |
| 1083 |
self.assertRaises(TypeError, posixpath.commonpath, |
| 1084 |
['usr/lib/', b'/usr/lib/python3']) |
| 1085 |
|
| 1086 |
|
| 1087 |
class PosixCommonTest(test_genericpath.CommonTest, unittest.TestCase): |
| 1088 |
pathmodule = posixpath |
| 1089 |
attributes = ['relpath', 'samefile', 'sameopenfile', 'samestat'] |
| 1090 |
|
| 1091 |
|
| 1092 |
class PathLikeTests(unittest.TestCase): |
| 1093 |
|
| 1094 |
path = posixpath |
| 1095 |
|
| 1096 |
def setUp(self): |
| 1097 |
self.file_name = TESTFN |
| 1098 |
self.file_path = FakePath(TESTFN) |
| 1099 |
self.addCleanup(os_helper.unlink, self.file_name) |
| 1100 |
with open(self.file_name, 'xb', 0) as file: |
| 1101 |
file.write(b"test_posixpath.PathLikeTests") |
| 1102 |
|
| 1103 |
def assertPathEqual(self, func): |
| 1104 |
self.assertEqual(func(self.file_path), func(self.file_name)) |
| 1105 |
|
| 1106 |
def test_path_normcase(self): |
| 1107 |
self.assertPathEqual(self.path.normcase) |
| 1108 |
|
| 1109 |
def test_path_isabs(self): |
| 1110 |
self.assertPathEqual(self.path.isabs) |
| 1111 |
|
| 1112 |
def test_path_join(self): |
| 1113 |
self.assertEqual(self.path.join('a', FakePath('b'), 'c'), |
| 1114 |
self.path.join('a', 'b', 'c')) |
| 1115 |
|
| 1116 |
def test_path_split(self): |
| 1117 |
self.assertPathEqual(self.path.split) |
| 1118 |
|
| 1119 |
def test_path_splitext(self): |
| 1120 |
self.assertPathEqual(self.path.splitext) |
| 1121 |
|
| 1122 |
def test_path_splitdrive(self): |
| 1123 |
self.assertPathEqual(self.path.splitdrive) |
| 1124 |
|
| 1125 |
def test_path_splitroot(self): |
| 1126 |
self.assertPathEqual(self.path.splitroot) |
| 1127 |
|
| 1128 |
def test_path_basename(self): |
| 1129 |
self.assertPathEqual(self.path.basename) |
| 1130 |
|
| 1131 |
def test_path_dirname(self): |
| 1132 |
self.assertPathEqual(self.path.dirname) |
| 1133 |
|
| 1134 |
def test_path_islink(self): |
| 1135 |
self.assertPathEqual(self.path.islink) |
| 1136 |
|
| 1137 |
def test_path_lexists(self): |
| 1138 |
self.assertPathEqual(self.path.lexists) |
| 1139 |
|
| 1140 |
def test_path_ismount(self): |
| 1141 |
self.assertPathEqual(self.path.ismount) |
| 1142 |
|
| 1143 |
def test_path_expanduser(self): |
| 1144 |
self.assertPathEqual(self.path.expanduser) |
| 1145 |
|
| 1146 |
def test_path_expandvars(self): |
| 1147 |
self.assertPathEqual(self.path.expandvars) |
| 1148 |
|
| 1149 |
def test_path_normpath(self): |
| 1150 |
self.assertPathEqual(self.path.normpath) |
| 1151 |
|
| 1152 |
def test_path_abspath(self): |
| 1153 |
self.assertPathEqual(self.path.abspath) |
| 1154 |
|
| 1155 |
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING}) |
| 1156 |
def test_path_realpath(self, kwargs): |
| 1157 |
self.assertPathEqual(self.path.realpath) |
| 1158 |
|
| 1159 |
self.assertPathEqual(partial(self.path.realpath, **kwargs)) |
| 1160 |
|
| 1161 |
def test_path_relpath(self): |
| 1162 |
self.assertPathEqual(self.path.relpath) |
| 1163 |
|
| 1164 |
def test_path_commonpath(self): |
| 1165 |
common_path = self.path.commonpath([self.file_path, self.file_name]) |
| 1166 |
self.assertEqual(common_path, self.file_name) |
| 1167 |
|
| 1168 |
|
| 1169 |
if __name__=="__main__": |
| 1170 |
unittest.main() |