-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathcheck_utils.py
71 lines (53 loc) · 2.01 KB
/
check_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-or-later
import unittest
def sliceCommandLineArguments():
"""
Slice command line arguments by -- argument.
"""
import sys
try:
double_shasl_index = sys.argv.index("--")
except ValueError:
unittest_args = sys.argv[:]
parser_args = []
else:
unittest_args = sys.argv[:double_shasl_index]
parser_args = sys.argv[double_shasl_index + 1:]
return unittest_args, parser_args
def parseArguments():
import argparse
# Construct argument parser.
parser = argparse.ArgumentParser(description="Static binary checker")
parser.add_argument('directory', help='Directories to check')
# Parse arguments which are not handled by unit testing framework.
unittest_args, parser_args = sliceCommandLineArguments()
args = parser.parse_args(args=parser_args)
# TODO(sergey): Run some checks here?
return args
def runScriptInBlender(blender_directory, script):
"""
Run given script inside Blender and check non-zero exit code
"""
import os
import subprocess
blender = os.path.join(blender_directory, "blender")
python = os.path.join(os.path.dirname(__file__), "scripts", script) + ".py"
command = (blender,
"-b",
"--factory-startup",
"--python-exit-code", "1",
"--python", python)
process = subprocess.Popen(command,
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output, error = process.communicate()
return process.returncode == 0
class SceiptUnitTesting(unittest.TestCase):
def checkScript(self, script):
# Parse arguments which are not handled by unit testing framework.
args = parseArguments()
# Perform actual test,
self.assertTrue(runScriptInBlender(args.directory, script),
"Failed to run script {}" . format(script))