コード例 #1
0
ファイル: test_csv_interface.py プロジェクト: dynaryu/eqrm
    def unnfinished_test_quick_convert_csv_to_arrays_lats_longs_file(self):
        (handle, file_name) = tempfile.mkstemp('.csv', 'test_csv_interface_')
        os.close(handle)
        
        LONGITUDE = [11.5, 11.6, 11.7, 11.8]
        LATITUDE = [-3.1, -3.2, -3.3, -3.4]
        WALLS = ['Brick veneer', 'Double Brick', 'Fibro', 'Double Brick']
        
        attribute_dic = {'LONGITUDE': LONGITUDE,
                         'LATITUDE': LATITUDE,
                         'WALLS': WALLS}
        title_index_dic = {'LONGITUDE': 0,
                           'LATITUDE': 1,
                           'WALLS': 2}
        util.dict2csv(file_name, title_index_dic, attribute_dic)
        print "file_name", file_name
        lon = csvi.quick_convert_csv_to_arrays(file_name, LONGITUDE=float)
        assert lon.keys()[0] == 'LONGITUDE'
        assert len(lon.keys()) == 1
        assert scipy.allclose(LONGITUDE, lon['LONGITUDE'])
        
        all_conversions = {'LONGITUDE': float,
                           'LATITUDE': float,
                           'WALLS': str}

        all = csvi.quick_convert_csv_to_arrays(self.dummy_f, **all_conversions)
        assert len(all.keys()) == 3
        assert scipy.allclose(LATITUDE, all['LATITUDE'])
        assert scipy.allclose(LONGITUDE, all['LONGITUDE'])
        assert scipy.allclose(self.WALLS == all['WALLS'])

        os.remove(file_name)
コード例 #2
0
    def unnfinished_test_quick_convert_csv_to_arrays_lats_longs_file(self):
        (handle, file_name) = tempfile.mkstemp('.csv', 'test_csv_interface_')
        os.close(handle)

        LONGITUDE = [11.5, 11.6, 11.7, 11.8]
        LATITUDE = [-3.1, -3.2, -3.3, -3.4]
        WALLS = ['Brick veneer', 'Double Brick', 'Fibro', 'Double Brick']

        attribute_dic = {
            'LONGITUDE': LONGITUDE,
            'LATITUDE': LATITUDE,
            'WALLS': WALLS
        }
        title_index_dic = {'LONGITUDE': 0, 'LATITUDE': 1, 'WALLS': 2}
        util.dict2csv(file_name, title_index_dic, attribute_dic)
        print "file_name", file_name
        lon = csvi.quick_convert_csv_to_arrays(file_name, LONGITUDE=float)
        assert lon.keys()[0] == 'LONGITUDE'
        assert len(lon.keys()) == 1
        assert scipy.allclose(LONGITUDE, lon['LONGITUDE'])

        all_conversions = {'LONGITUDE': float, 'LATITUDE': float, 'WALLS': str}

        all = csvi.quick_convert_csv_to_arrays(self.dummy_f, **all_conversions)
        assert len(all.keys()) == 3
        assert scipy.allclose(LATITUDE, all['LATITUDE'])
        assert scipy.allclose(LONGITUDE, all['LONGITUDE'])
        assert scipy.allclose(self.WALLS == all['WALLS'])

        os.remove(file_name)
コード例 #3
0
ファイル: test_csv_interface.py プロジェクト: dynaryu/eqrm
    def test_dict2csv_convert(self):
        (handle, file_name) = tempfile.mkstemp('.csv', 'test_csv_interface_')
        os.close(handle)
        
        attribute_dic = {'LONGITUDE': self.LONGITUDE,
                         'LATITUDE': self.LATITUDE,
                         'WALLS': self.WALLS}
        # This is actually assumed to be a list in the code...
        title_index_dic = {'LONGITUDE': 0,
                           'LATITUDE': 1,
                           'WALLS': 2}
        convert = {'LONGITUDE': float,
                   'LATITUDE': float,
                   'WALLS' :str}
        util.dict2csv(file_name, title_index_dic, attribute_dic)

        attribute_dic_new, title_index_dic_new = \
            csvi.csv2dict(file_name, title_check_list=title_index_dic,
                          convert=convert)
        self.assert_(attribute_dic_new['LONGITUDE'] == self.LONGITUDE)
        self.assert_(attribute_dic_new['LATITUDE'] == self.LATITUDE)
        self.assert_(attribute_dic_new['WALLS'] == self.WALLS)
        self.assert_(attribute_dic_new == attribute_dic)
        self.assert_(title_index_dic_new == title_index_dic_new)
        
        os.remove(file_name)
