示例#1
0
def compare_files(baseline_fname, output_fname, tolerance=0.0, baseline_begin='', baseline_end='', output_begin='', output_end=None, exact=True, using_yaml=True):
    INPUT=open_possibly_compressed_file(baseline_fname)
    baseline = extract_subtext(INPUT, begin_str=baseline_begin, end_str=baseline_end)
    INPUT.close()
    INPUT=open_possibly_compressed_file(output_fname)
    output = extract_subtext(INPUT, begin_str=output_begin, end_str=output_end)
    INPUT.close()
    compare_strings(baseline, output, tolerance=tolerance, exact=exact, using_yaml=using_yaml)
示例#2
0
def simple_yaml_parser(stream):
    if isinstance(stream, basestring):
        _stream = open_possibly_compressed_file(stream)
        repn = recursive_yaml_parser(_stream)[0]
        _stream.close()
        return repn
    return recursive_yaml_parser(stream)[0]
示例#3
0
def simple_yaml_parser(stream):
    if isinstance(stream, basestring):
        _stream = open_possibly_compressed_file(stream)
        repn = recursive_yaml_parser(_stream)[0]
        _stream.close()
        return repn
    return recursive_yaml_parser(stream)[0]
示例#4
0
def compare_files(baseline_fname,
                  output_fname,
                  tolerance=0.0,
                  baseline_begin='',
                  baseline_end='',
                  output_begin='',
                  output_end=None,
                  exact=True,
                  using_yaml=True):
    INPUT = open_possibly_compressed_file(baseline_fname)
    baseline = extract_subtext(INPUT,
                               begin_str=baseline_begin,
                               end_str=baseline_end)
    INPUT.close()
    INPUT = open_possibly_compressed_file(output_fname)
    output = extract_subtext(INPUT, begin_str=output_begin, end_str=output_end)
    INPUT.close()
    compare_strings(baseline,
                    output,
                    tolerance=tolerance,
                    exact=exact,
                    using_yaml=using_yaml)
示例#5
0
def extract_subtext(stream, begin_str='', end_str=None, comment='#'):
    if isinstance(stream,basestring):
        _stream = open_possibly_compressed_file(stream)
    else:
        _stream = stream
    if end_str is None:
        end_str == begin_str
    ans = []
    status = len(begin_str) == 0
    for line in _stream:
        tokens = re.split('[\t ]+',line.strip())
        if not status and line.startswith(begin_str):
            status = True
        elif not end_str is None and end_str != '' and line.startswith(end_str):
            break
        elif status:
            if tokens[0] != comment:
                ans.append(line)
    if isinstance(stream,basestring):
        _stream.close()
    return "".join(ans)
示例#6
0
def extract_subtext(stream, begin_str='', end_str=None, comment='#'):
    if isinstance(stream, basestring):
        _stream = open_possibly_compressed_file(stream)
    else:
        _stream = stream
    if end_str is None:
        end_str == begin_str
    ans = []
    status = len(begin_str) == 0
    for line in _stream:
        tokens = re.split('[\t ]+', line.strip())
        if not status and line.startswith(begin_str):
            status = True
        elif not end_str is None and end_str != '' and line.startswith(
                end_str):
            break
        elif status:
            if tokens[0] != comment:
                ans.append(line)
    if isinstance(stream, basestring):
        _stream.close()
    return "".join(ans)