Пример #1
0
def check_write_record_data(record, pos, num, data, typeString):

    if record.pos != pos:
        raise FortranRecordError("Writing " + typeString +
                                 " to record did not update pos properly: " +
                                 str(record.pos))
    if record.numBytes != num:
        raise FortranRecordError("Writing " + typeString +
                                 " to record did not update numBytes properly")
    if record.data != data:
        raise FortranRecordError(
            "Writing " + typeString +
            " to record did not set data member correctly")

    return 1
Пример #2
0
def test_reset_FR():

    tempPos = 4

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

    testRecord.pos = tempPos

    if testRecord.pos != tempPos:
        raise FortranRecordError("Internal error: unable to update "
                                 "testRecord.pos")

    testRecord.reset()
    if testRecord.pos != 0:
        raise FortranRecordError("reset() method did not reset pos")

    return 1
Пример #3
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
Пример #4
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
Пример #5
0
def test_read_FR_string_list():

    setStringList = ["Hello ", "World!"]
    setLength = len(setStringList[0])

    testRecord = _FortranRecord('', 0)
    testRecord.put_string(setStringList, setLength)
    testRecord.reset()

    testStringList = testRecord.get_string(setLength, 2)

    if testStringList != setStringList:
        raise FortranRecordError("List from get_string doesn't match value "
                                 "from put_string.")

    return 1
Пример #6
0
def test_read_FR_double_list():

    doubleList = [2.34, 8.65]

    testRecord = _FortranRecord('', 0)
    testRecord.put_double(doubleList)

    testRecord.reset()

    testList = testRecord.get_double(2)

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

    return 1
Пример #7
0
def test_read_FR_single_double():

    setDouble = 1.43

    testRecord = _FortranRecord('', 0)
    testRecord.put_double([setDouble])

    testRecord.reset()

    testDouble = testRecord.get_double()[0]

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

    return 1
Пример #8
0
def test_read_FR_single_long():

    setLong = 8

    testRecord = _FortranRecord('', 0)  # already tested
    testRecord.put_long([setLong])  # already tested

    testRecord.reset()  # already tested

    testLong = testRecord.get_long()[0]

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

    return 1
Пример #9
0
def test_read_FR_single_int():

    setInt = 8

    testRecord = _FortranRecord('', 0)  # already tested
    testRecord.put_int([setInt])  # already tested

    testRecord.reset()  # already tested

    testInt = testRecord.get_int()[0]

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

    return 1
Пример #10
0
def test_read_FR_long_list():

    setLongList = [8, 16]
    numLongs = 2

    testRecord = _FortranRecord('', 0)  # already tested
    testRecord.put_long(setLongList)  # already tested

    testRecord.reset()  # already tested

    testLong = testRecord.get_long(numLongs)

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

    return 1
Пример #11
0
def test_read_FR_int_list():

    setIntList = [8, 16]
    numInts = 2

    testRecord = _FortranRecord('', 0)  # already tested
    testRecord.put_int(setIntList)  # already tested

    testRecord.reset()  # already tested

    testInt = testRecord.get_int(numInts)

    if testInt != setIntList:
        raise FortranRecordError("Value from get_int doesn't match value "
                                 "from put_int.")

    return 1
Пример #12
0
def test_read_FR_single_string():

    setString = "Hello World!"
    setLength = len(setString)

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

    testRecord.reset()

    testString = testRecord.get_string(setLength)[0]

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

    return 1
Пример #13
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
Пример #14
0
def test_read_FR_float_list():

    floatList = [2.34, 8.65]

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

    testRecord.reset()

    testList = testRecord.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 FortranRecordError("List from get_float doesn't match value "
                                 "from put_float.")

    return 1