mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-22 11:43:13 +00:00
Test README examples
This commit is contained in:
parent
050e7fbd73
commit
50af39c6f3
3 changed files with 70 additions and 26 deletions
27
README.md
27
README.md
|
@ -57,8 +57,8 @@ for video in movies.search(unwatched=True):
|
|||
print(video.title)
|
||||
```
|
||||
```python
|
||||
# Example 2: Mark all Conan episodes watched.
|
||||
plex.library.get('Conan (2010)').markWatched()
|
||||
# Example 2: Mark all Game of Thrones episodes watched.
|
||||
plex.library.section('TV Shows').get('Game of Thrones').markWatched()
|
||||
```
|
||||
```python
|
||||
# Example 3: List all clients connected to the Server.
|
||||
|
@ -66,9 +66,9 @@ for client in plex.clients():
|
|||
print(client.title)
|
||||
```
|
||||
```python
|
||||
# Example 4: Play the movie Avatar on another client.
|
||||
# Example 4: Play the movie Cars on another client.
|
||||
# Note: Client must be on same network as server.
|
||||
avatar = plex.library.section('Movies').get('Avatar')
|
||||
avatar = plex.library.section('Movies').get('Cars')
|
||||
client = plex.client("Michael's iPhone")
|
||||
client.playMedia(avatar)
|
||||
```
|
||||
|
@ -78,29 +78,28 @@ for video in plex.search('Game'):
|
|||
print('%s (%s)' % (video.title, video.TYPE))
|
||||
```
|
||||
```python
|
||||
# Example 6: List all movies directed by the same person as Jurassic Park.
|
||||
# Example 6: List all movies directed by the same person as Die Hard.
|
||||
movies = plex.library.section('Movies')
|
||||
jurassic_park = movies.get('Jurassic Park')
|
||||
director = jurassic_park.directors[0]
|
||||
die_hard = movies.get('Die Hard')
|
||||
director = die_hard.directors[0]
|
||||
for movie in movies.search(None, director=director):
|
||||
print(movie.title)
|
||||
```
|
||||
```python
|
||||
# Example 7: List files for the latest episode of Friends.
|
||||
thelastone = plex.library.get('Friends').episodes()[-1]
|
||||
# Example 7: List files for the latest episode of The 100.
|
||||
thelastone = plex.library.section('TV Shows').get('The 100').episodes()[-1]
|
||||
for part in thelastone.iterParts():
|
||||
print(part.file)
|
||||
```
|
||||
```python
|
||||
# Example 8: Get a URL to stream a movie or show in another client
|
||||
jurassic_park = plex.library.section('Movies').get('Jurassic Park')
|
||||
print 'Run running the following command to play in VLC:'
|
||||
print 'vlc "%s"' % jurassic_park.getStreamUrl(videoResolution='800x600')
|
||||
die_hard = plex.library.section('Movies').get('Die Hard')
|
||||
print('Run running the following command to play in VLC:')
|
||||
print('vlc "%s"' % die_hard.getStreamURL(videoResolution='800x600'))
|
||||
```
|
||||
|
||||
```python
|
||||
# Example 9: Get audio/video/all playlists
|
||||
for playlist in self.plex.playlists():
|
||||
for playlist in plex.playlists():
|
||||
print(playlist.title)
|
||||
```
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import os, pytest, shlex, subprocess
|
||||
from os.path import abspath, dirname, join
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name == 'nt', reason='No make.bat specified for Windows')
|
||||
def test_build_documentation():
|
||||
docroot = join(dirname(dirname(abspath(__file__))), 'docs')
|
||||
cmd = shlex.split('/usr/bin/make html --warn-undefined-variables')
|
||||
proc = subprocess.Popen(cmd, cwd=docroot)
|
||||
status = proc.wait()
|
||||
assert status == 0
|
57
tests/test_misc.py
Normal file
57
tests/test_misc.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import pytest
|
||||
import shlex
|
||||
import subprocess
|
||||
from collections import defaultdict
|
||||
from os.path import abspath, dirname, join
|
||||
|
||||
SKIP_EXAMPLES = ['Example 4']
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name == 'nt', reason='No make.bat specified for Windows')
|
||||
def test_build_documentation():
|
||||
docroot = join(dirname(dirname(abspath(__file__))), 'docs')
|
||||
cmd = shlex.split('/usr/bin/make html --warn-undefined-variables')
|
||||
proc = subprocess.Popen(cmd, cwd=docroot)
|
||||
status = proc.wait()
|
||||
assert status == 0
|
||||
|
||||
|
||||
def test_readme_examples(pms):
|
||||
failed = 0
|
||||
examples = _fetch_examples(pms)
|
||||
assert len(examples), 'No examples found in README.md'
|
||||
for title, example in examples:
|
||||
if _check_run_example(title):
|
||||
try:
|
||||
print('\n%s\n%s' % (title, '-' * len(title)))
|
||||
exec('\n'.join(example))
|
||||
except Exception as err:
|
||||
failed += 1
|
||||
print('Error running test: %s\nError: %s' % (title, err))
|
||||
assert not failed, '%s examples raised an exception.' % failed
|
||||
|
||||
|
||||
def _fetch_examples(pms):
|
||||
parsing = False
|
||||
examples = []
|
||||
filepath = join(dirname(dirname(abspath(__file__))), 'README.md')
|
||||
with open(filepath, 'r') as handle:
|
||||
for line in handle.read().split('\n'):
|
||||
if line.startswith('# Example '):
|
||||
parsing = True
|
||||
title = line.lstrip('# ')
|
||||
examples.append([title, ['plex = pms']])
|
||||
elif parsing and line == '```':
|
||||
parsing = False
|
||||
elif parsing:
|
||||
examples[-1][1].append(line)
|
||||
return examples
|
||||
|
||||
|
||||
def _check_run_example(title):
|
||||
for skip_example in SKIP_EXAMPLES:
|
||||
if skip_example in title:
|
||||
return False
|
||||
return True
|
Loading…
Reference in a new issue