Skip to content

Commit 2d4ad01

Browse files
committed
more test coverage
1 parent cc933ef commit 2d4ad01

66 files changed

Lines changed: 238 additions & 484 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apprise/apprise.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def _create_notify_gen(
494494
f"type: {self.asset.encoding}"
495495
)
496496
logger.error(msg)
497-
raise TypeError(msg)
497+
raise TypeError(msg) from None
498498

499499
# Tracks conversions
500500
conversion_body_map = {}
@@ -581,7 +581,7 @@ def _create_notify_gen(
581581
# Must be of string type
582582
msg = "Failed to escape message body"
583583
logger.error(msg)
584-
raise TypeError(msg)
584+
raise TypeError(msg) from None
585585

586586
if server.interpret_emojis:
587587
#

apprise/apprise.pyi

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

apprise/apprise_attachment.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,8 @@ def __init__(
102102
self.location = location
103103

104104
# Now parse any paths specified
105-
if paths is not None:
106-
# Store our path(s)
107-
if not self.add(paths):
108-
# Parse Source domain based on from_addr
109-
raise TypeError("One or more attachments could not be added.")
105+
if paths is not None and not self.add(paths):
106+
raise TypeError("One or more attachments could not be added.")
110107

111108
def add(self, attachments, asset=None, cache=None):
112109
"""Adds one or more attachments into our list.

apprise/apprise_attachment.pyi

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

apprise/apprise_config.pyi

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

apprise/asset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def __init__(
255255
raise ValueError(
256256
"AppriseAsset namespace_salt(): "
257257
"Value provided could not be encoded"
258-
)
258+
) from None
259259

260260
else: # Unsupported
261261
raise ValueError(

apprise/asset.pyi

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

apprise/attachment/base.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def __init__(self, name=None, mimetype=None, cache=None, **kwargs):
160160
except (TypeError, ValueError):
161161
err = f"An invalid cache value ({cache}) was specified."
162162
self.logger.warning(err)
163-
raise TypeError(err)
163+
raise TypeError(err) from None
164164

165165
# Some simple error checking
166166
if self.cache < 0:
@@ -172,8 +172,7 @@ def __init__(self, name=None, mimetype=None, cache=None, **kwargs):
172172
self.cache = None
173173

174174
# Validate mimetype if specified
175-
if self._mimetype:
176-
if (
175+
if self._mimetype and (
177176
next(
178177
(
179178
t
@@ -182,11 +181,10 @@ def __init__(self, name=None, mimetype=None, cache=None, **kwargs):
182181
),
183182
None,
184183
)
185-
is None
186-
):
187-
err = f"An invalid mime-type ({mimetype}) was specified."
188-
self.logger.warning(err)
189-
raise TypeError(err)
184+
is None):
185+
err = f"An invalid mime-type ({mimetype}) was specified."
186+
self.logger.warning(err)
187+
raise TypeError(err)
190188

191189
return
192190

@@ -318,9 +316,9 @@ def base64(self, encoding="ascii"):
318316
else base64.b64encode(f.read())
319317
)
320318

321-
except (TypeError, FileNotFoundError):
319+
except (FileNotFoundError):
322320
# We no longer have a path to open
323-
raise exception.AppriseFileNotFound("Attachment Missing")
321+
raise exception.AppriseFileNotFound("Attachment Missing") from None
324322

325323
except (TypeError, OSError) as e:
326324
self.logger.warning(
@@ -329,7 +327,8 @@ def base64(self, encoding="ascii"):
329327
)
330328
)
331329
self.logger.debug(f"I/O Exception: {e!s}")
332-
raise exception.AppriseDiskIOError("Attachment Access Error")
330+
raise exception.AppriseDiskIOError(
331+
"Attachment Access Error") from e
333332

334333
def invalidate(self):
335334
"""Release any temporary data that may be open by child classes.
@@ -367,7 +366,7 @@ def download(self):
367366

368367
def open(self, mode="rb"):
369368
"""Return our file pointer and track it (we'll auto close later)"""
370-
pointer = open(self.path, mode=mode)
369+
pointer = open(self.path, mode=mode) # noqa: SIM115
371370
self.__pointers.add(pointer)
372371
return pointer
373372

apprise/attachment/base.pyi

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

apprise/attachment/http.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def download(self, **kwargs):
113113

114114
url = f"{self.schema}://{self.host}"
115115
if isinstance(self.port, int):
116-
url += ":%d" % self.port
116+
url += f":{self.port}"
117117

118118
url += self.fullpath
119119

@@ -194,7 +194,8 @@ def download(self, **kwargs):
194194
# to False or it isn't compatible with Microsoft Windows
195195
# instances. In lieu of this, __del__ will clean up the
196196
# file for us.
197-
self._temp_file = NamedTemporaryFile(delete=False)
197+
self._temp_file = \
198+
NamedTemporaryFile(delete=False) # noqa: SIM115
198199

199200
# Get our chunk size
200201
chunk_size = self.chunk_size
@@ -219,8 +220,8 @@ def download(self, **kwargs):
219220
self.logger.error(
220221
"HTTP response exceeds allowable"
221222
" maximum file length"
222-
f" ({int(self.max_file_size / 1024)}KB):"
223-
f" {self.url(privacy=True)}"
223+
f" ({int(self.max_file_size / 1024)}"
224+
f"KB): {self.url(privacy=True)}"
224225
)
225226

226227
# Invalidate any variables previously set

0 commit comments

Comments
 (0)