Ejemplo n.º 1
0
def test_write_BR():
    binary_file = _BinaryReader('test.file', 'wb')
    if not binary_file.f:
        raise ValueError("Failed to open new file for writing.")

    set_int = 8
    set_float = 3.14
    set_double_list = [1.6e-19, 6.02e23]
    set_string = "Hello World!"

    test_record = _FortranRecord('', 0)
    test_record.put_int([set_int])
    test_record.put_string([set_string], len(set_string))
    test_record.put_double(set_double_list)
    test_record.put_float([set_float])

    test_record.reset()

    binary_file.put_fortran_record(test_record)

    binary_file.close()

    if not filecmp.cmp('test.file', 'test_readBR.ref'):
        raise ValueError('Created file does not match reference.')

    return 1
Ejemplo n.º 2
0
def test_write_BR():

    binaryFile = _BinaryReader('test.file', 'wb')
    if not binaryFile.f:
        raise BinaryReaderError("Failed to open new file for writing.")

    setInt = 8
    setFloat = 3.14
    setDoubleList = [1.6e-19, 6.02e23]
    setString = "Hello World!"

    testRecord = _FortranRecord('', 0)
    testRecord.put_int([setInt])
    testRecord.put_string([setString], len(setString))
    testRecord.put_double(setDoubleList)
    testRecord.put_float([setFloat])

    testRecord.reset()

    binaryFile.put_fortran_record(testRecord)

    binaryFile.close()

    if not filecmp.cmp('test.file', 'test_readBR.ref'):
        raise BinaryReaderError('Created file does not match reference.')

    return 1
Ejemplo n.º 3
0
def test_write_BR():
    binary_file = _BinaryReader("test.file", "wb")
    if not binary_file.f:
        raise ValueError("Failed to open new file for writing.")

    set_int = 8
    set_float = 3.14
    set_double_list = [1.6e-19, 6.02e23]
    set_string = "Hello World!"

    test_record = _FortranRecord("", 0)
    test_record.put_int([set_int])
    test_record.put_string([set_string], len(set_string))
    test_record.put_double(set_double_list)
    test_record.put_float([set_float])

    test_record.reset()

    binary_file.put_fortran_record(test_record)

    binary_file.close()

    if not filecmp.cmp("test.file", "test_readBR.ref"):
        raise ValueError("Created file does not match reference.")

    return 1
Ejemplo n.º 4
0
def test_write_FR_double_list():
    set_double_list = [3.14, 0.3333]
    set_num_bytes = 16
    set_data = b'\x1f\x85\xebQ\xb8\x1e\t@io\xf0\x85\xc9T\xd5?'

    test_record = _FortranRecord('', 0)
    test_record.put_double(set_double_list)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "list of doubles")
Ejemplo n.º 5
0
def test_write_FR_float_list():
    set_floatList = [3.14, 0.3333]
    set_num_bytes = 8
    set_data = b'\xc3\xf5H@L\xa6\xaa>'

    test_record = _FortranRecord('', 0)
    test_record.put_float(set_floatList)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "list of floats")
Ejemplo n.º 6
0
def test_write_FR_float_list():
    set_floatList = [3.14, 0.3333]
    set_num_bytes = 8
    set_data = b'\xc3\xf5H@L\xa6\xaa>'

    test_record = _FortranRecord('', 0)
    test_record.put_float(set_floatList)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "list of floats")
Ejemplo n.º 7
0
def test_write_FR_double_list():
    set_double_list = [3.14, 0.3333]
    set_num_bytes = 16
    set_data = b'\x1f\x85\xebQ\xb8\x1e\t@io\xf0\x85\xc9T\xd5?'

    test_record = _FortranRecord('', 0)
    test_record.put_double(set_double_list)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "list of doubles")
Ejemplo n.º 8
0
def test_write_FR_long_list():
    set_long_list = [8, 16]
    set_num_bytes = 16
    set_data = \
        b'\x08\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00'

    test_record = _FortranRecord('', 0)
    test_record.put_long(set_long_list)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "list of 8-byte integers")
Ejemplo n.º 9
0
def test_write_FR_long_list():

    setLongList = [8, 16]
    setNumBytes = 16
    setData = '\x08\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00'

    testRecord = _FortranRecord('', 0)
    testRecord.put_long(setLongList)

    return check_write_record_data(testRecord, setNumBytes, setNumBytes,
                                   setData, "list of 8-byte integers")
