Skip to content

Commit 12149fb

Browse files
committed
Rewrite docstrings of some private helpers in doctest format so they are tested
1 parent 9b80f6e commit 12149fb

File tree

5 files changed

+50
-23
lines changed

5 files changed

+50
-23
lines changed

fs/_ftp_parse.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@
5656

5757

5858
def get_decoders():
59-
"""
60-
Returns all available FTP LIST line decoders with their matching regexes.
61-
"""
59+
"""Return all available FTP LIST line decoders with their matching regexes."""
6260
decoders = [
6361
(RE_LINUX, decode_linux),
6462
(RE_WINDOWSNT, decode_windowsnt),
@@ -149,13 +147,34 @@ def _decode_windowsnt_time(mtime):
149147

150148

151149
def decode_windowsnt(line, match):
152-
"""
153-
Decodes a Windows NT FTP LIST line like one of these:
150+
"""Decode a Windows NT FTP LIST line.
151+
152+
Examples:
153+
Decode a directory line::
154+
155+
>>> line = "11-02-18 02:12PM <DIR> images"
156+
>>> match = RE_WINDOWSNT.match(line)
157+
>>> pprint(decode_windowsnt(line, match))
158+
{'basic': {'is_dir': True, 'name': 'images'},
159+
'details': {'modified': 1518358320.0, 'type': 1},
160+
'ftp': {'ls': '11-02-18 02:12PM <DIR> images'}}
161+
162+
Decode a file line::
163+
164+
>>> line = "11-02-18 03:33PM 9276 logo.gif"
165+
>>> match = RE_WINDOWSNT.match(line)
166+
>>> pprint(decode_windowsnt(line, match))
167+
{'basic': {'is_dir': False, 'name': 'logo.gif'},
168+
'details': {'modified': 1518363180.0, 'size': 9276, 'type': 2},
169+
'ftp': {'ls': '11-02-18 03:33PM 9276 logo.gif'}}
170+
171+
Alternatively, the time might also be present in 24-hour format::
154172
155-
`11-02-18 02:12PM <DIR> images`
156-
`11-02-18 03:33PM 9276 logo.gif`
173+
>>> line = "11-02-18 15:33 9276 logo.gif"
174+
>>> match = RE_WINDOWSNT.match(line)
175+
>>> decode_windowsnt(line, match)["details"]["modified"]
176+
1518363180.0
157177
158-
Alternatively, the time (02:12PM) might also be present in 24-hour format (14:12).
159178
"""
160179
is_dir = match.group("size") == "<DIR>"
161180

fs/_url_tools.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111

1212
def url_quote(path_snippet):
1313
# type: (Text) -> Text
14-
"""
15-
On Windows, it will separate drive letter and quote windows
16-
path alone. No magic on Unix-alie path, just pythonic
17-
`pathname2url`
14+
"""Quote a URL without quoting the Windows drive letter, if any.
15+
16+
On Windows, it will separate drive letter and quote Windows
17+
path alone. No magic on Unix-like path, just pythonic
18+
`~urllib.request.pathname2url`.
1819
1920
Arguments:
20-
path_snippet: a file path, relative or absolute.
21+
path_snippet (str): a file path, relative or absolute.
22+
2123
"""
2224
if _WINDOWS_PLATFORM and _has_drive_letter(path_snippet):
2325
drive_letter, path = path_snippet.split(":", 1)
@@ -34,17 +36,19 @@ def url_quote(path_snippet):
3436

3537
def _has_drive_letter(path_snippet):
3638
# type: (Text) -> bool
37-
"""
38-
The following path will get True
39-
D:/Data
40-
C:\\My Dcouments\\ test
39+
"""Check whether a path contains a drive letter.
4140
42-
And will get False
41+
Arguments:
42+
path_snippet (str): a file path, relative or absolute.
4343
44-
/tmp/abc:test
44+
Example:
45+
>>> _has_drive_letter("D:/Data")
46+
True
47+
>>> _has_drive_letter(r"C:\\System32\\ test")
48+
True
49+
>>> _has_drive_letter("/tmp/abc:test")
50+
False
4551
46-
Arguments:
47-
path_snippet: a file path, relative or absolute.
4852
"""
4953
windows_drive_pattern = ".:[/\\\\].*$"
5054
return re.match(windows_drive_pattern, path_snippet) is not None

fs/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ def getmeta(self, namespace="standard"):
709709
network.
710710
read_only `True` if this filesystem is read only.
711711
supports_rename `True` if this filesystem supports an
712-
`os.rename` operation (or equivalent).
712+
`os.rename` operation.
713713
=================== ============================================
714714
715715
Most builtin filesystems will provide all these keys, and third-

fs/opener/registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def open_fs(
217217
filesystem *needs* to be writable, which is relevant for
218218
some archive filesystems. Passing ``writeable=False`` will
219219
**not** make the return filesystem read-only. For this,
220-
consider using `fs.wrap.WrapReadOnly` to wrap the returned
220+
consider using `fs.wrap.read_only` to wrap the returned
221221
instance.
222222
223223
"""

tests/test_doctest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import types
99
import warnings
1010
import tempfile
11+
import time
1112
import unittest
13+
from pprint import pprint
1214

1315
try:
1416
from unittest import mock
@@ -142,6 +144,8 @@ def tearDown(self):
142144
OSFS=lambda path: MemoryFS(),
143145
# NB (@althonos): This is for compatibility in `fs.registry`
144146
print_list=lambda path: None,
147+
pprint=pprint,
148+
time=time,
145149
)
146150

147151
# load the doctests into the unittest test suite

0 commit comments

Comments
 (0)