Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit ae8a661

Browse files
authored
Removes lint R0201 (#369)
* Removes lint R0201 * code coverage * lint * Update os_helper.py
1 parent 96bdca3 commit ae8a661

24 files changed

+139
-162
lines changed

_doc/sphinxdoc/source/conf.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,14 @@
1212
from pyquickhelper.helpgen.default_conf import set_sphinx_variables
1313

1414

15-
def callback_begin():
16-
print("[sphinx.conf.py] documentation started.")
17-
18-
1915
set_sphinx_variables(__file__, "pyquickhelper", "Xavier Dupré", 2022,
2016
"alabaster", alabaster.get_path(),
2117
locals(),
2218
github_repo="https://github.com/sdpython/pyquickhelper.git",
2319
extlinks=dict(issue=(
2420
'https://github.com/sdpython/pyquickhelper/issues/%s',
2521
'issue ')),
26-
link_resolve="http://www.xavierdupre.fr/app/",
27-
callback_begin=callback_begin)
22+
link_resolve="http://www.xavierdupre.fr/app/")
2823

2924
# there is an issue with this attribute on Anaconda math_number_all
3025
assert math_number_all or not math_number_all

_unittests/ut_helpgen/test_missing_function_helpgen.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import sys
77
import os
88
import unittest
9-
109
from pyquickhelper.pycode import ExtTestCase, skipif_vless, skipif_azure, skipif_appveyor
1110
from pyquickhelper.helpgen.utils_sphinx_config import NbImage
1211
from pyquickhelper.helpgen.post_process import remove_character_under32
@@ -18,13 +17,20 @@
1817
from pyquickhelper.helpgen.sphinx_helper import everything_but_python
1918
from pyquickhelper.helpgen.rst_converters import correct_indentation
2019
from pyquickhelper.helpgen.sphinxm_mock_app import MockSphinxApp
20+
from pyquickhelper.helpgen.utils_sphinx_config import _NbImage, getsitepackages
21+
from pyquickhelper.helpgen.sphinx_main_verification import SphinxVerificationException
22+
from pyquickhelper.helpgen.helpgen_exceptions import HelpGenException
2123

2224

2325
class TestMissingFunctionsHelpgen(ExtTestCase):
2426

2527
def test_nb_image(self):
2628
r = NbImage("completion.png")
2729
self.assertTrue(r is not None)
30+
self.assertRaise(lambda: NbImage("_completion.png"), FileNotFoundError)
31+
self.assertRaise(lambda: _NbImage("_completion.png"), FileNotFoundError)
32+
r = _NbImage("completion.png")
33+
self.assertTrue(r is not None)
2834

2935
def test_remove_character_under32(self):
3036
s = "a\na\r"
@@ -93,6 +99,16 @@ def test_correct_indentation(self):
9399
ded = text.replace(" ", "")
94100
self.assertEqual(ded.strip(" \n\r"), new_text.strip(" \n\r"))
95101

102+
def test_getsitepackages(self):
103+
res = getsitepackages()
104+
self.assertIsInstance(res, list)
105+
106+
def test_SphinxVerificationException(self):
107+
exc = SphinxVerificationException([])
108+
self.assertNotEmpty(exc)
109+
exc = HelpGenException('msg')
110+
self.assertNotEmpty(exc)
111+
96112

97113
if __name__ == "__main__":
98114
unittest.main()

