Skip to content

Commit 1385352

Browse files
committed
Use yapf for code formatting
1 parent dee33d7 commit 1385352

File tree

5 files changed

+68
-43
lines changed

5 files changed

+68
-43
lines changed

domdf_python_tools/paths.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def copytree(
7676
src: Union[str, pathlib.Path, os.PathLike],
7777
dst: Union[str, pathlib.Path, os.PathLike],
7878
symlinks: bool = False,
79-
ignore: Callable = None):
79+
ignore: Callable = None,
80+
):
8081
"""
8182
Alternative to :func:`shutil.copytree` to work in some situations where it doesn't.
8283
@@ -135,7 +136,8 @@ def maybe_make(
135136
directory: Union[str, pathlib.Path, os.PathLike],
136137
mode=0o777,
137138
parents: bool = False,
138-
exist_ok: bool = False):
139+
exist_ok: bool = False
140+
):
139141
"""
140142
Create a directory at this given path, but only if the directory does not already exist.
141143
@@ -201,7 +203,10 @@ def read(filename: Union[str, pathlib.Path, os.PathLike]) -> str:
201203
return f.read()
202204

203205

204-
def relpath(path: Union[str, pathlib.Path, os.PathLike], relative_to: Union[str, pathlib.Path, os.PathLike] = None) -> pathlib.Path:
206+
def relpath(
207+
path: Union[str, pathlib.Path, os.PathLike],
208+
relative_to: Union[str, pathlib.Path, os.PathLike] = None
209+
) -> pathlib.Path:
205210
"""
206211
Returns the path for the given file or directory relative to the given
207212
directory or, if that would require path traversal, returns the absolute path.
@@ -250,4 +255,3 @@ def write(var: AnyStr, filename: Union[str, pathlib.Path, os.PathLike]):
250255

251256
with open(os.path.join(os.getcwd(), filename), 'w') as f:
252257
f.write(var)
253-

domdf_python_tools/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,3 @@ def str2tuple(input_string: str, sep: str = ",") -> Tuple[int]:
205205
"""
206206

207207
return tuple(int(x) for x in input_string.split(sep))
208-

tests/test_bases.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,5 @@ def test_namedlist(capsys):
114114
stdout = captured.out.split("\n")
115115
assert stdout[0] == "<class 'domdf_python_tools.bases.namedlist.<locals>.NamedList'>"
116116
assert stdout[1] == "['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']"
117-
assert stdout[2] == "ShoppingList['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']"
117+
assert stdout[2] == (
118+
"ShoppingList['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']")

tests/test_paths.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# this package
1919
from domdf_python_tools import paths
2020

21-
2221
# TODO: Still need tests for copytree, relpath, relpath2, delete, write,
2322
# read and append.
2423
# Some of those might want deprecating in favour of pathlib
@@ -69,19 +68,23 @@ def test_parent_path():
6968
assert str(paths.parent_path("spam/spam/spam")) == "spam/spam"
7069

7170

72-
@pytest.mark.parametrize("relto, relpath", [
73-
("/home/username/Documents/games/chess.py", "/home/username/Documents/letter.doc"),
74-
("/home/username/Documents", "letter.doc"),
75-
(pathlib.Path("/home/username/Documents/games/chess.py"), "/home/username/Documents/letter.doc"),
76-
(pathlib.Path("/home/username/Documents"), "letter.doc"),
77-
])
71+
@pytest.mark.parametrize(
72+
"relto, relpath",
73+
[
74+
("/home/username/Documents/games/chess.py", "/home/username/Documents/letter.doc"),
75+
("/home/username/Documents", "letter.doc"),
76+
(pathlib.Path("/home/username/Documents/games/chess.py"), "/home/username/Documents/letter.doc"),
77+
(pathlib.Path("/home/username/Documents"), "letter.doc"),
78+
]
79+
)
7880
def test_relpath(relto, relpath):
7981
path = "/home/username/Documents/letter.doc"
8082
assert paths.relpath(path, relative_to=relto) == pathlib.Path(relpath)
8183
assert isinstance(paths.relpath(path, relative_to=relto), pathlib.Path)
8284

8385

8486
class TestCurrentDirOperations:
87+
8588
def test_append(self):
8689
file = pathlib.Path("paths_append_test_file.txt")
8790
file.write_text("initial content\n")

tests/test_utils.py

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ def test_pyversion():
2121
assert isinstance(pyversion, int)
2222

2323

