Пример #1
0
def list(env):
    # nose has --collect-only which identifies the tests, but does not run them.
    # We run nose with the same set of parameters as if we were running the
    # test, but we add --collect-only.  The result is a pandokia log file
    # that contains abbreviated test reports.  We read that log file to
    # find the test names.  (Everything except the name is an uninteresting
    # side-effect.)
    #
    # Note that the PDK_TESTPREFIX is applied by the nose plugin, not us.

    # If this function is called, it is only once per process.
    import pandokia.helpers.process as process
    import pandokia.helpers.filecomp as filecomp

    tmpfile = 'pdk.runner.tmp'
    # Do our best to make sure the file is not there already.
    try:
        os.unlink(tmpfile)
    except OSError:
        pass

    # run the command to collect the names
    # pandokia log goes to tmpfile - it is ok to used a fixed name because we
    # know that only one process can be running tests in a single directory.
    s = 'pdknose --pdk --with-doctest --doctest-tests --collect-only %(PDK_FILE)s' % env

    env = env.copy()
    env['PDK_LOG'] = tmpfile
    process.run_process(s.split(), env, output_file='pdknose.tmp')

    # gather the names from pdk.log
    l = []
    f = open(tmpfile, "r")
    for line in f:
        line = line.strip().split('=')
        if line[0] == 'test_name':
            l.append(line[1])

    f.close()

    # clean up
    filecomp.safe_rm('pdknose.tmp')
    filecomp.safe_rm(tmpfile)

    # return list
    return l
Пример #2
0
def lst(env):
    # nose has --collect-only which identifies the tests, but does not run them.
    # We run nose with the same set of parameters as if we were running the
    # test, but we add --collect-only.  The result is a pandokia log file
    # that contains abbreviated test reports.  We read that log file to
    # find the test names.  (Everything except the name is an uninteresting
    # side-effect.)
    #
    # Note that the PDK_TESTPREFIX is applied by the nose plugin, not us.

    # If this function is called, it is only once per process.
    import pandokia.helpers.process as process
    import pandokia.helpers.filecomp as filecomp

    tmpfile = 'pdk.runner.tmp'
    # Do our best to make sure the file is not there already.
    try:
        os.unlink(tmpfile)
    except OSError:
        pass

    # run the command to collect the names
    # pandokia log goes to tmpfile - it is ok to used a fixed name because we
    # know that only one process can be running tests in a single directory.
    s = 'pdknose --pdk --with-doctest --doctest-tests --collect-only %(PDK_FILE)s' % env

    env = env.copy()
    env['PDK_LOG'] = tmpfile
    process.run_process(s.split(), env, output_file='pdknose.tmp')

    # gather the names from pdk.log
    l = []
    f = open(tmpfile, "r")
    for line in f:
        line = line.strip().split('=')
        if line[0] == 'test_name':
            l.append(line[1])

    f.close()

    # clean up
    filecomp.safe_rm('pdknose.tmp')
    filecomp.safe_rm(tmpfile)

    # return list
    return l
Пример #3
0
def cmp_example(
        the_file,
        reference_file,
        msg=None,
        quiet=False,
        attr_prefix=None,
        tda=None,
        tra=None,
        **kwargs):
    '''
    This is an example of how to write your own file comparison function.
    See also the source code.

        the_file is the input file that we are testing.

        reference_file is the reference file that we already know to be correct.

        quiet is true to suppress all output.  Not all comparison functions
        are capable of this, because some of them use external packages
        (e.g. fitsdiff) that are too chatty.

        kwargs is a place for optional args that may influence how the
        comparison takes place.  For example, you might use this to specify
        to ignore case, to compare numbers with a certain tolerance, or to
        ignore certain fields in the file.

    This function returns True if the files are the same (according to the
    comparison parameters given).  Return False otherwise.  Raise an exception
    if some exceptional condition prevents you performing the comparison.

    Define a function like this, then add it to the dictionary with a commmand
    like:
        pandokia.helpers.filecomp.file_comparators['example'] = cmp_example

    You can then use it by calling file_compare()

    '''
    if (not quiet) and (header_message is not None):
        sys.stdout.write(header_message)

    safe_rm('filecomp.tmp')

    # cmp command - only works on unix-like systems
    r = process.run_process(
        ["cmp", the_file, reference_file], output_file="filecomp.tmp")

    process.cat('filecomp.tmp')
    safe_rm('filecomp.tmp')

    if r == 1:
        if not quiet:
            sys.stdout.write("file match error: %s\n" % the_file)
        return False
    elif r != 0:
        raise OSError("cmp command returned error status %d" % r)
    return True
Пример #4
0
def cmp_fits(
        the_file,
        reference_file,
        msg=None,
        quiet=False,
        attr_prefix=None,
        tda=None,
        tra=None,
        maxdiff=None,
        ignorekeys=None,
        ignorecomm=None):
    '''
    cmp_fits - compare fits files.  kwargs are passed through to fitsdiff
    '''

    if quiet:
        sys.stdout.write("(sorry - fitsdiff does not know how to be quiet)\n")

    safe_rm('filecomp.tmp')

    # fitsdiff does not know how to distinctively report that a reference
    # file was missing (it gives the same status as for a failed match)
    if not os.path.exists(reference_file):
        e = IOError('No reference file: %s' % reference_file)
        print(e)
        raise e

    # run fitsdiff externally - if you call it directly, it does
    # weird things to the tests. (This will change with Erik's new
    # fitsdiff API, but it isn't here yet.)

    arglist = ['fitsdiff']
    if maxdiff is not None:
        arglist = arglist + ['-r', str(maxdiff)]
    if ignorekeys is not None:
        arglist = arglist + ['-k', ','.join(ignorekeys)]
    if ignorecomm is not None:
        arglist = arglist + ['-c', ','.join(ignorecomm)]
    arglist = arglist + [the_file, reference_file]

    print(arglist)
    status = process.run_process(arglist, output_file="filecomp.tmp")

    process.cat('filecomp.tmp')
    safe_rm('filecomp.tmp')

    if status == 0:
        return True
    elif status == 1:
        return False
    else:
        raise Exception("fitsdiff error - exited %d" % status)
Пример #5
0
import pandokia.helpers.process as process
import filecmp
import os

testFiles = [
    'anonymousTypes.h', 'basicFunctions.h', 'basicTypedef.h', 'enums.h',
    'macros.h', 'structures.h', 'test3.h'
]

for file in testFiles:
    # run the program, capturing output into a file
    status = process.run_process(['./dumpSparrow.out', 'tests/' + file],
                                 output_file='testFile.tmp')
    fileName = file.rsplit(".", 1)[0]
    result = filecmp.cmp('testFile.tmp', 'tests/results/' + fileName + '.spr')

    if result == False:
        print "FAIL --> " + file
    else:
        print "PASS --> " + file

    # read the file and print it to the stdout being used by the test
    # process.cat(["testFile.tmp" ])

os.remove("testFile.tmp")