Skip to content

Commit b6c061a

Browse files
andrey-yantsenHellowlol
authored andcommitted
Bootstrap test plex (#290)
* fix markup in tests/conftest.py * add plex-bootstraptest
1 parent b18e186 commit b6c061a

File tree

3 files changed

+398
-5
lines changed

3 files changed

+398
-5
lines changed

plexapi/compat.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Python 2/3 compatability
33
# Always try Py3 first
44
import os
5+
import sys
56
from sys import version_info
67

78
ustr = str
@@ -51,3 +52,67 @@ def makedirs(name, mode=0o777, exist_ok=False):
5152
except OSError:
5253
if not os.path.isdir(name) or not exist_ok:
5354
raise
55+
56+
57+
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
58+
"""Given a command, mode, and a PATH string, return the path which
59+
conforms to the given mode on the PATH, or None if there is no such
60+
file.
61+
62+
`mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
63+
of os.environ.get("PATH"), or can be overridden with a custom search
64+
path.
65+
66+
Copied from https://hg.python.org/cpython/file/default/Lib/shutil.py
67+
"""
68+
# Check that a given file can be accessed with the correct mode.
69+
# Additionally check that `file` is not a directory, as on Windows
70+
# directories pass the os.access check.
71+
def _access_check(fn, mode):
72+
return (os.path.exists(fn) and os.access(fn, mode)
73+
and not os.path.isdir(fn))
74+
75+
# If we're given a path with a directory part, look it up directly rather
76+
# than referring to PATH directories. This includes checking relative to the
77+
# current directory, e.g. ./script
78+
if os.path.dirname(cmd):
79+
if _access_check(cmd, mode):
80+
return cmd
81+
return None
82+
83+
if path is None:
84+
path = os.environ.get("PATH", os.defpath)
85+
if not path:
86+
return None
87+
path = path.split(os.pathsep)
88+
89+
if sys.platform == "win32":
90+
# The current directory takes precedence on Windows.
91+
if not os.curdir in path:
92+
path.insert(0, os.curdir)
93+
94+
# PATHEXT is necessary to check on Windows.
95+
pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
96+
# See if the given file matches any of the expected path extensions.
97+
# This will allow us to short circuit when given "python.exe".
98+
# If it does match, only test that one, otherwise we have to try
99+
# others.
100+
if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
101+
files = [cmd]
102+
else:
103+
files = [cmd + ext for ext in pathext]
104+
else:
105+
# On other platforms you don't have things like PATHEXT to tell you
106+
# what file suffixes are executable, so just pass on cmd as-is.
107+
files = [cmd]
108+
109+
seen = set()
110+
for dir in path:
111+
normdir = os.path.normcase(dir)
112+
if not normdir in seen:
113+
seen.add(normdir)
114+
for thefile in files:
115+
name = os.path.join(dir, thefile)
116+
if _access_check(name, mode):
117+
return name
118+
return None

tests/conftest.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
# -*- coding: utf-8 -*-
22
# Running these tests requires a few things in your Plex Library.
3-
# Movies section containing both movies:
3+
# 1. Movies section containing both movies:
44
# * Sintel - https://durian.blender.org/
55
# * Elephants Dream - https://orange.blender.org/
66
# * Sita Sings the Blues - http://www.sitasingstheblues.com/
77
# * Big Buck Bunny - https://peach.blender.org/
8-
# TV Show section containing the shows:
8+
# 2. TV Show section containing the shows:
99
# * Game of Thrones (Season 1 and 2)
1010
# * The 100 (Seasons 1 and 2)
1111
# * (or symlink the above movies with proper names)
12-
# Music section containing the albums:
12+
# 3. Music section containing the albums:
1313
# Infinite State - Unmastered Impulses - https://github.com/kennethreitz/unmastered-impulses
1414
# Broke For Free - Layers - http://freemusicarchive.org/music/broke_for_free/Layers/
15-
# 3. A Photos section containing the photoalbums:
15+
# 4. A Photos section containing the photoalbums:
1616
# Cats (with cute cat photos inside)
17-
# 4. A TV Shows section containing at least two seasons of The 100.
1817
from datetime import datetime
1918
from functools import partial
2019

0 commit comments

Comments
 (0)