24-
@pytest.mark.parametrize("value, expects", [
25-
(12345, "12345"),
26-
(123.45, "123.45"),
27-
([123.45], "[123.45]"),
28-
({123.45}, "{123.45}"),
29-
((123.45, ), "(123.45,)"),
30-
(None, ""),
31-
(pathlib.Path("."), "."),
32-
(decimal.Decimal("1234"), "1234"),
33-
])
24+
@pytest.mark.parametrize(
25+
"value, expects",
26+
[
27+
(12345, "12345"),
28+
(123.45, "123.45"),
29+
([123.45], "[123.45]"),
30+
({123.45}, "{123.45}"),
31+
((123.45, ), "(123.45,)"),
32+
(None, ""),
33+
(pathlib.Path("."), "."),
34+
(decimal.Decimal("1234"), "1234"),
35+
]
36+
)
3437
def test_as_text(value, expects):
3538
assert utils.as_text(value) == expects
3639

@@ -69,15 +72,19 @@ def test_chunks():
6972
assert list(chunks(list(range(100)), 5))[0] == [0, 1, 2, 3, 4]
7073
assert list(chunks(["a", "b", "c"], 1)) == [["a"], ["b"], ["c"]]
7174

75+
7276
# TODO: cmp
7377

7478

75-
@pytest.mark.parametrize("value, expects", [
76-
([1, 2, 3], "1,2,3"),
77-
(["a", "b", "c"], "a,b,c"),
78-
(["a", "b", 1, 2], "a,b,1,2"),
79-
(["a", 2, pathlib.Path("foo.txt")], "a,2,foo.txt"),
80-
])
79+
@pytest.mark.parametrize(
80+
"value, expects",
81+
[
82+
([1, 2, 3], "1,2,3"),
83+
(["a", "b", "c"], "a,b,c"),
84+
(["a", "b", 1, 2], "a,b,1,2"),
85+
(["a", 2, pathlib.Path("foo.txt")], "a,2,foo.txt"),
86+
]
87+
)
8188
def test_list2str(value, expects):
8289
str_representation = list2str(value)
8390
assert isinstance(str_representation, str)
@@ -88,12 +95,15 @@ def test_list2str(value, expects):
8895
assert str_representation == expects
8996

9097

91-
@pytest.mark.parametrize("value, expects", [
92-
([1, 2, 3], "1;2;3"),
93-
(["a", "b", "c"], "a;b;c"),
94-
(["a", "b", 1, 2], "a;b;1;2"),
95-
(["a", 2, pathlib.Path("foo.txt")], "a;2;foo.txt"),
96-
])
98+
@pytest.mark.parametrize(
99+
"value, expects",
100+
[
101+
([1, 2, 3], "1;2;3"),
102+
(["a", "b", "c"], "a;b;c"),
103+
(["a", "b", 1, 2], "a;b;1;2"),
104+
(["a", 2, pathlib.Path("foo.txt")], "a;2;foo.txt"),
105+
]
106+
)
97107
def test_list2str_semicolon(value, expects):
98108
str_representation = list2str(value, sep=";")
99109
assert isinstance(str_representation, str)
@@ -159,6 +169,7 @@ def test_permutations():
159169

160170

161171
class CustomRepr:
172+
162173
def __init__(self):
163174
pass
164175

@@ -167,6 +178,7 @@ def __repr__(self):
167178

168179

169180
class NoRepr:
181+
170182
def __init__(self):
171183
pass
172184

@@ -211,19 +223,25 @@ def test_split_len():
211223
assert utils.split_len("Spam Spam Spam Spam Spam Spam Spam Spam ", 5) == ["Spam "] * 8
212224

213225

214-
@pytest.mark.parametrize("value, expects", [
215-
("1,2,3", (1, 2, 3)), # tests without spaces
216-
("1, 2, 3", (1, 2, 3)), # tests with spaces
217-
])
226+
@pytest.mark.parametrize(
227+
"value, expects",
228+
[
229+
("1,2,3", (1, 2, 3)), # tests without spaces
230+
("1, 2, 3", (1, 2, 3)), # tests with spaces
231+
]
232+
)
218233
def test_str2tuple(value, expects):
219234
assert isinstance(str2tuple(value), tuple)
220235
assert str2tuple(value) == expects
221236

222237

223-
@pytest.mark.parametrize("value, expects", [
224-
("1;2;3", (1, 2, 3)), # tests without semicolon
225-
("1; 2; 3", (1, 2, 3)), # tests with semicolon
226-
])
238+
@pytest.mark.parametrize(
239+
"value, expects",
240+
[
241+
("1;2;3", (1, 2, 3)), # tests without semicolon
242+
("1; 2; 3", (1, 2, 3)), # tests with semicolon
243+
]
244+
)
227245
def test_str2tuple_semicolon(value, expects):
228246
assert isinstance(str2tuple(value, sep=";"), tuple)
229247
assert str2tuple(value, sep=";") == expects

0 commit comments

Comments
 (0)