From f9921fbda8c3e6f38137869a4ec77bf72adbab44 Mon Sep 17 00:00:00 2001 From: Jared Lewis Date: Wed, 20 Nov 2024 19:12:13 +1100 Subject: [PATCH] test: Fix up tests --- packages/ref/tests/unit/cli/test_ingest.py | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/ref/tests/unit/cli/test_ingest.py b/packages/ref/tests/unit/cli/test_ingest.py index b34e4ab..604197e 100644 --- a/packages/ref/tests/unit/cli/test_ingest.py +++ b/packages/ref/tests/unit/cli/test_ingest.py @@ -50,37 +50,43 @@ def test_ingest_help(): class TestIngest: + data_dir = Path("CMIP6") / "ScenarioMIP" / "CSIRO" / "ACCESS-ESM1-5" / "ssp126" / "r1i1p1f1" + def test_ingest(self, esgf_data_dir, db): - result = runner.invoke(app, ["ingest", str(esgf_data_dir), "--source-type", "cmip6"]) + result = runner.invoke(app, ["ingest", str(esgf_data_dir / self.data_dir), "--source-type", "cmip6"]) assert result.exit_code == 0, result.output - assert db.session.query(Dataset).count() == 7 - assert db.session.query(CMIP6Dataset).count() == 7 - assert db.session.query(CMIP6File).count() == 11 + assert db.session.query(Dataset).count() == 5 + assert db.session.query(CMIP6Dataset).count() == 5 + assert db.session.query(CMIP6File).count() == 9 def test_ingest_and_solve(self, esgf_data_dir, db): result = runner.invoke(app, ["ingest", str(esgf_data_dir), "--source-type", "cmip6", "--solve"]) assert result.exit_code == 0, result.output assert "Solving for metrics that require recalculation." in result.output - def test_ingest_twice(self, esgf_data_dir, db): + def test_ingest_multiple_times(self, esgf_data_dir, db): + result = runner.invoke( + app, ["ingest", str(esgf_data_dir / self.data_dir / "Amon" / "tas"), "--source-type", "cmip6"] + ) + assert result.exit_code == 0, result.output + + assert db.session.query(Dataset).count() == 1 + assert db.session.query(CMIP6File).count() == 2 + result = runner.invoke( - app, ["ingest", str(esgf_data_dir / "CMIP6" / "ScenarioMIP"), "--source-type", "cmip6"] + app, ["ingest", str(esgf_data_dir / self.data_dir / "Amon" / "tas"), "--source-type", "cmip6"] ) assert result.exit_code == 0, result.output - assert db.session.query(Dataset).count() == 6 - assert db.session.query(CMIP6Dataset).count() == 6 - assert db.session.query(CMIP6File).count() == 10 + assert db.session.query(Dataset).count() == 1 result = runner.invoke( - app, ["ingest", str(esgf_data_dir / "CMIP6" / "ScenarioMIP"), "--source-type", "cmip6"] + app, ["ingest", str(esgf_data_dir / self.data_dir / "Amon" / "rsut"), "--source-type", "cmip6"] ) assert result.exit_code == 0, result.output - assert db.session.query(Dataset).count() == 6 - assert db.session.query(CMIP6Dataset).count() == 6 - assert db.session.query(CMIP6File).count() == 10 + assert db.session.query(Dataset).count() == 2 def test_ingest_missing(self, esgf_data_dir, db): result = runner.invoke(app, ["ingest", str(esgf_data_dir / "missing"), "--source-type", "cmip6"])