Beispiel #1
0
def t13(w):
    pretty = '%s t13' % __file__
    print(pretty)

    # cook a job, preserving sys.path for UNIT/ACCEPTANCE differences
    job = {
        'path':
        'job',
        'tags': ['TAG'],
        'profiles': [[{
            'type': 'handset'
        }], [{
            'type': 'hanset'
        }, {
            'type': 'workspace'
        }]]
    }
    exe = '#! /usr/bin/python2\n' \
        + 'import sys\n' \
        + 'sys.path = %s\n' % repr(sys.path) \
        + 'import json\n' \
        + 'import vcsjob\n' \
        + 'print(json.dumps(vcsjob.get_profiles()))'
    # look for the output from the last line in the test
    make_job(w, [job], exe)

    # store output from the job somewhere
    log_path = w.make_tempfile()

    try:
        vcsjob.execute_tags(w.path, ['TAG'], log_path=log_path)
    except Exception, e:
        print('FAIL %s: execute failed: %s' % (pretty, e))
        return False
Beispiel #2
0
def t7():
    pretty = '%s t7' % __file__
    print(pretty)

    w = Workspace(uid='vcsjob-execute-t7')

    # create the jobs tree
    def make_vcsjob_tree():
        path = w.make_tempdir()
        f = open(os.path.join(path, '.vcsjob'), 'w')
        # broken JSON file:
        f.write('{ "executables": [ { "path": "printenv.sh"')
        f.close()
        f = open(os.path.join(path, 'printenv.sh'), 'w')
        f.write('#! /bin/bash\nprintenv\n')
        f.close()
        os.chmod(os.path.join(path, 'printenv.sh'), 0755)
        return path

    jobs = make_vcsjob_tree()

    exc = None
    try:
        vcsjob.execute_tags(jobs_dir=jobs)
    except Exception, e:
        exc = e
Beispiel #3
0
def t5():
    pretty = '%s t5' % __file__
    print(pretty)

    exc = None
    try:
        vcsjob.execute_tags(None, None, None)
    except Exception, e:
        exc = e
Beispiel #4
0
def t21():
    pretty = '%s t21' % __file__
    print(pretty)

    w = Workspace()
    jobs = make_vcsjob_tree(w, coverage=['list', 'of', 'ints', 1, 2, 3])
    try:
        vcsjob.execute_tags(jobs_dir=jobs)
        print('FAIL %s: expected exception (invalid coverage)' % (pretty))
    except Exception, e:
        if '"coverage" attribute is not a list of strings' not in str(e):
            print('FAIL %s: wrong error: %s' % (pretty, str(e)))
Beispiel #5
0
def t17():
    pretty = '%s t17' % __file__
    print(pretty)

    w = Workspace(uid='vcsjob-execute-t17')
    jobs = make_vcsjob_tree(w, banner=13)
    try:
        vcsjob.execute_tags(jobs_dir=jobs)
        print('FAIL %s: expected exception (invalid banner - int)' % (pretty))
    except Exception, e:
        if not str(e).startswith(
                'job\'s "banner" attribute must be a string:'):
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
Beispiel #6
0
def t12():
    pretty = '%s t12' % __file__
    print(pretty)

    w = Workspace(uid='vcsjob-execute-t12')
    jobs = make_vcsjob_tree(w)
    os.unsetenv('PATH')

    exc = None
    try:
        vcsjob.execute_tags(jobs, None, ['PATH'])
    except Exception, e:
        exc = e
Beispiel #7
0
def t22():
    pretty = '%s t22' % __file__
    print(pretty)

    w = Workspace()
    jobs = make_vcsjob_tree(w, coverage=['Angry! €¤!^', '~ü#¤/=!¤$£.åäöÅÄÖ"'])
    backup = None
    try:
        (strio, backup) = redirect()
        vcsjob.execute_tags(jobs_dir=jobs)
        undirect(backup)
    except Exception, e:
        undirect(backup)
        print('FAIL %s: unexpected exception: %s' % (pretty, str(e)))
