Skip to content

Commit bab4094

Browse files
committed
Tidying up PathPlus tests
1 parent 64a4fe8 commit bab4094

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

tests/test_paths.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from domdf_python_tools import paths
2121
from domdf_python_tools.paths import clean_writer, PathPlus
2222

23-
2423
# TODO: delete, write, read and append might want deprecating in favour of pathlib
2524

2625

tests/test_paths_stdlib.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
# this package
2121
from domdf_python_tools.paths import PathPlus, PosixPathPlus, WindowsPathPlus
2222

23-
2423
try:
25-
import grp, pwd
24+
# stdlib
25+
import grp
26+
import pwd
2627
except ImportError:
2728
grp = pwd = None # type: ignore
2829

@@ -198,6 +199,7 @@ class PathTest(unittest.TestCase):
198199
cls = PathPlus
199200

200201
def setUp(self):
202+
201203
def cleanup():
202204
os.chmod(join('dirE'), 0o777)
203205
support.rmtree(BASE)
@@ -232,13 +234,15 @@ def cleanup():
232234
def dirlink(self, src, dest):
233235
os.symlink(src, dest, target_is_directory=True)
234236
else:
237+
235238
def dirlink(self, src, dest):
236239
os.symlink(src, dest)
237240

238241
def assertSame(self, path_a, path_b):
239242
self.assertTrue(
240243
os.path.samefile(str(path_a), str(path_b)),
241-
f"{path_a!r} and {path_b!r} don't point to the same file")
244+
f"{path_a!r} and {path_b!r} don't point to the same file"
245+
)
242246

243247
def assertFileNotFound(self, func, *args, **kwargs):
244248
with self.assertRaises(FileNotFoundError) as cm:
@@ -346,8 +350,7 @@ def test_read_write_bytes(self):
346350
def test_read_write_text(self):
347351
p = PathPlus(BASE)
348352
(p / 'fileA').write_text('äbcdefg', encoding='latin-1')
349-
self.assertEqual((p / 'fileA').read_text(
350-
encoding='utf-8', errors='ignore'), 'bcdefg')
353+
self.assertEqual((p / 'fileA').read_text(encoding='utf-8', errors='ignore'), 'bcdefg')
351354
# check that trying to write bytes does not truncate the file
352355
self.assertRaises(TypeError, (p / 'fileA').write_text, b'somebytes')
353356
self.assertEqual((p / 'fileA').read_text(encoding='latin-1'), 'äbcdefg')
@@ -381,6 +384,7 @@ def test_iterdir_nodir(self):
381384
self.assertIn(cm.exception.errno, (errno.ENOTDIR, errno.ENOENT, errno.EINVAL))
382385

383386
def test_glob_common(self):
387+
384388
def _check(glob, expected):
385389
self.assertEqual(set(glob), {P(BASE, q) for q in expected})
386390

@@ -405,6 +409,7 @@ def _check(glob, expected):
405409
_check(p.glob("*/fileB"), ['dirB/fileB', 'linkB/fileB'])
406410

407411
def test_rglob_common(self):
412+
408413
def _check(glob, expected):
409414
self.assertEqual(set(glob), {P(BASE, q) for q in expected})
410415

@@ -418,8 +423,7 @@ def _check(glob, expected):
418423
if symlink_skip_reason:
419424
_check(p.rglob("*/fileB"), ["dirB/fileB"])
420425
else:
421-
_check(p.rglob("*/fileB"), ["dirB/fileB", "dirB/linkD/fileB",
422-
"linkB/fileB", "dirA/linkC/fileB"])
426+
_check(p.rglob("*/fileB"), ["dirB/fileB", "dirB/linkD/fileB", "linkB/fileB", "dirA/linkC/fileB"])
423427
_check(p.rglob("file*"), ["fileA", "dirB/fileB", "dirC/fileC", "dirC/dirD/fileD"])
424428
p = P(BASE, "dirC")
425429
_check(p.rglob("file*"), ["dirC/fileC", "dirC/dirD/fileD"])
@@ -433,9 +437,15 @@ def test_rglob_symlink_loop(self):
433437
given = set(p.rglob('*'))
434438
expect = {
435439
'brokenLink',
436-
'dirA', 'dirA/linkC',
437-
'dirB', 'dirB/fileB', 'dirB/linkD',
438-
'dirC', 'dirC/dirD', 'dirC/dirD/fileD', 'dirC/fileC',
440+
'dirA',
441+
'dirA/linkC',
442+
'dirB',
443+
'dirB/fileB',
444+
'dirB/linkD',
445+
'dirC',
446+
'dirC/dirD',
447+
'dirC/dirD/fileD',
448+
'dirC/fileC',
439449
'dirE',
440450
'fileA',
441451
'linkA',
@@ -907,8 +917,7 @@ def test_is_socket_true(self):
907917
try:
908918
sock.bind(str(P))
909919
except OSError as e:
910-
if (isinstance(e, PermissionError) or
911-
"AF_UNIX path too long" in str(e)):
920+
if isinstance(e, PermissionError) or "AF_UNIX path too long" in str(e):
912921
self.skipTest("cannot bind Unix socket: " + str(e))
913922
self.assertTrue(P.is_socket())
914923
self.assertFalse(P.is_fifo())
@@ -1008,8 +1017,7 @@ def test_complex_symlinks_relative_dot_dot(self):
10081017

10091018
def test_concrete_class(self):
10101019
p = PathPlus('a')
1011-
self.assertIs(type(p),
1012-
WindowsPathPlus if os.name == 'nt' else PosixPathPlus)
1020+
self.assertIs(type(p), WindowsPathPlus if os.name == 'nt' else PosixPathPlus)
10131021

10141022
def test_unsupported_flavour(self):
10151023
if os.name == 'nt':

0 commit comments

Comments
 (0)