_unittests/ut_loghelper/test_missing.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,31 @@
22
@brief test tree node (time=1s)
33
"""
44

5-
65
import sys
76
import os
87
import unittest
9-
10-
from pyquickhelper.loghelper.flog import fLOG, IsEmptyString
8+
from pyquickhelper.pycode import ExtTestCase
9+
from pyquickhelper.loghelper.flog import IsEmptyString
1110
from pyquickhelper.loghelper.pqh_exception import PQHException
11+
from pyquickhelper.loghelper.os_helper import get_machine
1212

1313

14-
class TestMissing(unittest.TestCase):
14+
class TestMissing(ExtTestCase):
1515

1616
def test_exception(self):
17-
fLOG(
18-
__file__,
19-
self._testMethodName,
20-
OutputPrint=__name__ == "__main__")
21-
2217
try:
2318
raise PQHException("error", True)
2419
except PQHException:
2520
pass
2621

2722
def test_is_missing(self):
28-
fLOG(
29-
__file__,
30-
self._testMethodName,
31-
OutputPrint=__name__ == "__main__")
32-
3323
assert IsEmptyString("")
3424
assert IsEmptyString(None)
3525
assert not IsEmptyString("-")
3626

27+
def test_get_machine(self):
28+
self.assertIsInstance(get_machine(), str)
29+
3730

3831
if __name__ == "__main__":
3932
unittest.main()

_unittests/ut_pycode/test_LONG_full_unit_test_module_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def skip_function(name, code, duration):
8383
for command in ["version", "write_version", "clean_pyd",
8484
"build_script", "copy27",
8585
"run_pylint .*((myex)|(example_ext)).*[.]py$ "
86-
"-iC0103 -iR0201 -iC0123 -iC0111 -iW0611 -iE0401 -iE0611 -iE0401",
86+
"-iC0103 -iC0123 -iC0111 -iW0611 -iE0401 -iE0611 -iE0401",
8787
"unittests -e .*code_style.*",
8888
"unittests -g .*((ext)|(code_style)|(run_notebooks)).*",
8989
"unittests_LONG", "unittests_SKIP",

_unittests/ut_pycode/test_check_pep8_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def check_pep8_one_file():
3434

3535
def check_pep8_error_file():
3636
check_pep8(this, recursive=False,
37-
pylint_ignore=('C0111', 'R0201', 'C0103'),
37+
pylint_ignore=('C0111', 'C0103'),
3838
pattern="test_check_pep8_sample.py",
3939
neg_pattern="##",
4040
skip=["test_check_pep8_sample.py:15",

src/pyquickhelper/filehelper/anyfhelper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def change_file_status(folder, status=stat.S_IWRITE, strict=False,
9595
res.append(d)
9696
try:
9797
mode = os.stat(f).st_mode
98-
except FileNotFoundError:
98+
except FileNotFoundError: # pragma: no cover
9999
# it appends for some weird path
100100
warnings.warn(
101101
"[change_file_status] unable to find '{0}'".format(f), UserWarning)

src/pyquickhelper/filehelper/download_helper.py

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import http.client as http_client
1414
try:
1515
from http.client import InvalidURL
16-
except ImportError:
16+
except ImportError: # pragma: no cover
1717
InvalidURL = ValueError
1818

1919

@@ -93,51 +93,17 @@ def _local_loop(ur):
9393
else:
9494
with urllib_request.urlopen(url) as ur:
9595
res = ur.read()
96-
except (urllib_error.HTTPError, urllib_error.URLError,
97-
ConnectionRefusedError) as e:
98-
if raise_exception:
99-
raise InternetException(
100-
"Unable to retrieve content, url='{0}'".format(url)) from e
101-
warnings.warn(
102-
"Unable to retrieve content from '{0}' exc: {1}".format(url, e), ResourceWarning)
103-
return None
104-
except socket.timeout as e:
105-
if raise_exception:
106-
raise InternetException(
107-
"Unable to retrieve content, url='{0}'".format(url)) from e
108-
warnings.warn("unable to retrieve content from {0} because of timeout {1}: {2}".format(
109-
url, timeout, e), ResourceWarning)
110-
return None
111-
except ConnectionResetError as e:
112-
if raise_exception:
113-
raise InternetException(
114-
"Unable to retrieve content, url='{0}'".format(url)) from e
115-
warnings.warn(
116-
"unable to retrieve content from {0} because of ConnectionResetError: {1}".format(url, e), ResourceWarning)
117-
return None
118-
except http_client.BadStatusLine as e:
119-
if raise_exception:
120-
raise InternetException(
121-
"Unable to retrieve content, url='{0}'".format(url)) from e
122-
warnings.warn(
123-
"Unable to retrieve content from '{0}' because of http.client.BadStatusLine: {1}".format(url, e), ResourceWarning)
124-
return None
125-
except http_client.IncompleteRead as e:
126-
if raise_exception:
127-
raise InternetException(
128-
"Unable to retrieve content url='{0}'".format(url)) from e
129-
warnings.warn(
130-
"Unable to retrieve content from '{0}' because of http.client.IncompleteRead: {1}".format(url, e), ResourceWarning)
131-
return None
132-
except (ValueError, InvalidURL) as e:
96+
except (urllib_error.HTTPError, urllib_error.URLError, ConnectionRefusedError,
97+
socket.timeout, ConnectionResetError, http_client.BadStatusLine,
98+
http_client.IncompleteRead, ValueError, InvalidURL) as e:
13399
if raise_exception:
134100
raise InternetException(
135101
"Unable to retrieve content url='{0}'".format(url)) from e
136102
warnings.warn(
137103
"Unable to retrieve content from '{0}' because of {1}".format(url, e), ResourceWarning)
138104
return None
139105
except Exception as e:
140-
if raise_exception:
106+
if raise_exception: # pragma: no cover
141107
raise InternetException(
142108
"Unable to retrieve content, url='{0}', exc={1}".format(url, e)) from e
143109
warnings.warn(
@@ -152,7 +118,7 @@ def _local_loop(ur):
152118
if encoding is not None:
153119
try:
154120
content = res.decode(encoding)
155-
except UnicodeDecodeError as e:
121+
except UnicodeDecodeError as e: # pragma: no cover
156122
# it tries different encoding
157123

158124
laste = [e]

src/pyquickhelper/filehelper/encrypted_backup.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def enumerate_read_encrypt(self, fullname):
198198
try:
199199
data = f.read(self._threshold_size)
200200
cont = True
201-
except PermissionError as e:
201+
except PermissionError as e: # pragma: no cover
202202
yield e
203203
cont = False
204204
if cont:
@@ -209,7 +209,7 @@ def enumerate_read_encrypt(self, fullname):
209209
yield enc
210210
try:
211211
data = f.read(self._threshold_size)
212-
except PermissionError as e:
212+
except PermissionError as e: # pragma: no cover
213213
yield e
214214
cont = False
215215

@@ -226,14 +226,14 @@ def compress(self, data):
226226
# delay import
227227
try:
228228
import lzma
229-
except ImportError:
229+
except ImportError: # pragma: no cover
230230
import pylzma as lzma
231231
return lzma.compress(data)
232232
elif self._compress is None:
233233
return data
234234
else:
235-
raise ValueError(
236-
"unexpected compression algorithm {0}".format(self._compress))
235+
raise ValueError( # pragma: no cover
236+
"Unexpected compression algorithm '{0}'.".format(self._compress))
237237

238238
def decompress(self, data):
239239
"""
@@ -248,14 +248,14 @@ def decompress(self, data):
248248
# delay import
249249
try:
250250
import lzma
251-
except ImportError:
251+
except ImportError: # pragma: no cover
252252
import pylzma as lzma
253253
return lzma.decompress(data)
254254
elif self._compress is None:
255255
return data
256256
else:
257-
raise ValueError(
258-
"unexpected compression algorithm {0}".format(self._compress))
257+
raise ValueError( # pragma: no cover
258+
"Unexpected compression algorithm '{0}'.".format(self._compress))
259259

