예제 #1
0
def load_fake_datas(select_dataset_code=None):
    """Load datas from DATASETS dict
    
    key: DATASETS[dataset_code]['datas']
    """
    
    fetcher = bis.BIS()
    
    results = {}
    
    for dataset_code, dataset in DATASETS.items():
        
        if select_dataset_code and select_dataset_code != dataset_code:
            continue
        
        _dataset = Datasets(provider_name=bis.PROVIDER_NAME, 
                    dataset_code=dataset_code, 
                    name=dataset['name'], 
                    doc_href=dataset['doc_href'], 
                    fetcher=fetcher, 
                    is_load_previous_version=False)
        
        dataset_datas = bis.BIS_Data(_dataset, is_autoload=False)
        dataset_datas._load_datas(dataset['datas'])
        
        results[dataset_code] = {'series': []}

        for d in dataset_datas.rows:
            row = bis.csv_dict(dataset_datas.headers, d)
            results[dataset_code]['series'].append(dataset_datas.build_serie(d))
            
            #pprint(results)
    return results
예제 #2
0
    def test_load_read_csv(self):
        """Load special csv - direct from string
        """
        # nosetests -s -v dlstats.tests.fetchers.test_bis:BISUtilsTestCase.test_load_read_csv

        d = {}
        #d['CNFS'] = DATASETS['CNFS'].copy()        
        d = DATASETS.copy()
        
        for dataset_code, dataset in d.items():
            datas = dataset['datas']            
            fileobj = io.StringIO(datas, newline="\n")
            rows, headers, release_date, dimension_keys, periods = bis.local_read_csv(fileobj=fileobj)
            #len(dimension_keys)
            #print(headers)
            self.assertTrue('KEY' in headers)
            
            line1 = bis.csv_dict(headers, next(rows))
예제 #3
0
    def test_load_read_csv(self):

        # nosetests -s -v dlstats.tests.fetchers.test_bis:BISUtilsTestCase.test_load_read_csv
        
        d = FETCHER_DATASETS.copy()
        print()
        for dataset_code, dataset in d.items():
            if dataset_code != "DSRP":
                continue
            filepath = FETCHER_DATASETS[dataset_code]["filepath"]
            datas = dataset['datas']            
            fileobj = io.StringIO(datas)#, newline=os.linesep)
            rows, headers, release_date, dimension_keys, periods = bis.local_read_csv(fileobj=fileobj)
            self.assertTrue('KEY' in headers)
            line1 = bis.csv_dict(headers, next(rows))
            #TODO: test values ?
            print(dataset_code, dimension_keys, line1)
            self.assertEqual(len(dimension_keys), FETCHER_DATASETS[dataset_code]["dimensions_count"])
예제 #4
0
    def test_load_read_csv(self):

        # nosetests -s -v dlstats.tests.fetchers.test_bis:BISUtilsTestCase.test_load_read_csv

        d = FETCHER_DATASETS.copy()
        print()
        for dataset_code, dataset in d.items():
            if dataset_code != "DSRP":
                continue
            filepath = FETCHER_DATASETS[dataset_code]["filepath"]
            datas = dataset['datas']
            fileobj = io.StringIO(datas)  #, newline=os.linesep)
            rows, headers, release_date, dimension_keys, periods = bis.local_read_csv(
                fileobj=fileobj)
            self.assertTrue('KEY' in headers)
            line1 = bis.csv_dict(headers, next(rows))
            #TODO: test values ?
            print(dataset_code, dimension_keys, line1)
            self.assertEqual(
                len(dimension_keys),
                FETCHER_DATASETS[dataset_code]["dimensions_count"])