Skip to content

Commit

Permalink
Avoid code repetition in test
Browse files Browse the repository at this point in the history
Co-authored-by: Gonzalo <gonzaponte@gmail.com>
  • Loading branch information
gondiaz and gonzaponte authored Oct 28, 2021
1 parent bef634c commit 21ed856
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions invisible_cities/database/load_db_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,15 @@ def test_RadioactivityData_max_version():

conn = sqlite3.connect(DB.get_db(db_file))

# test Activity table
query = '''SELECT * FROM Activity
WHERE G4Volume = '{0}' AND Isotope = '{1}'
'''
for (g4volume, isotope), req in activity.groupby(["G4Volume", "Isotope"]):
all_versions = pd.read_sql_query(query.format(g4volume, isotope), conn)
max_version = all_versions[all_versions.Version == all_versions.Version.max()]
np.testing.assert_allclose(req.TotalActivity, max_version.TotalActivity)

# test Efficiency table
query = '''SELECT * FROM Efficiency
WHERE G4Volume = '{0}' AND Isotope = '{1}'
'''
for (g4volume, isotope), req in efficiency.groupby(["G4Volume", "Isotope"]):
all_versions = pd.read_sql_query(query.format(g4volume, isotope), conn)
max_version = all_versions[all_versions.Version == all_versions.Version.max()]
np.testing.assert_allclose(req.MCEfficiency, max_version.MCEfficiency)
for table, table_name, column in zip(( activity , efficiency ),
( "Activity", "Efficiency"),
("TotalActivity", "MCEfficiency")):

query = "SELECT * FROM {0} WHERE G4Volume = '{1}' AND Isotope = '{2}'"
for (g4volume, isotope), req in table.groupby(["G4Volume", "Isotope"]):
all_versions = pd.read_sql_query(query.format(table_name, g4volume, isotope), conn)
max_version = all_versions[all_versions.Version == all_versions.Version.max()]
np.testing.assert_allclose(req[column], max_version[column])


@mark.parametrize("version", (0, 1, 2))
Expand Down

0 comments on commit 21ed856

Please sign in to comment.