Ejemplo n.º 10
0
def test_write_FR_string_list():
    set_string_list = ["Hello ", "World!"]
    set_length = len(set_string_list[0])
    set_num_bytes = 12
    set_data = b'Hello World!'

    test_record = _FortranRecord('', 0)
    test_record.put_string(set_string_list, set_length)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "list of strings")
Ejemplo n.º 11
0
def test_write_FR_string_list():
    set_string_list = ["Hello ", "World!"]
    set_length = len(set_string_list[0])
    set_num_bytes = 12
    set_data = b'Hello World!'

    test_record = _FortranRecord('', 0)
    test_record.put_string(set_string_list, set_length)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "list of strings")
Ejemplo n.º 12
0
def test_write_FR_long_list():
    set_long_list = [8, 16]
    set_num_bytes = 16
    set_data = b"\x08\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00"

    test_record = _FortranRecord("", 0)
    test_record.put_long(set_long_list)

    return check_write_record_data(
        test_record, set_num_bytes, set_num_bytes, set_data, "list of 8-byte integers"
    )
Ejemplo n.º 13
0
def test_write_FR_int_list():
    set_intList = [8, 16]
    set_num_bytes = 8
    set_data = b'\x08\x00\x00\x00\x10\x00\x00\x00'

    test_record = _FortranRecord('', 0)

    # write integer list
    test_record.put_int(set_intList)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "list of 4-byte integers")
Ejemplo n.º 14
0
def test_write_FR_int_list():
    set_intList = [8, 16]
    set_num_bytes = 8
    set_data = b'\x08\x00\x00\x00\x10\x00\x00\x00'

    test_record = _FortranRecord('', 0)

    # write integer list
    test_record.put_int(set_intList)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "list of 4-byte integers")
Ejemplo n.º 15
0
def test_write_FR_single_double():
    set_double = 3.14
    set_num_bytes = 8
    set_data = b'\x1f\x85\xebQ\xb8\x1e\t@'

    # create new record
    test_record = _FortranRecord('', 0)  # already tested

    # write double
    test_record.put_double(set_double)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "double")
Ejemplo n.º 16
0
def test_write_FR_single_float():
    set_float = 3.14
    set_num_bytes = 4
    set_data = b'\xc3\xf5H@'

    # create new record
    test_record = _FortranRecord('', 0)  # already tested

    # write float
    test_record.put_float(set_float)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "float")
Ejemplo n.º 17
0
def test_write_FR_single_double():
    set_double = 3.14
    set_num_bytes = 8
    set_data = b'\x1f\x85\xebQ\xb8\x1e\t@'

    # create new record
    test_record = _FortranRecord('', 0)  # already tested

    # write double
    test_record.put_double(set_double)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "double")
Ejemplo n.º 18
0
def test_write_FR_single_int():
    set_int = 8
    set_num_bytes = 4
    set_data = b'\x08\x00\x00\x00'

    # create new record
    test_record = _FortranRecord('', 0)  # already tested

    # write integer
    test_record.put_int(set_int)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "4-byte integer")
Ejemplo n.º 19
0
def test_write_FR_single_int():
    set_int = 8
    set_num_bytes = 4
    set_data = b'\x08\x00\x00\x00'

    # create new record
    test_record = _FortranRecord('', 0)  # already tested

    # write integer
    test_record.put_int(set_int)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "4-byte integer")
Ejemplo n.º 20
0
def test_write_FR_single_float():
    set_float = 3.14
    set_num_bytes = 4
    set_data = b'\xc3\xf5H@'

    # create new record
    test_record = _FortranRecord('', 0)  # already tested

    # write float
    test_record.put_float(set_float)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "float")
Ejemplo n.º 21
0
def test_make_empty_FR():
    testRecord = _FortranRecord('',0)

    if testRecord.data != '':
        raise FortranRecordError("Failed to make an new empty _FortranRecord.  "
                                 "Record has data.")
    if testRecord.numBytes != 0:
        raise FortranRecordError("Failed to make an new empty _FortranRecord.  "
                                 "Record has numBytes>0.")
    if testRecord.pos != 0:
        raise FortranRecordError("Failed to make an new empty _FortranRecord.  "
                                 "Position is not at 0.")

    return 1
Ejemplo n.º 22
0
def test_make_empty_FR():
    test_record = _FortranRecord('', 0)

    if len(test_record.data) != 0:
        raise ValueError("Failed to make an new empty _FortranRecord. "
                         " Record has data.")
    if test_record.num_bytes != 0:
        raise ValueError("Failed to make an new empty _FortranRecord. "
                         " Record has num_bytes>0.")
    if test_record.pos != 0:
        raise ValueError("Failed to make an new empty _FortranRecord. "
                         " Position is not at 0.")

    return 1