コード例 #4
0
ファイル: test_csv_interface.py プロジェクト: dynaryu/eqrm
    def test_dict2csv_bad(self):
        (handle, file_name) = tempfile.mkstemp('.csv', 'test_csv_interface_')
        os.close(handle)
        
        attribute_dic = {'LONGITUDE': self.LONGITUDE,
                         'LATITUDE': self.LATITUDE,
                         'WALLS': self.WALLS}
        title_index_dic = {'LONGITUDE': 0,
                           'LATITUDE': 1,
                           'WALLS': 2}
        util.dict2csv(file_name, title_index_dic, attribute_dic)

        try:
            attribute_dic_new, title_index_dic_new = \
                csvi.csv2dict(file_name, title_check_list={'wire': 8})
        except IOError:
            os.remove(file_name)
        else:
            os.remove(file_name)
            self.failUnless(False, "Error not thrown")
コード例 #5
0
    def test_dict2csv_bad(self):
        (handle, file_name) = tempfile.mkstemp('.csv', 'test_csv_interface_')
        os.close(handle)

        attribute_dic = {
            'LONGITUDE': self.LONGITUDE,
            'LATITUDE': self.LATITUDE,
            'WALLS': self.WALLS
        }
        title_index_dic = {'LONGITUDE': 0, 'LATITUDE': 1, 'WALLS': 2}
        util.dict2csv(file_name, title_index_dic, attribute_dic)

        try:
            attribute_dic_new, title_index_dic_new = \
                csvi.csv2dict(file_name, title_check_list={'wire': 8})
        except IOError:
            os.remove(file_name)
        else:
            os.remove(file_name)
            self.failUnless(False, "Error not thrown")
コード例 #6
0
ファイル: test_csv_interface.py プロジェクト: dynaryu/eqrm
    def test_dict2csv(self):
        (handle, file_name) = tempfile.mkstemp('.csv', 'test_csv_interface_')
        os.close(handle)
        
        attribute_dic = {'LONGITUDE': self.LONGITUDE,
                         'LATITUDE': self.LATITUDE,
                         'WALLS': self.WALLS}
        title_index_dic = {'LONGITUDE': 0,
                           'LATITUDE': 1,
                           'WALLS': 2}

        util.dict2csv(file_name, title_index_dic, attribute_dic)

        (attribute_dic_new, title_index_dic_new) = \
            csvi.csv2dict(file_name, title_check_list=title_index_dic)
        attribute_dic_new['LONGITUDE'] = \
            [float(x) for x in attribute_dic_new['LONGITUDE']]
        attribute_dic_new['LATITUDE'] = \
            [float(x) for x in attribute_dic_new['LATITUDE']]

        self.assert_(attribute_dic_new == attribute_dic)
        self.assert_(title_index_dic_new == title_index_dic_new)
        
        os.remove(file_name)
コード例 #7
0
    def test_dict2csv_convert(self):
        (handle, file_name) = tempfile.mkstemp('.csv', 'test_csv_interface_')
        os.close(handle)

        attribute_dic = {
            'LONGITUDE': self.LONGITUDE,
            'LATITUDE': self.LATITUDE,
            'WALLS': self.WALLS
        }
        # This is actually assumed to be a list in the code...
        title_index_dic = {'LONGITUDE': 0, 'LATITUDE': 1, 'WALLS': 2}
        convert = {'LONGITUDE': float, 'LATITUDE': float, 'WALLS': str}
        util.dict2csv(file_name, title_index_dic, attribute_dic)

        attribute_dic_new, title_index_dic_new = \
            csvi.csv2dict(file_name, title_check_list=title_index_dic,
                          convert=convert)
        self.assert_(attribute_dic_new['LONGITUDE'] == self.LONGITUDE)
        self.assert_(attribute_dic_new['LATITUDE'] == self.LATITUDE)
        self.assert_(attribute_dic_new['WALLS'] == self.WALLS)
        self.assert_(attribute_dic_new == attribute_dic)
        self.assert_(title_index_dic_new == title_index_dic_new)

        os.remove(file_name)
コード例 #8
0
    def test_dict2csv(self):
        (handle, file_name) = tempfile.mkstemp('.csv', 'test_csv_interface_')
        os.close(handle)

        attribute_dic = {
            'LONGITUDE': self.LONGITUDE,
            'LATITUDE': self.LATITUDE,
            'WALLS': self.WALLS
        }
        title_index_dic = {'LONGITUDE': 0, 'LATITUDE': 1, 'WALLS': 2}

        util.dict2csv(file_name, title_index_dic, attribute_dic)

        (attribute_dic_new, title_index_dic_new) = \
            csvi.csv2dict(file_name, title_check_list=title_index_dic)
        attribute_dic_new['LONGITUDE'] = \
            [float(x) for x in attribute_dic_new['LONGITUDE']]
        attribute_dic_new['LATITUDE'] = \
            [float(x) for x in attribute_dic_new['LATITUDE']]

        self.assert_(attribute_dic_new == attribute_dic)
        self.assert_(title_index_dic_new == title_index_dic_new)

        os.remove(file_name)