Skip to content

Commit 5ef90f3

Browse files
authored
Merge pull request #224 from pkkid/covcov
Covcov
2 parents 0e4d53a + 47e4c9d commit 5ef90f3

18 files changed

+246
-80
lines changed

.coveragerc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ exclude_lines =
33
pragma: no cover
44
raise NotImplementedError
55
raise Unsupported
6+
raise Exception
67
except ImportError
8+
except BadRequest
79
def __repr__
810
def __bool__
9-
if __name__ == .__main__.:
11+
def __iter__
12+
def __hash__
13+
def __len__
14+
if __name__ == .__main__.:

plexapi/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@
3535
logformat = CONFIG.get('log.format', '%(asctime)s %(module)12s:%(lineno)-4s %(levelname)-9s %(message)s')
3636
loglevel = CONFIG.get('log.level', 'INFO').upper()
3737
loghandler = logging.NullHandler()
38-
if logfile:
38+
39+
if logfile: # pragma: no cover
3940
logbackups = CONFIG.get('log.backup_count', 3, int)
4041
logbytes = CONFIG.get('log.rotate_bytes', 512000, int)
4142
loghandler = RotatingFileHandler(os.path.expanduser(logfile), 'a', logbytes, logbackups)
43+
4244
loghandler.setFormatter(logging.Formatter(logformat))
4345
log.addHandler(loghandler)
4446
log.setLevel(loglevel)

plexapi/alert.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def run(self):
3232
url = self._server.url(self.key).replace('http', 'ws')
3333
log.info('Starting AlertListener: %s', url)
3434
self._ws = websocket.WebSocketApp(url, on_message=self._onMessage,
35-
on_error=self._onError)
35+
on_error=self._onError)
3636
self._ws.run_forever()
3737

3838
def stop(self):
@@ -47,12 +47,12 @@ def _onMessage(self, ws, message):
4747
""" Called when websocket message is recieved. """
4848
try:
4949
data = json.loads(message)['NotificationContainer']
50-
log.debug('Alert: %s', data)
50+
log.debug('Alert: %s %s %s', *data)
5151
if self._callback:
5252
self._callback(data)
53-
except Exception as err:
53+
except Exception as err: # pragma: no cover
5454
log.error('AlertListener Msg Error: %s', err)
5555

56-
def _onError(self, ws, err):
56+
def _onError(self, ws, err): # pragma: no cover
5757
""" Called when websocket error is recieved. """
5858
log.error('AlertListener Error: %s' % err)

plexapi/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def playMedia(self, media, offset=0, **params):
444444
if not self.product != 'OpenPHT':
445445
try:
446446
self.sendCommand('timeline/subscribe', port=server_url[1].strip('/'), protocol='http')
447-
except:
447+
except: # noqa: E722
448448
# some clients dont need or like this and raises http 400.
449449
# We want to include the exception in the log,
450450
# but it might still work so we swallow it.

plexapi/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get(self, key, default=None, cast=None):
3535
section, name = key.lower().split('.')
3636
value = self.data.get(section, {}).get(name, default)
3737
return cast(value) if cast else value
38-
except:
38+
except: # noqa: E722
3939
return default
4040

4141
def _asDict(self):

plexapi/media.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def _loadData(self, data):
148148
self.type = cast(int, data.attrib.get('streamType'))
149149

150150
@staticmethod
151-
def parse(server, data, initpath):
151+
def parse(server, data, initpath): # pragma: no cover seems to be dead code.
152152
""" Factory method returns a new MediaPartStream from xml data. """
153153
STREAMCLS = {1: VideoStream, 2: AudioStream, 3: SubtitleStream}
154154
stype = cast(int, data.attrib.get('streamType'))

plexapi/myplex.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ def query(self, url, method=None, headers=None, timeout=None, **kwargs):
150150
log.debug('%s %s %s', method.__name__.upper(), url, kwargs.get('json', ''))
151151
headers = self._headers(**headers or {})
152152
response = method(url, headers=headers, timeout=timeout, **kwargs)
153-
if response.status_code not in (200, 201, 204):
153+
if response.status_code not in (200, 201, 204): # pragma: no cover
154154
codename = codes.get(response.status_code)[0]
155155
errtext = response.text.replace('\n', ' ')
156-
log.warn('BadRequest (%s) %s %s; %s' % (response.status_code, codename, response.url, errtext))
156+
log.warning('BadRequest (%s) %s %s; %s' % (response.status_code, codename, response.url, errtext))
157157
raise BadRequest('(%s) %s %s; %s' % (response.status_code, codename, response.url, errtext))
158158
data = response.text.encode('utf8')
159159
return ElementTree.fromstring(data) if data.strip() else None
@@ -428,8 +428,8 @@ def _loadData(self, data):
428428
self.recommendationsPlaylistId = data.attrib.get('recommendationsPlaylistId')
429429
self.restricted = data.attrib.get('restricted')
430430
self.thumb = data.attrib.get('thumb')
431-
self.title = data.attrib.get('title')
432-
self.username = data.attrib.get('username')
431+
self.title = data.attrib.get('title', '')
432+
self.username = data.attrib.get('username', '')
433433
self.servers = self.findItems(data, MyPlexServerShare)
434434

435435
def get_token(self, machineIdentifier):

plexapi/photo.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def albums(self, **kwargs):
5454
def album(self, title):
5555
""" Returns the :class:`~plexapi.photo.Photoalbum` that matches the specified title. """
5656
for album in self.albums():
57-
if album.attrib.get('title').lower() == title.lower():
57+
if album.title.lower() == title.lower():
5858
return album
5959
raise NotFound('Unable to find album: %s' % title)
6060

