def skip_test__write_metadata(self): try: from opus_gui.results_manager.run.indicator_framework.image_types.table import Table except: pass else: table = Table( source_data = self.cross_scenario_source_data, attribute = 'opus_core.test.attribute', dataset_name = 'test', output_type = 'tab', years = [1980,1981] # Indicators are not actually being computed, so the years don't matter here. ) table.create(False) table.date_computed = None output = self.data_manager._export_indicator_to_file( indicator = table, source_data = self.cross_scenario_source_data, year = None) expected = [ '<version>1.0</version>', '<Table>', '\t<attributes>[\'opus_core.test.attribute\']</attributes>', '\t<dataset_name>test</dataset_name>', '\t<years>[1980, 1981]</years>', '\t<date_computed>None</date_computed>', '\t<name>attribute</name>', '\t<operation>None</operation>', '\t<storage_location>%s</storage_location>'%os.path.join(self.temp_cache_path, 'indicators'), '\t<output_type>tab</output_type>', '\t<source_data>', '\t\t<cache_directory>%s</cache_directory>'%self.temp_cache_path, '\t\t<comparison_cache_directory>%s</comparison_cache_directory>'%self.temp_cache_path2, '\t\t<run_description>%s</run_description>'%self.cross_scenario_source_data.get_run_description(), '\t\t<years>[1980]</years>', '\t\t<package_order>[\'opus_core\']</package_order>', '\t</source_data>', '</Table>' ] for i in range(len(output)): if expected[i] != output[i]: print expected[i] print output[i] self.assertEqual(output,expected)
def skip_test__read_write_metadata(self): try: from opus_gui.results_manager.run.indicator_framework.image_types.table import Table except: raise else: table = Table( source_data = self.source_data, attribute = 'opus_core.test.attribute', dataset_name = 'test', output_type = 'tab', years = [1980,1981] # Indicators are not actually being computed, so the years don't matter here. ) table.create(False) self.data_manager._export_indicator_to_file(indicator = table, source_data = self.source_data, year = None) metadata_file = table.get_file_name(extension = 'meta') metadata_path = os.path.join(table.get_storage_location(), metadata_file) self.assertEqual(os.path.exists(metadata_path), True) expected_path = 'test__tab__attribute.meta' self.assertEqual(metadata_file,expected_path) new_table = self.data_manager._import_indicator_from_file(metadata_path) for attr in ['attributes','dataset_name', 'output_type','date_computed', 'years']: old_val = table.__getattribute__(attr) new_val = new_table.__getattribute__(attr) self.assertEqual(old_val,new_val) self.assertEqual(table.source_data.cache_directory, new_table.source_data.cache_directory) self.assertEqual(table.source_data.dataset_pool_configuration.package_order, new_table.source_data.dataset_pool_configuration.package_order)