Skip to content

Commit 840f829

Browse files
committed
Linting and updated copyright
1 parent 07b2e3b commit 840f829

File tree

10 files changed

+77
-80
lines changed

10 files changed

+77
-80
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ python:
55
- '3.7'
66
- "3.8"
77
install:
8-
- pip install -U coveralls pytest pytz
8+
- pip install coveralls -r tests/requirements.txt
99
script:
10-
- coverage run --source=domdf_python_tools -m pytest
10+
- pytest --cov=sdjson tests/
1111
after_success:
1212
- coveralls
1313
deploy:

domdf_python_tools/__init__.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Compiled 2018-2019 by Dominic Davis-Foster <[email protected]>
1+
# Compiled 2018-2020 by Dominic Davis-Foster <[email protected]>
22
#
33
# terminal.py
44
# Copyright © 2014-2019 Dominic Davis-Foster <[email protected]>
@@ -8,7 +8,7 @@
88
# Copyright © 2011 jtriley
99
#
1010
# paths.py
11-
# Copyright © 2018-2019 Dominic Davis-Foster <[email protected]>
11+
# Copyright © 2018-2020 Dominic Davis-Foster <[email protected]>
1212
#
1313
# copytree based on https://stackoverflow.com/a/12514470/3092681
1414
# Copyright © 2012 atzz
@@ -21,14 +21,29 @@
2121
# Copyright © 1995-2000 Corporation for National Research Initiatives . All rights reserved.
2222
# Copyright © 1991-1995 Stichting Mathematisch Centrum . All rights reserved.
2323
#
24+
# This program is free software; you can redistribute it and/or modify
25+
# it under the terms of the GNU Lesser General Public License as published by
26+
# the Free Software Foundation; either version 3 of the License, or
27+
# (at your option) any later version.
28+
#
29+
# This program is distributed in the hope that it will be useful,
30+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
31+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32+
# GNU Lesser General Public License for more details.
33+
#
34+
# You should have received a copy of the GNU Lesser General Public License
35+
# along with this program; if not, write to the Free Software
36+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
37+
# MA 02110-1301, USA.
38+
#
2439

2540
from domdf_python_tools.utils import *
2641
from domdf_python_tools import paths, terminal, utils, doctools
2742

2843
__all__ = ["paths", "terminal", "utils", "dates"]
2944

3045
__author__ = "Dominic Davis-Foster"
31-
__copyright__ = "2014-2019 Dominic Davis-Foster"
46+
__copyright__ = "2014-2020 Dominic Davis-Foster"
3247

3348
__license__ = "LGPLv3+"
3449
__version__ = "0.2.1"

domdf_python_tools/paths.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Functions for paths and files
77
"""
88
#
9-
# Copyright © 2018-2019 Dominic Davis-Foster <[email protected]>
9+
# Copyright © 2018-2020 Dominic Davis-Foster <[email protected]>
1010
#
1111
# check_dependencies based on https://stackoverflow.com/a/29044693/3092681
1212
# Copyright © 2015 TehTechGuy
@@ -58,15 +58,26 @@ def copytree(src, dst, symlinks=False, ignore=None):
5858
:type src: str
5959
:param dst: Destination to copy file to
6060
:type dst: str
61-
:param symlinks: Whether to represent symbolic links in the source as symbolic links in the destination
62-
If false or omitted, the contents and metadata of the linked files are copied to the new tree.
63-
When symlinks is false, if the file pointed by the symlink doesn’t exist, an exception will be added in the list of errors raised in an Error exception at the end of the copy process. You can set the optional ignore_dangling_symlinks flag to true if you want to silence this exception. Notice that this option has no effect on platforms that don’t support os.symlink().
61+
:param symlinks: Whether to represent symbolic links in the source as symbolic
62+
links in the destination. If false or omitted, the contents and metadata
63+
of the linked files are copied to the new tree. When symlinks is false,
64+
if the file pointed by the symlink doesn't exist, an exception will be
65+
added in the list of errors raised in an Error exception at the end of
66+
the copy process. You can set the optional ignore_dangling_symlinks
67+
flag to true if you want to silence this exception. Notice that this
68+
option has no effect on platforms that don’t support os.symlink().
6469
:type symlinks: bool
65-
:param ignore: A callable that will receive as its arguments the source directory, and a list of its contents.
66-
The ignore callable will be called once for each directory that is copied.
67-
The callable must return a sequence of directory and file names relative to the current directory (i.e. a subset of the items in its second argument); these names will then be ignored in the copy process. ignore_patterns() can be used to create such a callable that ignores names based on glob-style patterns.
70+
:param ignore: A callable that will receive as its arguments the source
71+
directory, and a list of its contents. The ignore callable will be
72+
called once for each directory that is copied. The callable must return
73+
a sequence of directory and file names relative to the current
74+
directory (i.e. a subset of the items in its second argument); these
75+
names will then be ignored in the copy process. ignore_patterns() can
76+
be used to create such a callable that ignores names based on
77+
glob-style patterns.
6878
6979
:return:
80+
:rtype:
7081
"""
7182

