示例#1
0
def test_usage_with_missing_evaler_return_value(tmpdir):
    task = ProcessCodeTask()
    task.inputFile = os.path.join(os.path.dirname(__file__), 'resources',
                                  'aug_codes-01.json')
    task.outputFile = os.path.join(tmpdir, 'genCodes-py-ignore.json')
    task.verbose = True

    printHeader('test_usage_with_missing_evaler_return_value')
    task.execute(evalerWithoutReturn)
    printErrors(task)

    assert len(task.allErrors) == 1
    print(f'\nExpected {len(task.allErrors)} error(s)')
示例#2
0
def test_usage_with_production_evaler(tmpdir):
    task = ProcessCodeTask()
    task.inputFile = os.path.join(os.path.dirname(__file__), 'resources',
                                  'aug_codes-01.json')
    task.outputFile = os.path.join(tmpdir, 'genCodes-py-ignore.json')
    task.verbose = True

    printHeader('test_usage_with_production_evaler')
    task.execute(productionEvaler)
    printErrors(task)

    assert len(task.allErrors) == 2
    print(f'\nExpected {len(task.allErrors)} error(s)')
示例#3
0
def test_usage_producing_duplicate_ids(tmpdir):
    task = ProcessCodeTask()
    task.inputFile = os.path.join(os.path.dirname(__file__), 'resources',
                                  'aug_codes-01.json')
    task.outputFile = os.path.join(tmpdir, 'genCodes-py-ignore.json')
    task.verbose = True

    printHeader('test_usage_producing_duplicate_ids')
    task.execute(evalerProducingDuplicateIds)
    printErrors(task)

    assert len(task.allErrors) == 1
    print(f'\nExpected {len(task.allErrors)} error(s)')
示例#4
0
def test_basic_usage(tmpdir):
    task = ProcessCodeTask()
    task.inputFile = os.path.join(os.path.dirname(__file__), 'resources',
                                  'aug_codes-00.json')
    task.outputFile = os.path.join(tmpdir, 'actual_gen_codes.json')

    printHeader('test_basic_usage')
    task.execute(evaler)
    printErrors(task)

    assert not task.allErrors
    print('Output successfully written to {0}'.format(task.outputFile))
示例#5
0
def test_context_scope_method_access(tmpdir):
    task = ProcessCodeTask()
    task.inputFile = os.path.join(os.path.dirname(__file__), 'resources',
                                  'aug_codes-02.json')
    task.outputFile = os.path.join(tmpdir, 'genCodes-py-02.json')

    printHeader('test_context_scope_method_access')
    task.execute(contextScopeMethodAccessEvaler)
    printErrors(task)

    assert not task.allErrors

    with open(task.outputFile, encoding='utf8') as f:
        data = f.read()
    assert re.sub(r'\r\n|\n|\r', "\n", data) == '{}\n' + \
        '{"fileId":1,"generatedCodes":[' + \
        '{"id":1,"skipped":true},' + \
        '{"id":2,"skipped":true},' + \
        '{"id":3,"skipped":true}]}\n'
示例#6
0
from code_augmentor_support.tasks import ProcessCodeTask

import MyFunctions
import OtherFunctions

FUNCTION_NAME_REGEX = re.compile(
    r'^((MyFunctions|OtherFunctions)\.)[a-zA-Z]\w*$')


def callUserFunction(functionName, augCode, context):
    # validate name.
    if not FUNCTION_NAME_REGEX.search(functionName):
        raise Exception("Invalid/Unsupported function name: " + functionName)

    # name is valid. make function call "dynamically".
    result = eval(functionName + '(augCode, context)')
    return result


instance = ProcessCodeTask()
instance.inputFile = sys.argv[1]
instance.outputFile = sys.argv[2]
if len(sys.argv) > 3:
    instance.verbose = bool(sys.argv[3])
instance.execute(callUserFunction)
if instance.allErrors:
    print(str(len(instance.allErrors)) + " error(s) found.", file=sys.stderr)
    for errMsg in instance.allErrors:
        print(errMsg, file=sys.stderr)
    sys.exit(1)