summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-12-02 00:13:46 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-12-02 00:13:46 (GMT)
commitd6958ac6c0fec90524bf9c4999c8bc75fff0c71b (patch)
tree93f5e47349d8b51b9cec9f2c1710b8dc1e13c98b /Lib
parentedfe8869c8e888e676091c87330b3bf0f3d9814b (diff)
downloadcpython-d6958ac6c0fec90524bf9c4999c8bc75fff0c71b.zip
cpython-d6958ac6c0fec90524bf9c4999c8bc75fff0c71b.tar.gz
cpython-d6958ac6c0fec90524bf9c4999c8bc75fff0c71b.tar.bz2
Add sys.getandroidapilevel()
Issue #28740: Add sys.getandroidapilevel(): return the build time API version of Android as an integer. Function only available on Android.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/support/__init__.py9
-rw-r--r--Lib/test/test_sys.py7
2 files changed, 14 insertions, 2 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 52c908e..eb5a89a 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -766,8 +766,13 @@ requires_lzma = unittest.skipUnless(lzma, 'requires lzma')
is_jython = sys.platform.startswith('java')
-_ANDROID_API_LEVEL = sysconfig.get_config_var('ANDROID_API_LEVEL')
-is_android = (_ANDROID_API_LEVEL is not None and _ANDROID_API_LEVEL > 0)
+try:
+ # constant used by requires_android_level()
+ _ANDROID_API_LEVEL = sys.getandroidapilevel()
+ is_android = True
+except AttributeError:
+ # sys.getandroidapilevel() is only available on Android
+ is_android = False
if sys.platform != 'win32':
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index df9ebd4..828421c 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -826,6 +826,13 @@ class SysModuleTest(unittest.TestCase):
rc, stdout, stderr = assert_python_ok('-c', code)
self.assertEqual(stdout.rstrip(), b'True')
+ @unittest.skipUnless(hasattr(sys, 'getandroidapilevel'),
+ 'need sys.getandroidapilevel()')
+ def test_getandroidapilevel(self):
+ level = sys.getandroidapilevel()
+ self.assertIsInstance(level, int)
+ self.assertGreater(level, 0)
+
@test.support.cpython_only
class SizeofTest(unittest.TestCase):