7283
import shutil
@@ -119,7 +130,8 @@ def relpath(path, relative_to=None):
119130
120131
:param path: Path to find the relative path for
121132
:type path: str
122-
:param relative_to: The directory to find the path relative to. Defaults to the current working directory (i.e. os.getcwd())
133+
:param relative_to: The directory to find the path relative to.
134+
Defaults to the current working directory (i.e. os.getcwd())
123135
:type relative_to: str
124136
125137
:return:
@@ -128,8 +140,10 @@ def relpath(path, relative_to=None):
128140
if relative_to is None:
129141
relative_to = os.getcwd()
130142

131-
#if os.path.normpath(os.path.abspath(path)).startswith(os.path.normpath(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))):
132-
if os.path.normpath(os.path.abspath(path)).startswith(os.path.normpath(os.path.dirname(os.path.dirname(os.path.abspath(relative_to))))):
143+
# if os.path.normpath(os.path.abspath(path)).startswith(
144+
# os.path.normpath(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))):
145+
if os.path.normpath(os.path.abspath(path)).startswith(
146+
os.path.normpath(os.path.dirname(os.path.dirname(os.path.abspath(relative_to))))):
133147
return os.path.relpath(os.path.abspath(path))
134148
else:
135149
return os.path.abspath(path)

domdf_python_tools/terminal.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Useful functions for terminal-based programs
77
"""
88
#
9-
# Copyright © 2014-2019 Dominic Davis-Foster <[email protected]>
9+
# Copyright © 2014-2020 Dominic Davis-Foster <[email protected]>
1010
#
1111
# get_terminal_size, _get_terminal_size_windows, _get_terminal_size_tput and _get_terminal_size_linux
1212
# from https://gist.github.com/jtriley/1108174
@@ -64,7 +64,6 @@ def br():
6464
print("")
6565

6666

67-
6867
def interrupt():
6968
"""
7069
Print what to do to abort the script; dynamic depending on OS
@@ -94,7 +93,9 @@ def overtype(*objects, sep=' ', end='', file=sys.stdout, flush=False):
9493
:param file: An object with a ``write(string)`` method; default ``sys.stdout``
9594
:param flush: If true, the stream is forcibly flushed.
9695
:type flush: bool
96+
9797
:return:
98+
:rtype:
9899
"""
99100

100101
object0 = f"\r{objects[0]}"
@@ -111,6 +112,7 @@ def get_terminal_size():
111112
Originally retrieved from: http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python
112113
113114
:return: tuple_xy
115+
:rtype:
114116
"""
115117