Ejemplo n.º 23
0
def test_write_FR_single_string():
    set_string = "Hello World!"
    set_length = len(set_string)
    set_num_bytes = 12
    set_data = b'Hello World!'

    # create new record
    test_record = _FortranRecord('', 0)  # already tested

    # write string
    test_record.put_string([set_string], 12, 1)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "string")
Ejemplo n.º 24
0
def test_read_FR_single_long():
    set_long = 8

    test_record = _FortranRecord("", 0)  # already tested
    test_record.put_long([set_long])  # already tested

    test_record.reset()  # already tested

    testLong = test_record.get_long()[0]

    if testLong != set_long:
        raise ValueError("Value from get_long doesn't match value " "from put_long.")

    return 1
Ejemplo n.º 25
0
def test_write_FR_single_long():
    set_long = 8

    set_num_bytes = 8
    set_data = b'\x08\x00\x00\x00\x00\x00\x00\x00'

    # create new record
    test_record = _FortranRecord('', 0)  # already tested

    # write long
    test_record.put_long(set_long)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "8-byte integer")
Ejemplo n.º 26
0
def test_read_FR_single_int():
    set_int = 8

    test_record = _FortranRecord("", 0)  # already tested
    test_record.put_int([set_int])  # already tested

    test_record.reset()  # already tested

    test_int = test_record.get_int()[0]

    if test_int != set_int:
        raise ValueError("Value from get_int doesn't match value " "from put_int.")

    return 1
Ejemplo n.º 27
0
def test_read_FR_string_list():
    set_string_list = ["Hello ", "World!"]
    set_length = len(set_string_list[0])

    test_record = _FortranRecord("", 0)
    test_record.put_string(set_string_list, set_length)
    test_record.reset()

    test_string_list = test_record.get_string(set_length, 2)

    if test_string_list != set_string_list:
        raise ValueError("List from get_string doesn't match value " "from put_string.")

    return 1
Ejemplo n.º 28
0
def test_read_FR_double_list():
    double_list = [2.34, 8.65]

    test_record = _FortranRecord("", 0)
    test_record.put_double(double_list)

    test_record.reset()

    testList = test_record.get_double(2)

    if testList != double_list:
        raise ValueError("List from get_double doesn't match value " "from put_double.")

    return 1
Ejemplo n.º 29
0
def test_write_FR_single_string():
    set_string = "Hello World!"
    set_length = len(set_string)
    set_num_bytes = 12
    set_data = b'Hello World!'

    # create new record
    test_record = _FortranRecord('', 0)  # already tested

    # write string
    test_record.put_string([set_string], 12, 1)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "string")
Ejemplo n.º 30
0
def test_write_FR_single_long():
    set_long = 8

    set_num_bytes = 8
    set_data = b'\x08\x00\x00\x00\x00\x00\x00\x00'

    # create new record
    test_record = _FortranRecord('', 0)  # already tested

    # write long
    test_record.put_long(set_long)

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "8-byte integer")
Ejemplo n.º 31
0
def test_make_empty_FR():
    test_record = _FortranRecord('', 0)

    if len(test_record.data) != 0:
        raise ValueError("Failed to make an new empty _FortranRecord. "
                         " Record has data.")
    if test_record.num_bytes != 0:
        raise ValueError("Failed to make an new empty _FortranRecord. "
                         " Record has num_bytes>0.")
    if test_record.pos != 0:
        raise ValueError("Failed to make an new empty _FortranRecord. "
                         " Position is not at 0.")

    return 1
Ejemplo n.º 32
0
def test_reset_FR():
    temp_pos = 4

    test_record = _FortranRecord('', 0)  # already tested

    test_record.pos = temp_pos

    if test_record.pos != temp_pos:
        raise ValueError("Internal error: unable to update test_record.pos")

    test_record.reset()
    if test_record.pos != 0:
        raise ValueError("reset() method did not reset pos")

    return 1
Ejemplo n.º 33
0
def test_read_FR_single_double():
    set_double = 1.43

    test_record = _FortranRecord('', 0)
    test_record.put_double([set_double])

    test_record.reset()

    testDouble = test_record.get_double()[0]

    if testDouble != set_double:
        raise ValueError("Value from get_double doesn't match value "
                         "from put_double.")

    return 1
