aboutsummaryrefslogtreecommitdiffstats
path: root/build/platform/python/tests/testlib.py
blob: d12f2815d485d2391c54570a665a51269bfe822d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os
import subprocess

import yatest.common


def get_python_bin(ver):
    res_name = 'EXTERNAL_PYTHON{}_RESOURCE_GLOBAL'.format(ver.replace('.', ''))
    gr = yatest.common.global_resources()
    if res_name in gr:
        bindir = os.path.join(gr[res_name], 'python', 'bin')
        if ('python' + ver) in os.listdir(bindir):
            return os.path.join(bindir, 'python' + ver)
        return os.path.join(bindir, 'python')

    raise AssertionError("Resource '{}' is not available: {}".format(res_name, gr))


def check_python_version(version):
    ver = subprocess.check_output([get_python_bin(version), '-V'], stderr=subprocess.STDOUT).decode('utf-8')
    assert version in ver