diff --git a/dsi/plugins/file_reader.py b/dsi/plugins/file_reader.py index 54ed98b..ea8e0ce 100644 --- a/dsi/plugins/file_reader.py +++ b/dsi/plugins/file_reader.py @@ -76,7 +76,7 @@ def add_rows(self) -> None: if self.db_name is not None: self.csv_data[self.db_name] = table_data else: - self.csv_data["CSV"] = table_data + self.csv_data = table_data self.set_schema_2(self.csv_data) diff --git a/dsi/plugins/metadata.py b/dsi/plugins/metadata.py index 6b19436..15fdfbf 100644 --- a/dsi/plugins/metadata.py +++ b/dsi/plugins/metadata.py @@ -64,7 +64,13 @@ def set_schema(self, table_data: list, validation_model=None) -> None: self.strict_mode_lock = True def set_schema_2(self, collection, validation_model=None) -> None: - self.output_collector = collection + # Finds file_reader class that called set_schema and assigns that as table_name for this data + if not isinstance(collection[next(iter(collection))], OrderedDict): + caller_frame = inspect.stack()[1] + tableName = caller_frame.frame.f_locals.get('self', None).__class__.__name__ + self.output_collector[tableName] = collection + else: + self.output_collector = collection self.table_cnt = len(collection.keys()) self.validation_model = validation_model diff --git a/dsi/plugins/tests/test_file_reader.py b/dsi/plugins/tests/test_file_reader.py index cb9ef23..36024cd 100644 --- a/dsi/plugins/tests/test_file_reader.py +++ b/dsi/plugins/tests/test_file_reader.py @@ -97,7 +97,7 @@ def test_csv_plugin_leaves_active_metadata_wellformed(): def test_yaml_reader(): a=Terminal() - a.load_module('plugin', 'YAML', 'reader', filenames=["examples/data/student_test1.yml", "examples/data/student_test2.yml"], target_table_prefix = "student") + a.load_module('plugin', 'YAML1', 'reader', filenames=["examples/data/student_test1.yml", "examples/data/student_test2.yml"], target_table_prefix = "student") a.transload() assert len(a.active_metadata.keys()) == 4 # 4 tables - math, address, physics, dsi_units @@ -110,7 +110,7 @@ def test_yaml_reader(): def test_toml_reader(): a=Terminal() - a.load_module('plugin', 'TOML', 'reader', filenames="examples/data/results.toml", target_table_prefix = "results") + a.load_module('plugin', 'TOML1', 'reader', filenames="examples/data/results.toml", target_table_prefix = "results") a.transload() assert len(a.active_metadata.keys()) == 2 # 2 tables - people and dsi_units diff --git a/dsi/plugins/tests/test_file_writer.py b/dsi/plugins/tests/test_file_writer.py index 2fa1cdb..3ca1cbf 100644 --- a/dsi/plugins/tests/test_file_writer.py +++ b/dsi/plugins/tests/test_file_writer.py @@ -22,8 +22,8 @@ def test_csv_plugin_type(): def test_export_db_erd(): a=Terminal(debug_flag=False) a.load_module('plugin', 'Schema', 'reader', filename="examples/data/example_schema.json" , target_table_prefix = "student") - a.load_module('plugin', 'YAML', 'reader', filenames=["examples/data/student_test1.yml", "examples/data/student_test2.yml"], target_table_prefix = "student") - a.load_module('plugin', 'TOML', 'reader', filenames=["examples/data/results.toml"], target_table_prefix = "results") + a.load_module('plugin', 'YAML1', 'reader', filenames=["examples/data/student_test1.yml", "examples/data/student_test2.yml"], target_table_prefix = "student") + a.load_module('plugin', 'TOML1', 'reader', filenames=["examples/data/results.toml"], target_table_prefix = "results") a.load_module('plugin', 'ER_Diagram', 'writer', filename = 'erd_test_output.png') a.transload()