construct_command()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
1
"""
2
cli takes the given arguments and create a test call performed by the
3
given mayapy version.
4
"""
5
import os
6
import sys
7
import argparse
8
import subprocess
9
10
try:
11
    import pytest
12
except ImportError:
13
    pytest = None
14
15
from mayatest import mayaloc, runner
16
17
18
def args_parser(args):
19
    parser = argparse.ArgumentParser(
20
        description='Runs unit tests for a Maya module')
21
    parser.add_argument(
22
        '-m', '--maya', help='Maya version', type=int, default=2016)
23
    parser.add_argument(
24
        '-py', '--pytest', help='pytest extra args', type=str, default='')
25
    return parser.parse_args(args)
26
27
28
def construct_command(pargs):
29
    mayapy = mayaloc.mayapy(pargs.maya)
30
    if not os.path.isfile(mayapy):
31
        raise RuntimeError(
32
            'Maya {0} is not installed on the system'.format(pargs.maya))
33
34
    cmd = [mayapy, runner.__file__]
35
    cmd.append(None if pytest is None else pytest.__file__)
36
    cmd.append(pargs.pytest)
37
    return cmd
38
39
40
def main():
41
    pargs = args_parser(sys.argv[1:])
42
    with mayaloc.clean_maya_environment():
43
        try:
44
            subprocess.check_call(construct_command(pargs))
45
        except subprocess.CalledProcessError:
46
            pass
47
48
49
if __name__ == '__main__':
50
    main()
51