@@ -66,17 +66,10 @@ def photos(self, **kwargs):
6666
def photo(self, title):
6767
""" Returns the :class:`~plexapi.photo.Photo` that matches the specified title. """
6868
for photo in self.photos():
69-
if photo.attrib.get('title').lower() == title.lower():
69+
if photo.title.lower() == title.lower():
7070
return photo
7171
raise NotFound('Unable to find photo: %s' % title)
7272

73-
def reload(self):
74-
""" Reload the data for this object from self.key. """
75-
self._initpath = self.key
76-
data = self._server.query(self.key)
77-
self._loadData(data)
78-
return self
79-
8073

8174
@utils.registerPlexObject
8275
class Photo(PlexPartialObject):

plexapi/playlist.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ def _loadData(self, data):
3434
self.updatedAt = toDatetime(data.attrib.get('updatedAt'))
3535
self._items = None # cache for self.items
3636

37-
def __len__(self):
37+
def __len__(self): # pragma: no cover
3838
return len(self.items())
3939

40-
def __contains__(self, other):
40+
def __contains__(self, other): # pragma: no cover
4141
return any(i.key == other.key for i in self.items())
4242

43-
def __getitem__(self, key):
43+
def __getitem__(self, key): # pragma: no cover
4444
return self.items()[key]
4545

4646
def items(self):
@@ -57,7 +57,7 @@ def addItems(self, items):
5757
items = [items]
5858
ratingKeys = []
5959
for item in items:
60-
if item.listType != self.playlistType:
60+
if item.listType != self.playlistType: # pragma: no cover
6161
raise BadRequest('Can not mix media types when building a playlist: %s and %s' %
6262
(self.playlistType, item.listType))
6363
ratingKeys.append(str(item.ratingKey))
@@ -108,7 +108,7 @@ def create(cls, server, title, items):
108108
items = [items]
109109
ratingKeys = []
110110
for item in items:
111-
if item.listType != items[0].listType:
111+
if item.listType != items[0].listType: # pragma: no cover
112112
raise BadRequest('Can not mix media types when building a playlist')
113113
ratingKeys.append(str(item.ratingKey))
114114
ratingKeys = ','.join(ratingKeys)

plexapi/utils.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ def cast(func, value):
7474
return value
7575

7676

77-
def getattributeOrNone(obj, self, attr):
78-
""" Returns result from __getattribute__ or None if not found. """
79-
try:
80-
return super(obj, self).__getattribute__(attr)
81-
except AttributeError:
82-
return None
83-
84-
8577
def joinArgs(args):
8678
""" Returns a query string (uses for HTTP URLs) where only the value is URL encoded.
8779
Example return value: '?genre=action&type=1337'.
@@ -129,7 +121,7 @@ def rget(obj, attrstr, default=None, delim='.'): # pragma: no cover
129121
if attrstr:
130122
return rget(value, attrstr, default, delim)
131123
return value
132-
except:
124+
except: # noqa: E722
133125
return default
134126

135127

@@ -198,7 +190,8 @@ def toList(value, itemcast=None, delim=','):
198190
return [itemcast(item) for item in value.split(delim) if item != '']
199191

200192

201-
def downloadSessionImages(server, filename=None, height=150, width=150, opacity=100, saturation=100):
193+
def downloadSessionImages(server, filename=None, height=150, width=150,
194+
opacity=100, saturation=100): # pragma: no cover
202195
""" Helper to download a bif image or thumb.url from plex.server.sessions.
203196
204197
Parameters:
@@ -243,7 +236,7 @@ def download(url, filename=None, savepath=None, session=None, chunksize=4024,
243236
mocked (bool): Helper to do evertything except write the file.
244237
unpack (bool): Unpack the zip file.
245238
showstatus(bool): Display a progressbar.
246-
239+
247240
Example:
248241
>>> download(a_episode.getStreamURL(), a_episode.location)
249242
/path/to/file
@@ -278,7 +271,7 @@ def download(url, filename=None, savepath=None, session=None, chunksize=4024,
278271

279272
# save the file to disk
280273
log.info('Downloading: %s', fullpath)
281-
if showstatus:
274+
if showstatus: # pragma: no cover
282275
total = int(response.headers.get('content-length', 0))
283276
bar = tqdm(unit='B', unit_scale=True, total=total, desc=filename)
284277

@@ -288,7 +281,7 @@ def download(url, filename=None, savepath=None, session=None, chunksize=4024,
288281
if showstatus:
289282
bar.update(len(chunk))
290283

291-
if showstatus:
284+
if showstatus: # pragma: no cover
292285
bar.close()
293286
# check we want to unzip the contents
294287
if fullpath.endswith('zip') and unpack:
@@ -314,7 +307,7 @@ def tag_helper(tag, items, locked=True, remove=False):
314307
return data
315308

316309

317-
def getMyPlexAccount(opts=None):
310+
def getMyPlexAccount(opts=None): # pragma: no cover
318311
""" Helper function tries to get a MyPlex Account instance by checking
319312
the the following locations for a username and password. This is
320313
useful to create user-friendly command line tools.
@@ -341,7 +334,7 @@ def getMyPlexAccount(opts=None):
341334
return MyPlexAccount(username, password)
342335

343336

344-
def choose(msg, items, attr):
337+
def choose(msg, items, attr): # pragma: no cover
345338
""" Command line helper to display a list of choices, asking the
346339
user to choose one of the options.
347340
"""

0 commit comments

Comments
 (0)