From d0bef53736a20b2dd4d4d65a6de4fb99034c9247 Mon Sep 17 00:00:00 2001 From: Steph Merritt Date: Tue, 20 Aug 2024 17:17:46 +0100 Subject: [PATCH] One more unit test, bug fix --- src/adler/dataclasses/AdlerData.py | 11 ++++------- tests/adler/dataclasses/test_AdlerData.py | 6 ++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/adler/dataclasses/AdlerData.py b/src/adler/dataclasses/AdlerData.py index b635f98..72863d8 100644 --- a/src/adler/dataclasses/AdlerData.py +++ b/src/adler/dataclasses/AdlerData.py @@ -110,19 +110,16 @@ def populate_phase_parameters(self, filter_name, **kwargs): kwargs.get(model_key), ) - def populate_from_database(self, filepath, tablename="AdlerData"): + def populate_from_database(self, filepath): """Populates the AdlerData object with information from the most recent timestamped entry for the ssObjectId in a given database. Parameters ----------- filepath : path-like object - Filepath with the location of the output SQL database. - - table_name : str, optional - String containing the table name to write the data to. Default is "AdlerData". + Filepath with the location of the output SQL database. Note that for now, we assume only one table with all the data. """ - con = self._get_database_connection(filepath, tablename) + con = self._get_database_connection(filepath) cursor = con.cursor() sql_query = f"""SELECT * from AdlerData where ssObjectId='{self.ssObjectId}' ORDER BY timestamp DESC LIMIT 1""" query_result = cursor.execute(sql_query) @@ -134,7 +131,7 @@ def populate_from_database(self, filepath, tablename="AdlerData"): raise ValueError("No data found in this database for the supplied ssObjectId.") fetched_data = [np.nan if v is None else v for v in fetched_data_raw] # replaces Nones with nans - column_list = self._get_database_columns(con, tablename) + column_list = self._get_database_columns(con, "AdlerData") con.close() filter_bools = [ diff --git a/tests/adler/dataclasses/test_AdlerData.py b/tests/adler/dataclasses/test_AdlerData.py index 996abb2..6c1e1e2 100644 --- a/tests/adler/dataclasses/test_AdlerData.py +++ b/tests/adler/dataclasses/test_AdlerData.py @@ -278,3 +278,9 @@ def test_read_row_from_database(): error_info_2.value.args[0] == "Data does not exist for some of the requested filters in this database. Filters in database for this object: ['u', 'g', 'r']" ) + + with pytest.raises(ValueError) as error_info_3: + bad_filter = AdlerData("8268570668335894776", ["u", "g", "h"]) + bad_filter.populate_from_database("./dummy_location.db") + + assert error_info_3.value.args[0] == "Database cannot be found at given filepath."