260260
def start_transfering(self):
261261
"""
@@ -278,8 +278,9 @@ def start_transfering(self):
278278
(i, len(total), sum_bytes))
279279
relp = os.path.relpath(file.fullname, self._root_local)
280280
if ".." in relp:
281-
raise ValueError("the local root is not accurate:\n{0}\nFILE:\n{1}\nRELPATH:\n{2}".format(
282-
self, file.fullname, relp))
281+
raise ValueError( # pragma: no cover
282+
"The local root is not accurate:\n{0}\nFILE:\n{1}\nRELPATH:\n{2}".format(
283+
self, file.fullname, relp))
283284

284285
path = self._root_remote + "/" + os.path.split(relp)[0]
285286
path = path.replace("\\", "/")
@@ -317,8 +318,9 @@ def start_transfering(self):
317318
issues.append((relp, err))
318319

319320
if len(issues) >= 5:
320-
raise EncryptedBackupError("too many issues:\n{0}".format(
321-
"\n".join("{0} -- {1}".format(a, b) for a, b in issues)))
321+
raise EncryptedBackupError( # pragma: no cover
322+
"Too many issues:\n{0}".format(
323+
"\n".join("{0} -- {1}".format(a, b) for a, b in issues)))
322324

323325
self.transfer_mapping()
324326
return done, issues
@@ -343,11 +345,11 @@ def retrieve(self, path, filename=None, root=None):
343345
@return filename or data
344346
"""
345347
if self.Mapping is None:
346-
raise EncryptedBackupError(
347-
"load the mapping with method load_mapping")
348+
raise EncryptedBackupError( # pragma: no cover
349+
"Load first the mapping with method load_mapping.")
348350
if path not in self.Mapping:
349-
raise EncryptedBackupError(
350-
"the mapping is not up to date or file {0} cannot be found".format(path))
351+
raise EncryptedBackupError( # pragma: no cover
352+
"The mapping is not up to date or file '{0}' cannot be found.".format(path))
351353
info = self.Mapping[path]
352354
if len(info.pieces) == 0:
353355
# the file is empty