Ejemplo n.º 34
0
def test_read_FR_double_list():
    double_list = [2.34, 8.65]

    test_record = _FortranRecord('', 0)
    test_record.put_double(double_list)

    test_record.reset()

    testList = test_record.get_double(2)

    if testList != double_list:
        raise ValueError("List from get_double doesn't match value "
                         "from put_double.")

    return 1
Ejemplo n.º 35
0
def test_read_FR_single_long():
    set_long = 8

    test_record = _FortranRecord('', 0)  # already tested
    test_record.put_long([set_long])  # already tested

    test_record.reset()  # already tested

    testLong = test_record.get_long()[0]

    if testLong != set_long:
        raise ValueError("Value from get_long doesn't match value "
                         "from put_long.")

    return 1
Ejemplo n.º 36
0
def test_read_FR_single_double():
    set_double = 1.43

    test_record = _FortranRecord('', 0)
    test_record.put_double([set_double])

    test_record.reset()

    testDouble = test_record.get_double()[0]

    if testDouble != set_double:
        raise ValueError("Value from get_double doesn't match value "
                         "from put_double.")

    return 1
Ejemplo n.º 37
0
def test_read_FR_long_list():
    set_long_list = [8, 16]
    numLongs = 2

    test_record = _FortranRecord("", 0)  # already tested
    test_record.put_long(set_long_list)  # already tested

    test_record.reset()  # already tested

    testLong = test_record.get_long(numLongs)

    if testLong != set_long_list:
        raise ValueError("Value from get_long doesn't match value " "from put_long.")

    return 1
Ejemplo n.º 38
0
def test_read_FR_string_list():
    set_string_list = ["Hello ", "World!"]
    set_length = len(set_string_list[0])

    test_record = _FortranRecord('', 0)
    test_record.put_string(set_string_list, set_length)
    test_record.reset()

    test_string_list = test_record.get_string(set_length, 2)

    if test_string_list != set_string_list:
        raise ValueError("List from get_string doesn't match value "
                         "from put_string.")

    return 1
Ejemplo n.º 39
0
def test_reset_FR():
    temp_pos = 4

    test_record = _FortranRecord("", 0)  # already tested

    test_record.pos = temp_pos

    if test_record.pos != temp_pos:
        raise ValueError("Internal error: unable to update test_record.pos")

    test_record.reset()
    if test_record.pos != 0:
        raise ValueError("reset() method did not reset pos")

    return 1
Ejemplo n.º 40
0
def test_read_FR_single_int():
    set_int = 8

    test_record = _FortranRecord('', 0)  # already tested
    test_record.put_int([set_int])  # already tested

    test_record.reset()  # already tested

    test_int = test_record.get_int()[0]

    if test_int != set_int:
        raise ValueError("Value from get_int doesn't match value "
                         "from put_int.")

    return 1
Ejemplo n.º 41
0
def test_read_FR_int_list():
    set_intList = [8, 16]
    num_ints = 2

    test_record = _FortranRecord("", 0)  # already tested
    test_record.put_int(set_intList)  # already tested

    test_record.reset()  # already tested

    test_int = test_record.get_int(num_ints)

    if test_int != set_intList:
        raise ValueError("Value from get_int doesn't match value " "from put_int.")

    return 1
Ejemplo n.º 42
0
def test_read_FR_int_list():
    set_intList = [8, 16]
    num_ints = 2

    test_record = _FortranRecord('', 0)  # already tested
    test_record.put_int(set_intList)  # already tested

    test_record.reset()  # already tested

    test_int = test_record.get_int(num_ints)

    if test_int != set_intList:
        raise ValueError("Value from get_int doesn't match value "
                         "from put_int.")

    return 1
Ejemplo n.º 43
0
def test_read_FR_long_list():
    set_long_list = [8, 16]
    numLongs = 2

    test_record = _FortranRecord('', 0)  # already tested
    test_record.put_long(set_long_list)  # already tested

    test_record.reset()  # already tested

    testLong = test_record.get_long(numLongs)

    if testLong != set_long_list:
        raise ValueError("Value from get_long doesn't match value "
                         "from put_long.")

    return 1
Ejemplo n.º 44
0
def test_read_FR_single_string():
    set_string = "Hello World!"
    set_length = len(set_string)

    # create new record
    test_record = _FortranRecord("", 0)  # already tested
    test_record.put_string([set_string], 12, 1)

    test_record.reset()

    test_string = test_record.get_string(set_length)[0]

    if test_string != set_string:
        raise ValueError("List from get_string doesn't match value " "from put_string.")

    return 1
