mirror of
https://github.com/kristoferssolo/solorice.git
synced 2026-03-18 08:09:40 +00:00
Minor changes
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
import random
|
||||
import tempfile
|
||||
import json
|
||||
import time
|
||||
|
||||
|
||||
def parse_params(param_string):
|
||||
test_marker = 'test '
|
||||
assert param_string.startswith(test_marker)
|
||||
param_string = param_string[len(test_marker):]
|
||||
result = dict()
|
||||
kv_pairs = param_string.split(',')
|
||||
for p in kv_pairs:
|
||||
if p.find(':') == -1:
|
||||
continue
|
||||
key, value = p.split(':')
|
||||
result[key] = value
|
||||
return result
|
||||
|
||||
|
||||
class MockException(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
param_string = sys.argv[1]
|
||||
params = parse_params(param_string)
|
||||
output = ' '.join(sys.argv)
|
||||
tmp_dir = tempfile.gettempdir()
|
||||
tmp_file = os.path.join(tmp_dir, 'rnd_mock.{}.txt'.format(random.randint(0, 1000 * 1000 * 1000)))
|
||||
with open(tmp_file, 'w') as f:
|
||||
for i in range(10):
|
||||
f.write(param_string + '\n')
|
||||
report = {'result_path': tmp_file}
|
||||
|
||||
|
||||
if 'sleep' in params:
|
||||
sleep_time = float(params['sleep'])
|
||||
time.sleep(sleep_time)
|
||||
|
||||
if 'error' in params:
|
||||
report['error_type'] = 'Mock Error'
|
||||
report['error_details'] = params['error']
|
||||
|
||||
if 'warning' in params:
|
||||
report['warnings'] = params['warning'].split(';')
|
||||
|
||||
if 'unhandled_exception' in params:
|
||||
raise MockException('Unhandled Mock Exception')
|
||||
|
||||
if 'handled_exception' in params:
|
||||
try:
|
||||
raise MockException('Handled Mock Exception')
|
||||
except Exception as e:
|
||||
report['error_type'] = 'Exception'
|
||||
report['error_details'] = str(e)
|
||||
|
||||
if 'stderr' in params:
|
||||
sys.stderr.write(params['stderr'])
|
||||
|
||||
if 'stdout' in params:
|
||||
sys.stdout.write(params['stdout'])
|
||||
else:
|
||||
sys.stdout.write(json.dumps(report))
|
||||
|
||||
if 'return_code' in params:
|
||||
return_code = int(params['return_code'])
|
||||
sys.exit(return_code)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user