| 1 |
""" |
| 2 |
Tests for Posix-flavoured pathlib.types._JoinablePath |
| 3 |
""" |
| 4 |
|
| 5 |
import os |
| 6 |
import unittest |
| 7 |
|
| 8 |
from .support import is_pypi |
| 9 |
from .support.lexical_path import LexicalPosixPath |
| 10 |
|
| 11 |
|
| 12 |
class JoinTestBase: |
| 13 |
def test_join(self): |
| 14 |
P = self.cls |
| 15 |
p = P('//a') |
| 16 |
pp = p.joinpath('b') |
| 17 |
self.assertEqual(pp, P('//a/b')) |
| 18 |
pp = P('/a').joinpath('//c') |
| 19 |
self.assertEqual(pp, P('//c')) |
| 20 |
pp = P('//a').joinpath('/c') |
| 21 |
self.assertEqual(pp, P('/c')) |
| 22 |
|
| 23 |
def test_div(self): |
| 24 |
# Basically the same as joinpath(). |
| 25 |
P = self.cls |
| 26 |
p = P('//a') |
| 27 |
pp = p / 'b' |
| 28 |
self.assertEqual(pp, P('//a/b')) |
| 29 |
pp = P('/a') / '//c' |
| 30 |
self.assertEqual(pp, P('//c')) |
| 31 |
pp = P('//a') / '/c' |
| 32 |
self.assertEqual(pp, P('/c')) |
| 33 |
|
| 34 |
|
| 35 |
class LexicalPosixPathJoinTest(JoinTestBase, unittest.TestCase): |
| 36 |
cls = LexicalPosixPath |
| 37 |
|
| 38 |
|
| 39 |
if not is_pypi: |
| 40 |
from pathlib import PurePosixPath, PosixPath |
| 41 |
|
| 42 |
class PurePosixPathJoinTest(JoinTestBase, unittest.TestCase): |
| 43 |
cls = PurePosixPath |
| 44 |
|
| 45 |
if os.name != 'nt': |
| 46 |
class PosixPathJoinTest(JoinTestBase, unittest.TestCase): |
| 47 |
cls = PosixPath |
| 48 |
|
| 49 |
|
| 50 |
if __name__ == "__main__": |
| 51 |
unittest.main() |