Ejemplo n.º 45
0
def test_read_FR_single_string():
    set_string = "Hello World!"
    set_length = len(set_string)

    # create new record
    test_record = _FortranRecord('', 0)  # already tested
    test_record.put_string([set_string], 12, 1)

    test_record.reset()

    test_string = test_record.get_string(set_length)[0]

    if test_string != set_string:
        raise ValueError("List from get_string doesn't match value "
                         "from put_string.")

    return 1
Ejemplo n.º 46
0
def test_make_empty_FR():
    testRecord = _FortranRecord('', 0)

    if testRecord.data != '':
        raise FortranRecordError(
            "Failed to make an new empty _FortranRecord.  "
            "Record has data.")
    if testRecord.numBytes != 0:
        raise FortranRecordError(
            "Failed to make an new empty _FortranRecord.  "
            "Record has numBytes>0.")
    if testRecord.pos != 0:
        raise FortranRecordError(
            "Failed to make an new empty _FortranRecord.  "
            "Position is not at 0.")

    return 1
Ejemplo n.º 47
0
def test_write_FR_mixed_record():
    set_int = 8
    set_float = 3.14
    set_double_list = [1.6e-19, 6.02e23]
    set_string = "Hello World!"

    set_num_bytes = 4 + 4 + (2 * 8) + 12
    set_data = b'\x08\x00\x00\x00Hello World!#B\x92\x0c\xa1\x9c\x07<a\xd3' + \
               b'\xa8\x10\x9f\xde\xdfD\xc3\xf5H@'

    test_record = _FortranRecord('', 0)
    test_record.put_int(set_int)
    test_record.put_string([set_string], len(set_string))
    test_record.put_double(set_double_list)
    test_record.put_float([set_float])

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "list of doubles")
Ejemplo n.º 48
0
def test_write_FR_mixed_record():
    set_int = 8
    set_float = 3.14
    set_double_list = [1.6e-19, 6.02e23]
    set_string = "Hello World!"

    set_num_bytes = 4 + 4 + (2 * 8) + 12
    set_data = b'\x08\x00\x00\x00Hello World!#B\x92\x0c\xa1\x9c\x07<a\xd3' + \
               b'\xa8\x10\x9f\xde\xdfD\xc3\xf5H@'

    test_record = _FortranRecord('', 0)
    test_record.put_int(set_int)
    test_record.put_string([set_string], len(set_string))
    test_record.put_double(set_double_list)
    test_record.put_float([set_float])

    return check_write_record_data(test_record, set_num_bytes, set_num_bytes,
                                   set_data, "list of doubles")
Ejemplo n.º 49
0
def test_read_FR_mixed_record():

    setInt = 8
    setFloat = 3.14
    setDoubleList = [1.6e-19,6.02e23]
    setString = "Hello World!"
    
    testRecord = _FortranRecord('',0)
    testRecord.put_int([setInt])
    testRecord.put_string([setString],len(setString))
    testRecord.put_double(setDoubleList)
    testRecord.put_float([setFloat])

    testRecord.reset()

    testInt = testRecord.get_int()[0]
    if testInt != setInt:
        raise FortranRecordError("Value from get_int doesn't match value "
                                 "from put_int.")

    testString = testRecord.get_string(12)[0]
    if testString != setString:
        raise FortranRecordError("List from get_string doesn't match value "
                                 "from put_string.")

    testDoubleList = testRecord.get_double(2)
    if testDoubleList != setDoubleList:
        raise FortranRecordError("List from get_double doesn't match value "
                                 "from put_double.")

    testFloat = testRecord.get_float()[0]
    # NOTE: since Python doesn't do native 32-bit floats, both values should be
    #       passed through a string formatting to truncate to 6 digits
    setFloat  = '%10.6f' % setFloat
    testFloat = '%10.6f' % testFloat

    if testFloat != setFloat:
        print str(setFloat) + " != " + str(testFloat)
        raise FortranRecordError("Value from get_float doesn't match value "
                                 "from put_float.")
    
    return 1
