Python: Python 2 compatibility

This commit is contained in:
Vicki Pfau 2017-08-13 16:00:42 -07:00
parent 04713d9de1
commit d68e12c354
4 changed files with 7 additions and 7 deletions

View File

@ -21,7 +21,7 @@ class CinemaTest(object):
try: try:
with open(os.path.join(self.path, 'manifest.yml'), 'r') as f: with open(os.path.join(self.path, 'manifest.yml'), 'r') as f:
dictMerge(self.settings, yaml.safe_load(f)) dictMerge(self.settings, yaml.safe_load(f))
except FileNotFoundError: except IOError:
pass pass
self.tests = {} self.tests = {}
@ -66,7 +66,7 @@ class VideoTest(CinemaTest):
try: try:
baseline = VideoFrame.load(os.path.join(self.path, self.BASELINE % i)) baseline = VideoFrame.load(os.path.join(self.path, self.BASELINE % i))
yield baseline, frame, VideoFrame.diff(baseline, frame) yield baseline, frame, VideoFrame.diff(baseline, frame)
except FileNotFoundError: except IOError:
yield None, frame, (None, None) yield None, frame, (None, None)
def test(self): def test(self):
@ -83,7 +83,7 @@ def gatherTests(root=os.getcwd()):
test = [f for f in files if re.match(CinemaTest.TEST, f)] test = [f for f in files if re.match(CinemaTest.TEST, f)]
if not test: if not test:
continue continue
prefix = os.path.commonpath([path, root]) prefix = os.path.commonprefix([path, root])
suffix = path[len(prefix)+1:] suffix = path[len(prefix)+1:]
testPath = suffix.split(os.sep) testPath = suffix.split(os.sep)
testRoot = tests testRoot = tests

View File

@ -42,7 +42,7 @@ def pytest_exception_interact(node, call, report):
try: try:
with open(os.path.join(vtest.path, 'manifest.yml'), 'r') as f: with open(os.path.join(vtest.path, 'manifest.yml'), 'r') as f:
settings = yaml.safe_load(f) settings = yaml.safe_load(f)
except FileNotFoundError: except IOError:
settings = {} settings = {}
settings['fail'] = True settings['fail'] = True
with open(os.path.join(vtest.path, 'manifest.yml'), 'w') as f: with open(os.path.join(vtest.path, 'manifest.yml'), 'w') as f:

View File

@ -40,7 +40,7 @@ def test_video(vtest, pytestconfig):
else: else:
try: try:
vtest.test() vtest.test()
except FileNotFoundError: except IOError:
raise raise
if pytestconfig.getoption('--mark-succeeding') and 'fail' in vtest.settings: if pytestconfig.getoption('--mark-succeeding') and 'fail' in vtest.settings:
# TODO: This can fail if an entire directory is marked as failing # TODO: This can fail if an entire directory is marked as failing
@ -48,7 +48,7 @@ def test_video(vtest, pytestconfig):
try: try:
with open(os.path.join(vtest.path, 'manifest.yml'), 'r') as f: with open(os.path.join(vtest.path, 'manifest.yml'), 'r') as f:
settings = yaml.safe_load(f) settings = yaml.safe_load(f)
except FileNotFoundError: except IOError:
pass pass
if 'fail' in settings: if 'fail' in settings:
del settings['fail'] del settings['fail']

View File

@ -41,7 +41,7 @@ def ingestDirectory(path, dest):
try: try:
with open(os.path.join(dest, root, fname, 'manifest.yml'), 'r') as f: with open(os.path.join(dest, root, fname, 'manifest.yml'), 'r') as f:
manifest = yaml.safe_load(f) or {} manifest = yaml.safe_load(f) or {}
except FileNotFoundError: except IOError:
pass pass
dictMerge(manifest, { dictMerge(manifest, {
'config': { 'config': {