Esempio n. 1
0
def test_read_file_in():
    """ Test read_file_in() """

    # description of test    
    description = "Test read_file_in() - test reading of water use files; using simplified water use formatted file"

    # expected values to test with actual values
    expected = {"months": "JFM_WU",
                "units": "Mgal/day",
                "column_names": ["huc12", "newhydroid", "AqGwWL", "CoGwWL", "DoGwWL", "InGwWL", "IrGwWL"],
                "huc12": ["20401010101", "20401010101", "20401010101", "20401010101", "20401010101", "20401010101", "20401010102"],
                "newhydroid": ["256", "241", "222", "220", "12", "11", "8"],
                "AqGwWL": [2.0, 4.0, 6.0, 3.0, 1.0, 2.0, 2.0],
                "CoGwWL": [5.0, 3.0, 4.0, 8.0, 3.0, 6.0, 1.0],
                "DoGwWL": [2.0, 4.0, 6.0, 3.0, 1.0, 2.0, 2.0],
                "InGwWL": [5.0, 3.0, 4.0, 8.0, 3.0, 6.0, 1.0],
                "IrGwWL": [-2.0, -4.0, -6.0, -8.0, -1.0, -1.0, -1.0]
    }
    
    # create test data
    fileobj = StringIO(fixture["data_file_JFM"])
    
    # read file object
    actual = wateruse.read_file_in(fileobj)
    
    # assert equality
    _perform_assertion(actual, expected, description = description)  
Esempio n. 2
0
def _get_all_total_wateruse_for_tests(wateruse_files, id_list, wateruse_factor_file = None, in_cfs = False):
    """ Test get_all_total_wateruse - strictly a test function here that mirrors get_all_total_wateruse in water.py but creates fileobj from StringIO instead of reading a file path """

    # calculate average values for a list of water use files
    all_total_wateruse_dict = {}
    for wateruse_file in wateruse_files:
        fileobj = StringIO(wateruse_file)
        wateruse_data = wateruse.read_file_in(fileobj) 

        # if water use factor file is supplied, then apply factors        
        if wateruse_factor_file:
            # read water use factor file
            fileobj_factors = StringIO(wateruse_factor_file)
            wateruse_factors = wateruse.read_factor_file_in(fileobj_factors)
                
            # calculate average wateruse for a list of ids
            total_wateruse_dict = wateruse.get_total_wateruse(wateruse_data = wateruse_data, id_list = id_list, wateruse_factors = wateruse_factors)

        else:
            # calculate average wateruse for a list of ids
            total_wateruse_dict = wateruse.get_total_wateruse(wateruse_data = wateruse_data, id_list = id_list)

        # convert values to cfs
        if in_cfs:
            for key, value in total_wateruse_dict.iteritems():
                value_cfs = wateruse.convert_wateruse_units(value)
                total_wateruse_dict[key] = value_cfs
        
        # update dictionary 
        all_total_wateruse_dict.update(total_wateruse_dict)   
    
    return all_total_wateruse_dict