src/platform/python/test_cinema.py (view raw)
1import pytest
2import cinema.test
3import mgba.log
4import os.path
5import yaml
6
7mgba.log.installDefault(mgba.log.NullLogger())
8
9def flatten(d):
10 l = []
11 for k, v in d.tests.items():
12 if v.tests:
13 l.extend(flatten(v))
14 else:
15 l.append(v)
16 l.sort()
17 return l
18
19def pytest_generate_tests(metafunc):
20 if 'vtest' in metafunc.fixturenames:
21 tests = cinema.test.gatherTests(os.path.join(os.path.dirname(__file__), 'tests/cinema'))
22 testList = flatten(tests)
23 params = []
24 for test in testList:
25 marks = []
26 xfail = test.settings.get('fail')
27 if xfail:
28 marks = pytest.mark.xfail(reason=xfail if isinstance(xfail, str) else None)
29 params.append(pytest.param(test, id=test.name, marks=marks))
30 metafunc.parametrize('vtest', params, indirect=True)
31
32@pytest.fixture
33def vtest(request):
34 return request.param
35
36def test_video(vtest, pytestconfig):
37 vtest.setUp()
38 if pytestconfig.getoption('--rebaseline'):
39 vtest.generateBaseline()
40 else:
41 try:
42 vtest.test()
43 except FileNotFoundError:
44 raise
45 if pytestconfig.getoption('--mark-succeeding') and 'fail' in vtest.settings:
46 # TODO: This can fail if an entire directory is marked as failing
47 settings = {}
48 try:
49 with open(os.path.join(vtest.path, 'manifest.yml'), 'r') as f:
50 settings = yaml.safe_load(f)
51 except FileNotFoundError:
52 pass
53 if 'fail' in settings:
54 del settings['fail']
55 else:
56 settings['fail'] = False
57 if settings:
58 with open(os.path.join(vtest.path, 'manifest.yml'), 'w') as f:
59 yaml.dump(settings, f, default_flow_style=False)
60 else:
61 os.remove(os.path.join(vtest.path, 'manifest.yml'))