Passed
Push — master ( 60cda1...c2cb96 )
by Marcus
43s
created

construct_command()   A

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
"""
3
import os
4
import sys
5
import argparse
6
import subprocess
7
8
import pytest
9
from mayatest import mayaloc
10
11
12
def args_parser(args):
13
    parser = argparse.ArgumentParser(
14
        description='Runs unit tests for a Maya module')
15
    parser.add_argument(
16
        '-m', '--maya', help='Maya version', type=int, default=2016)
17
    parser.add_argument(
18
        '-py', '--pytest', help='pytest extra args', type=str)
19
    return parser.parse_args(args)
20
21
22
def construct_command(pargs):
23
    mayapy = mayaloc.mayapy(pargs.maya)
24
    if not os.path.isfile(mayapy):
25
        raise RuntimeError(
26
            'Maya {0} is not installed on the system'.format(pargs.maya))
27
28
    cmd = [mayapy, os.path.normpath(os.path.realpath(pytest.__file__))]
29
    if pargs.pytest:
30
        cmd.append(pargs.pytest)
31
    return cmd
32
33
34
def main():
35
    pargs = args_parser(sys.argv[1:])
36
    with mayaloc.clean_maya_environment():
37
        try:
38
            subprocess.check_call(construct_command(pargs))
39
        except subprocess.CalledProcessError:
40
            pass
41
42
43
if __name__ == '__main__':
44
    main()
45