src/pyquickhelper/filehelper/file_tree_node.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def __init__(self, root, file=None, filter=None, level=0, parent=None,
9292
@param fLOG logging function to use
9393
"""
9494
if root is None:
95-
raise ValueError("root cannot be None")
95+
raise ValueError( # pragma: no cover
96+
"root cannot be None.")
9697
self._root = root
9798
self._file = None if file is None else file
9899
self._children = []
@@ -109,12 +110,14 @@ def __init__(self, root, file=None, filter=None, level=0, parent=None,
109110
if not os.path.exists(root):
110111
raise PQHException("path '%s' does not exist" % root)
111112
if not os.path.isdir(root):
112-
raise PQHException("path '%s' is not a folder" % root)
113+
raise PQHException( # pragma: no cover
114+
"path '%s' is not a folder" % root)
113115

114116
if self._file is not None:
115117
if not self.exists():
116-
raise PQHException(
117-
"%s does not exist [%s,%s]" % (self.get_fullname(), root, file))
118+
raise PQHException( # pragma: no cover
119+
"%s does not exist [%s,%s]" % (
120+
self.get_fullname(), root, file))
118121

119122
self._fillstat()
120123
if self.isdir():
@@ -277,8 +280,9 @@ def _fill(self, filter, repository):
277280
@param repository use svn or git
278281
"""
279282
if not self.isdir():
280-
raise PQHException(
281-
"unable to look into a file %s full %s" % (self._file, self.get_fullname()))
283+
raise PQHException( # pragma: no cover
284+
"Unable to look into a file %r full %r." % (
285+
self._file, self.get_fullname()))
282286

283287
if repository:
284288
opt = "repo_ls"
@@ -309,7 +313,7 @@ def _fill(self, filter, repository):
309313
n = FileTreeNode(self._root, os.path.join(fi, a), filter, level=self._level + 1,
310314
parent=self, repository=repository, log=self._log,
311315
log1=self._log1 or self._log, fLOG=self.fLOG)
312-
except PQHException as e:
316+
except PQHException as e: # pragma: no cover
313317
if "does not exist" in str(e):
314318
self.fLOG(
315319
"a folder should exist, but is it is not, it continues [opt=%s]" % opt)
@@ -475,7 +479,7 @@ def remove(self):
475479
self.fLOG("removing ", full)
476480
try:
477481
os.remove(full)
478-
except OSError as e:
482+
except OSError as e: # pragma: no cover
479483
self.fLOG(
480484
"unable to remove ", full, " --- ", str(e).replace("\n", " "))
481485
self.fLOG("[pyqerror] ", e)
@@ -494,10 +498,11 @@ def copy_to(self, path, exc=True):
494498
the new file is older.
495499
"""
496500
if not os.path.exists(path):
497-
raise PQHException("this path does not exist: '{0}'".format(path))
501+
raise PQHException( # pragma: no cover
502+
"This path does not exist: '{0}'.".format(path))
498503
if self.isdir():
499-
raise PQHException(
500-
"this node represents a folder " + self.get_fullname())
504+
raise PQHException( # pragma: no cover
505+
"This node represents a folder %r." % self.get_fullname())
501506
full = self.get_fullname()
502507
temp = os.path.split(self._file)[0]
503508
dest = os.path.join(path, temp)
@@ -522,7 +527,7 @@ def copy_to(self, path, exc=True):
522527
if t1 > t2 and exc:
523528
raise PQHException(mes)
524529
warnings.warn(mes, RuntimeWarning)
525-
except OSError as e:
530+
except OSError as e: # pragma: no cover
526531
# else :
527532
self.fLOG("unable to copy file ", full, " to ", path)
528533
self.fLOG("[pyqerror]", e)

0 commit comments

Comments
 (0)