Beispiel #8
0
def t19():
    pretty = '%s t19' % __file__
    print(pretty)

    w = Workspace(uid='vcsjob-execute-t18')
    jobs = make_vcsjob_tree(w, banner='"Angry jobs! €¤!^~ü#¤/=!¤$£.åäöÅÄÖ"')
    backup = None
    try:
        (strio, backup) = redirect()
        vcsjob.execute_tags(jobs_dir=jobs)
        undirect(backup)
    except Exception, e:
        undirect(backup)
        print('FAIL %s: unexpected exception: %s' % (pretty, str(e)))
Beispiel #9
0
def t2(w):
    pretty = '%s t2' % __file__
    print(pretty)

    root = find_vcsjob_dir(__file__)
    log  = os.path.join(w.path, 'log.txt')

    # produce reference output
    strio, backup = redirect()
    try:
        vcsjob.execute_tags(root, ['DEMO'], [], None)
    except Exception, e:
        undirect(backup)
        print('FAIL %s: could not produce reference: %s' % (pretty, e))
        return False
Beispiel #10
0
def t6(w):
    pretty = '%s t6' % __file__
    print(pretty)

    root = find_vcsjob_dir(__file__)
    log  = os.path.join(w.path, 'log.txt')

    try:
        status = vcsjob.execute_tags(root, ['NO_SUCH_TAG'], [], log)
    except Exception, e:
        print('FAIL %s: could not log to file: %s' % (pretty, e))
        return False
Beispiel #11
0
def t9():
    pretty = '%s t9' % __file__
    print(pretty)

    w = Workspace(uid='vcsjob-execute-t9')

    # create the jobs tree
    def make_vcsjob_tree():
        path = w.make_tempdir()
        f = open(os.path.join(path, '.vcsjob'), 'w')
        f.write('{ "executables": [ { "path": "no_such_file" } ] }')
        f.close()
        return path

    jobs = make_vcsjob_tree()

    exc = None
    try:
        vcsjob.execute_tags(jobs_dir=jobs)
    except Exception, e:
        exc = e
Beispiel #12
0
def t8():
    pretty = '%s t8' % __file__
    print(pretty)

    w = Workspace(uid='vcsjob-execute-t8')

    # create the jobs tree
    def make_vcsjob_tree():
        path = w.make_tempdir()
        f = open(os.path.join(path, '.vcsjob'), 'w')
        # no "path" attr:
        f.write('{ "executables": [ { "PATH": "printenv.sh" } ] }')
        f.close()
        return path

    jobs = make_vcsjob_tree()

    exc = None
    try:
        result = vcsjob.execute_tags(jobs_dir=jobs)
    except Exception, e:
        exc = e
Beispiel #13
0
def t11():
    pretty = '%s t11' % __file__
    print(pretty)

    w = Workspace(uid='vcsjob-execute-t11')
    jobs = make_vcsjob_tree(w)

    cwd_bak = os.getcwd()
    (strio, backup) = redirect()
    result = vcsjob.execute_tags(jobs_dir=jobs, job_tags=['THAT'])
    undirect(backup)
    os.chdir(cwd_bak)

    if result == vcsjob.OK:
        print(
            'FAIL %s: vcsjob.execute_tags() returned OK even though there were '
            'no jobs to run' % pretty)
        return
    result = strio.getvalue().split('\n')[0]
    if result != 'WARNING: no jobs were executed':
        print('FAIL %s: error not shown:\n%s' % (pretty, strio.getvalue()))
        return

    w.delete()
Beispiel #14
0
    # produce reference output
    strio, backup = redirect()
    try:
        vcsjob.execute_tags(root, ['DEMO'], [], None)
    except Exception, e:
        undirect(backup)
        print('FAIL %s: could not produce reference: %s' % (pretty, e))
        return False
    undirect(backup)

    expected = strio.getvalue().splitlines()
    expected = '\n'.join(e for e in expected if not e.startswith('vcsjob: {'))

    # produce tested output
    try:
        vcsjob.execute_tags(root, ['DEMO'], [], log)
    except Exception, e:
        print('FAIL %s: could not log to file: %s' % (pretty, e))
        return False

    with open(log) as f:
        actual = f.read().splitlines()
        actual = [a for a in actual if not a.startswith('vcsjob: {')]
    actual = [a for a in actual if not a.startswith('VCSJOB_LOG_PATH=')]
    actual = '\n'.join(actual)

    if actual != expected:
        print('FAIL %s: wrong logs: %s != %s' % (pretty, actual, expected))
        return False

    return True