From eac7dbe6c43a9b32ebf41151538b7226087d9271 Mon Sep 17 00:00:00 2001 From: Dazhong Xia Date: Mon, 13 Nov 2023 12:32:34 -0800 Subject: [PATCH 1/2] Always use tmp path for clobber tests. --- test/unit/extract/xbrl_test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/unit/extract/xbrl_test.py b/test/unit/extract/xbrl_test.py index 0aeb2a920d..bb08e4081b 100644 --- a/test/unit/extract/xbrl_test.py +++ b/test/unit/extract/xbrl_test.py @@ -163,7 +163,7 @@ def test_xbrl2sqlite_db_exists_no_clobber(mocker): xbrl2sqlite(context) -def test_xbrl2sqlite_db_exists_yes_clobber(mocker): +def test_xbrl2sqlite_db_exists_yes_clobber(mocker, tmp_path): convert_form_mock = mocker.MagicMock() mocker.patch("pudl.extract.xbrl.convert_form", new=convert_form_mock) @@ -171,7 +171,8 @@ def test_xbrl2sqlite_db_exists_yes_clobber(mocker): mock_datastore = mocker.MagicMock() mocker.patch("pudl.extract.xbrl.FercXbrlDatastore", return_value=mock_datastore) - ferc1_sqlite_path = PudlPaths().output_dir / "ferc1_xbrl.sqlite" + # always use tmp path here so that we don't clobber the live DB when --live-dbs is passed + ferc1_sqlite_path = tmp_path / "ferc1_xbrl.sqlite" ferc1_sqlite_path.touch() # mock the db path so we can assert it gets clobbered From 3c6c93f4fc26b3519d950003cc6af7413fe928ea Mon Sep 17 00:00:00 2001 From: Dazhong Xia Date: Mon, 13 Nov 2023 14:28:55 -0800 Subject: [PATCH 2/2] Also use tmp path in test_xbrl2sqlite --- test/unit/extract/xbrl_test.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/unit/extract/xbrl_test.py b/test/unit/extract/xbrl_test.py index bb08e4081b..61ff1bdb07 100644 --- a/test/unit/extract/xbrl_test.py +++ b/test/unit/extract/xbrl_test.py @@ -91,7 +91,7 @@ def test_ferc_xbrl_datastore_get_filings(mocker): ), ], ) -def test_xbrl2sqlite(settings, forms, mocker): +def test_xbrl2sqlite(settings, forms, mocker, tmp_path): convert_form_mock = mocker.MagicMock() mocker.patch("pudl.extract.xbrl.convert_form", new=convert_form_mock) @@ -99,6 +99,14 @@ def test_xbrl2sqlite(settings, forms, mocker): mock_datastore = mocker.MagicMock() mocker.patch("pudl.extract.xbrl.FercXbrlDatastore", return_value=mock_datastore) + # always use tmp path here so that we don't clobber the live DB when --live-dbs is passed + mock_pudl_paths = mocker.MagicMock( + spec=PudlPaths(), + sqlite_db_path=lambda form_name: tmp_path / f"{form_name}.sqlite", + output_dir=PudlPaths().output_dir, + ) + mocker.patch("pudl.extract.xbrl.PudlPaths", return_value=mock_pudl_paths) + # Construct xbrl2sqlite op context context = build_op_context( resources={ @@ -122,7 +130,7 @@ def test_xbrl2sqlite(settings, forms, mocker): form, mock_datastore, output_path=PudlPaths().output_dir, - sql_path=PudlPaths().output_dir / f"ferc{form.value}_xbrl.sqlite", + sql_path=tmp_path / f"ferc{form.value}_xbrl.sqlite", batch_size=20, workers=10, )