Debian Codegraph @

tests/annotations.py

raw symbols SCIP
1 import os
2 import sys
3
4 import pytest
5 import pyglet
6
7
8 # Platform identifiers
9 class Platform:
10 """
11 Predefined lists of identifiers for platforms. For use with
12 :func:`.require_platform` and :func:`.skip_platform`. Combine platforms using +.
13 """
14 LINUX = ('linux-compat', 'linux2', 'linux')
15 """Linux platforms"""
16
17 WINDOWS = ('win32', 'cygwin')
18 """MS Windows platforms"""
19
20 OSX = ('darwin',)
21 """Mac OS X platforms"""
22
23
24 def require_platform(platform):
25 """
26 Only run the test on the given platform(s), skip on other platforms.
27
28 :param list(str) platform: A list of platform identifiers as returned by
29 :data:`pyglet.options`. See also :class:`tests.annotations.Platform`.
30 """
31 return pytest.mark.skipif(pyglet.compat_platform not in platform,
32 reason=f'requires platform: {platform!s}')
33
34
35 def skip_platform(platform):
36 """
37 Skip test on the given platform(s).
38
39 :param list(str) platform: A list of platform identifiers as returned by
40 :data:`pyglet.options`. See also :class:`tests.annotations.Platform`.
41 """
42 return pytest.mark.skipif(pyglet.compat_platform in platform,
43 reason=f'not supported for platform: {platform!s}')
44
45
46 def require_gl_extension(extension):
47 """
48 Skip the test if the given GL extension is not available.
49
50 :param str extension: Name of the extension required.
51 """
52
53 from pyglet.gl import gl_info
54 return pytest.mark.skipif(not gl_info.have_extension(extension),
55 reason=f'Tests requires GL extension {extension}')
56
57
58 def require_python_version(version):
59 """
60 Skip test on older Python versions.
61
62 :param tuple version: The major, minor Python version as a tuple.
63 """
64 return pytest.mark.skipif(sys.version_info < version,
65 reason=f"Test require at least Python version {version}")
66
67
68 def skip_if_continuous_integration():
69 """
70 Skip the test if being run under a Continuous Integration service.
71 """
72 return pytest.mark.skipif(any(key in os.environ for key in ['CI']),
73 reason="Test is unreliable, or unavailable under Continuous Integration ")