Ejemplo n.º 50
0
def test_read_FR_mixed_record():

    setInt = 8
    setFloat = 3.14
    setDoubleList = [1.6e-19, 6.02e23]
    setString = "Hello World!"

    testRecord = _FortranRecord('', 0)
    testRecord.put_int([setInt])
    testRecord.put_string([setString], len(setString))
    testRecord.put_double(setDoubleList)
    testRecord.put_float([setFloat])

    testRecord.reset()

    testInt = testRecord.get_int()[0]
    if testInt != setInt:
        raise FortranRecordError("Value from get_int doesn't match value "
                                 "from put_int.")

    testString = testRecord.get_string(12)[0]
    if testString != setString:
        raise FortranRecordError("List from get_string doesn't match value "
                                 "from put_string.")

    testDoubleList = testRecord.get_double(2)
    if testDoubleList != setDoubleList:
        raise FortranRecordError("List from get_double doesn't match value "
                                 "from put_double.")

    testFloat = testRecord.get_float()[0]
    # NOTE: since Python doesn't do native 32-bit floats, both values should be
    #       passed through a string formatting to truncate to 6 digits
    setFloat = '%10.6f' % setFloat
    testFloat = '%10.6f' % testFloat

    if testFloat != setFloat:
        print str(setFloat) + " != " + str(testFloat)
        raise FortranRecordError("Value from get_float doesn't match value "
                                 "from put_float.")

    return 1
Ejemplo n.º 51
0
def test_read_FR_single_float():
    set_float = 6.1

    test_record = _FortranRecord("", 0)
    test_record.put_float([set_float])

    test_record.reset()

    test_float = test_record.get_float()[0]

    # NOTE: since Python doesn't do native 32-bit floats, both values should be
    #       passed through a string formatting to truncate to 6 digits
    set_float = "%10.6f" % set_float
    test_float = "%10.6f" % test_float

    if test_float != set_float:
        print("{0} != {1}".format(set_float, test_float))
        raise ValueError("Value from get_float doesn't match value " "from put_float.")

    return 1
Ejemplo n.º 52
0
def test_read_FR_float_list():
    floatList = [2.34, 8.65]

    test_record = _FortranRecord("", 0)
    test_record.put_float(floatList)

    test_record.reset()

    testList = test_record.get_float(2)

    # NOTE: since Python doesn't do native 32-bit floats, both values should be
    #       passed through a string formatting to truncate to 6 digits
    floatList = ["%10.6f" % floatList[0], "%10.6f" % floatList[1]]
    testList = ["%10.6f" % testList[0], "%10.6f" % testList[1]]

    if testList != floatList:
        print(floatList)
        print(testList)
        raise ValueError("List from get_float doesn't match value " "from put_float.")

    return 1
Ejemplo n.º 53
0
def test_read_FR_single_float():
    set_float = 6.1

    test_record = _FortranRecord('', 0)
    test_record.put_float([set_float])

    test_record.reset()

    test_float = test_record.get_float()[0]

    # NOTE: since Python doesn't do native 32-bit floats, both values should be
    #       passed through a string formatting to truncate to 6 digits
    set_float = '%10.6f' % set_float
    test_float = '%10.6f' % test_float

    if test_float != set_float:
        print("{0} != {1}".format(set_float, test_float))
        raise ValueError("Value from get_float doesn't match value "
                         "from put_float.")

    return 1
Ejemplo n.º 54
0
def test_read_FR_float_list():
    floatList = [2.34, 8.65]

    test_record = _FortranRecord('', 0)
    test_record.put_float(floatList)

    test_record.reset()

    testList = test_record.get_float(2)

    # NOTE: since Python doesn't do native 32-bit floats, both values should be
    #       passed through a string formatting to truncate to 6 digits
    floatList = ['%10.6f' % floatList[0], '%10.6f' % floatList[1]]
    testList = ['%10.6f' % testList[0], '%10.6f' % testList[1]]

    if testList != floatList:
        print(floatList)
        print(testList)
        raise ValueError("List from get_float doesn't match value "
                         "from put_float.")

    return 1
Ejemplo n.º 55
0
def test_read_FR_single_float():

    setFloat = 6.1

    testRecord = _FortranRecord('', 0)
    testRecord.put_float([setFloat])

    testRecord.reset()

    testFloat = testRecord.get_float()[0]

    # NOTE: since Python doesn't do native 32-bit floats, both values should be
    #       passed through a string formatting to truncate to 6 digits
    setFloat = '%10.6f' % setFloat
    testFloat = '%10.6f' % testFloat

    if testFloat != setFloat:
        print str(setFloat) + " != " + str(testFloat)
        raise FortranRecordError("Value from get_float doesn't match value "
                                 "from put_float.")

    return 1