116118
current_os = platform.system()
@@ -138,9 +140,11 @@ def _get_terminal_size_windows():
138140
csbi = create_string_buffer(22)
139141
res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
140142
if res:
141-
(buf_x, buf_y, cur_x, cur_y, wattr,
142-
left, top, right, bottom,
143-
maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
143+
(
144+
buf_x, buf_y, cur_x, cur_y, wattr,
145+
left, top, right, bottom,
146+
maxx, maxy,
147+
) = struct.unpack("hhhhHhhhhhh", csbi.raw)
144148
size_x = right - left + 1
145149
size_y = bottom - top + 1
146150
return size_x, size_y

domdf_python_tools/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
General Functions
77
"""
88
#
9-
# Copyright © 2018-2019 Dominic Davis-Foster <[email protected]>
9+
# Copyright © 2018-2020 Dominic Davis-Foster <[email protected]>
1010
#
1111
# This program is free software; you can redistribute it and/or modify
1212
# it under the terms of the GNU Lesser General Public License as published by
@@ -100,7 +100,7 @@ def check_dependencies(dependencies, prt=True):
100100

101101
missing_modules = []
102102
for requirement in dependencies:
103-
if not requirement in modules:
103+
if requirement not in modules:
104104
missing_modules.append(requirement)
105105

106106
if prt:

tests/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pytest >= 5.1.1
2+
pytest-cov >= 2.8.1
3+
pytz >= 2019.1
4+
coverage>=5.1

tests/test_dates.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def test_utc_offset():
4242
# TODO: Finish
4343

4444

45-
4645
def test_converting_timezone():
4746
# No matter what timezone we convert to the timestamp should be the same
4847
for tz in pytz.all_timezones:

tests/test_doctools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# TODO: test sphinxification of docstrings
1717

18+
1819
class Cafe:
1920
"""
2021
Generic class for a Cafe
@@ -197,7 +198,8 @@ def test_decorators():
197198

198199
# Functions
199200
assert undocumented_function.__doc__ == documented_function.__doc__
200-
assert partially_documented_function.__doc__.startswith("\nThis function works like documented function except it returns the result telepathically.")
201+
assert partially_documented_function.__doc__.startswith(
202+
"\nThis function works like documented function except it returns the result telepathically.")
201203
assert doctools.deindent_string(partially_documented_function.__doc__).endswith(
202204
doctools.deindent_string(documented_function.__doc__))
203205
# Deindented both strings to be sure of equivalence
@@ -234,5 +236,3 @@ def funC():
234236

235237
doctools.append_doctring_from_another(funB, funC)
236238
assert funB.__doc__ == "Hello\nWorld"
237-
238-

tests/test_init.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/test_utils.py

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,66 +13,46 @@
1313

1414
import pytest
1515

16-
from domdf_python_tools.utils import str2tuple, tuple2str, chunks, list2str, list2string, bdict
16+
from domdf_python_tools.utils import str2tuple, tuple2str, chunks, list2str, list2string, bdict, pyversion
1717
from domdf_python_tools import utils
1818

1919

20+
def test_pyversion():
21+
assert isinstance(pyversion, int)
22+
23+
2024
def test_str2tuple():
2125
assert isinstance(str2tuple("1,2,3"), tuple) # tests without spaces
2226
assert isinstance(str2tuple("1, 2, 3"), tuple) # tests with spaces
2327
assert isinstance(str2tuple("1; 2; 3", sep=";"), tuple) # tests with semicolon
24-
if str2tuple("1,2,3") == (1, 2, 3):
25-
assert 1
26-
else:
27-
assert 0
28+
assert str2tuple("1,2,3") == (1, 2, 3)
2829

2930

3031
def test_tuple2str():
3132
assert isinstance(tuple2str(("1", "2", "3",)), str)
32-
if tuple2str((1, 2, 3)) == "1,2,3":
33-
assert 1
34-
else:
35-
assert 0
33+
assert tuple2str((1, 2, 3)) == "1,2,3"
3634

3735
assert isinstance(tuple2str((1, 2, 3,), sep=";"), str) # tests with semicolon
38-
if tuple2str((1, 2, 3), sep=";") == "1;2;3":
39-
assert 1
40-
else:
41-
assert 0
36+
assert tuple2str((1, 2, 3), sep=";") == "1;2;3"
4237

4338

4439
def test_chunks():
4540
assert isinstance(chunks(list(range(100)), 5), types.GeneratorType)
46-
if list(chunks(list(range(100)), 5))[0] == [0, 1, 2, 3, 4]:
47-
assert 1
48-
else:
49-
assert 0
41+
assert list(chunks(list(range(100)), 5))[0] == [0, 1, 2, 3, 4]
5042

5143

5244
def test_list2str():
5345
assert isinstance(list2str([1, 2, 3, ]), str)
54-
if list2str([1, 2, 3]) == "1,2,3":
55-
assert 1
56-
else:
57-
assert 0
46+
assert list2str([1, 2, 3]) == "1,2,3"
5847

5948
assert isinstance(list2str([1, 2, 3], sep=";"), str) # tests with semicolon
60-
if list2str((1, 2, 3), sep=";") == "1;2;3":
61-
assert 1
62-
else:
63-
assert 0
49+
assert list2str((1, 2, 3), sep=";") == "1;2;3"
6450

6551
assert isinstance(list2string([1, 2, 3, ]), str)
66-
if list2string([1, 2, 3]) == "1,2,3":
67-
assert 1
68-
else:
69-
assert 0
52+
assert list2string([1, 2, 3]) == "1,2,3"
7053

7154
assert isinstance(list2string([1, 2, 3], sep=";"), str) # tests with semicolon
72-
if list2string((1, 2, 3), sep=";") == "1;2;3":
73-
assert 1
74-
else:
75-
assert 0
55+
assert list2string((1, 2, 3), sep=";") == "1;2;3"
7656

7757

7858
def test_bdict():
@@ -110,13 +90,13 @@ def test_bdict_booleans():
11090
new_dict = bdict(original_dict)
11191

11292
assert new_dict[True] == "True"
113-
assert new_dict["True"] == True
93+
assert new_dict["True"]
11494

11595
original_dict = {True: True, False: False, None: None}
11696

11797
new_dict = bdict(original_dict)
11898

119-
assert new_dict[True] is True
99+
assert new_dict[True]
120100

121101

122102
def test_bdict_from_zip():
@@ -231,4 +211,3 @@ def test_permutations():
231211

232212
with pytest.raises(ValueError):
233213
utils.permutations(data, 0)
234-

0 commit comments

Comments
 (0)