예제 #1
0
def test_with_success():
  file_name = "testfile"
  file_data = "testoutput"
  ensure_file_absent(file_name)
  with safeoutput.open(file_name) as f:
    f.write(file_data)
  assert expected_file(file_name, file_data)
예제 #2
0
def test_close_success():
  file_name = "testfile"
  file_data = "testoutput"
  ensure_file_absent(file_name)
  f = safeoutput.open(file_name)
  f.write(file_data)
  f.close()
  assert expected_file(file_name, file_data)
예제 #3
0
def test_stdout_with_success_str(capsys):
    file_data = u"testoutput"
    mode = "w"
    with safeoutput.open(None, mode) as f:
        f.write(file_data)
    out, err = capsys.readouterr()
    assert out == file_data
    assert err == ""
예제 #4
0
def test_write_stdout_after_close(capsys):
    file_data = u"testoutput"
    f = safeoutput.open(None)
    f.write(file_data)
    f.close()
    f.write(file_data)
    out, err = capsys.readouterr()
    assert out == file_data + file_data
    assert err == ""
예제 #5
0
def main():
    args = docopt(usage)
    bl = open(args['<bindlite>'], 'r')
    sorted_records = bindlite2route53(bl, args['--zone'], args['--default-ttl'])

    with safeoutput.open(args['--output']) as output:
        for record in sorted_records:
            output.write(json.dumps(record, sort_keys=True) + "\n")

    return 0
예제 #6
0
def test_write_after_close():
  file_name = "testfile"
  file_data = "testoutput"
  ensure_file_absent(file_name)
  f = safeoutput.open(file_name)
  f.write(file_data)
  f.close()
  assert expected_file(file_name, file_data)
  with pytest.raises(ValueError):
    f.write(file_data)
  assert expected_file(file_name, file_data)
예제 #7
0
def test_with_exception():
  file_name = "testfile"
  file_data = "testoutput"
  ensure_file_absent(file_name)
  try:
    with safeoutput.open(file_name) as f:
      f.write(file_data)
      raise ValueError("We eff'ed up")
  except ValueError:
    pass
  assert expected_file(file_name, None)
예제 #8
0
def main():
    args = docopt(usage)
    records = []
    with open(args['<bl>']) as bl:
        for line in bl.readlines():
            record = parse_record(line)
            if record[1] in ('CNAME', 'A'):
                records.append(record)

    workers = int(args['--workers'])

    with safeoutput.open(args['--output']) as output:
        for record, ret_code in run(workers, records):
            sys.stderr.write("%s,\t\t%d\n" % (" ".join(record), ret_code))
            if ret_code != 0:
                output.write("%s\n" % " ".join(record))
예제 #9
0
def main():
    args = docopt(usage)
    yaml = args['--yaml']
    if args['--spec']:
        config = get_config(yaml,args['--spec'])
    else:
        config = get_config(yaml)

    r53 = R53(config)
    zone = r53.conn.get_zone(args['<zone>'])
    records = get_r53_records(zone)

    with safeoutput.open(args['--output']) as output:
        for record in records:
            output.write(json.dumps(record, sort_keys=True) + "\n")

    return 0
예제 #10
0
def main():
    args = docopt(usage)
    current_file = open(args['<current>'], 'r')
    desired_file = open(args['<desired>'], 'r')


    # assumes input files are ordered
    delta = difflib.ndiff(sort_resource_records(current_file),
                sort_resource_records(desired_file))

    delta = list(delta)
    to_delete = [line.replace('- ','') for line in delta if line.startswith('-')]
    to_create = [line.replace('+ ','') for line in delta if line.startswith('+')]

    to_delete = stamp_change(to_delete, 'DELETE')
    to_create = stamp_change(to_create, 'CREATE')

    changes = list(to_delete) + list(to_create)

    with safeoutput.open(args['--output']) as output:
        output.writelines(changes)

    return 0
예제 #11
0
 def write():
   f = safeoutput.open(file_name)
   f.write(file_data)
   raise ValueError("We eff'ed up")
예제 #12
0
def expect_success(file_data, mode):
    file_name = _filename()
    ensure_file_absent(file_name)
    with safeoutput.open(file_name, mode) as f:
        f.write(file_data)
    assert expected_file(file_name, file_data)