From c0ffe30876f8702faa1acdeff0457013224df89c Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Tue, 17 Sep 2024 20:26:44 -0400 Subject: [PATCH 01/12] Empty build.txt file which is used for C++/C --- requirements/build.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/requirements/build.txt b/requirements/build.txt index f72d870..e69de29 100644 --- a/requirements/build.txt +++ b/requirements/build.txt @@ -1,2 +0,0 @@ -python -setuptools From 3e8dd2348b73887f6604befdeecd9c46ca1ee20b Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Tue, 17 Sep 2024 20:32:27 -0400 Subject: [PATCH 02/12] Fix arb value to fix warning --- tests/test_diffraction_objects.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index fa613a5..a410f31 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -236,18 +236,20 @@ def test_dump(tmp_path, mocker): directory = Path(tmp_path) file = directory / "testfile" test = Diffraction_object() - test.wavelength = 1.54 + test.wavelength = 1.01 test.name = "test" test.scat_quantity = "x-ray" test.insert_scattering_quantity( x, y, "q", metadata={"thing1": 1, "thing2": "thing2", "package_info": {"package2": "3.4.5"}} ) + + with mocker.patch("importlib.metadata.version", return_value="3.3.0"), freeze_time("2012-01-14"): test.dump(file, "q") with open(file, "r") as f: actual = f.read() expected = ( - "[Diffraction_object]\nname = test\nwavelength = 1.54\nscat_quantity = x-ray\nthing1 = 1\n" + "[Diffraction_object]\nname = test\nwavelength = 1.01\nscat_quantity = x-ray\nthing1 = 1\n" "thing2 = thing2\npackage_info = {'package2': '3.4.5', 'diffpy.utils': '3.3.0'}\n" "creation_time = 2012-01-14 00:00:00\n\n" "#### start data\n0.000000000000000000e+00 0.000000000000000000e+00\n" @@ -262,4 +264,5 @@ def test_dump(tmp_path, mocker): "9.000000000000000000e+00 9.000000000000000000e+00\n" "1.000000000000000000e+01 1.000000000000000000e+01\n" ) + assert actual == expected From b62fddb46ce88d11814a78e9bb75a022ca8ece52 Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Tue, 17 Sep 2024 20:42:18 -0400 Subject: [PATCH 03/12] Remove patch warning --- tests/test_diffraction_objects.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index a410f31..21b6c66 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -243,9 +243,10 @@ def test_dump(tmp_path, mocker): x, y, "q", metadata={"thing1": 1, "thing2": "thing2", "package_info": {"package2": "3.4.5"}} ) - - with mocker.patch("importlib.metadata.version", return_value="3.3.0"), freeze_time("2012-01-14"): + mocker.patch("importlib.metadata.version", return_value="3.3.0") + with freeze_time("2012-01-14"): test.dump(file, "q") + with open(file, "r") as f: actual = f.read() expected = ( From 6e2ed38c9f8e3e760fbaf5957dfddbd3027e95ec Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Tue, 17 Sep 2024 20:43:51 -0400 Subject: [PATCH 04/12] Add news --- news/warning.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/warning.rst diff --git a/news/warning.rst b/news/warning.rst new file mode 100644 index 0000000..4576880 --- /dev/null +++ b/news/warning.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Two Pytest warnings due to numpy and pytest mocker in test_dump function + +**Security:** + +* From de82a7705e207a16e90639abe75e21adf172676d Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Thu, 19 Sep 2024 07:16:27 -0400 Subject: [PATCH 05/12] Clean up tests for catching error --- tests/test_diffraction_objects.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index 8958c17..aa99326 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -241,21 +241,28 @@ def test_dump(tmp_path, mocker): test.name = "test" test.scat_quantity = "x-ray" - # Capture warnings due to invalid arcsin input value due to the wavelenght being 1.54 + # Setup the testing environment to capture warnings triggered by an invalid arcsin input with warnings.catch_warnings(record=True) as captured_warnings: + # Configure the warnings system to capture all warnings warnings.simplefilter("always") + + # Perform the method call that is expected to trigger the RuntimeWarning due to the specified wavelength test.insert_scattering_quantity( x, y, "q", metadata={"thing1": 1, "thing2": "thing2", "package_info": {"package2": "3.4.5"}} ) - # Assert that a RuntimeWarning was raised + # Verify that at least one RuntimeWarning is raised due to the arcsin domain error from wavelength 1.54 assert any( isinstance(w.message, RuntimeWarning) for w in captured_warnings - ), "Expected a RuntimeWarning due to invalid arcsin input value from the wavelenght set to 1.54" - # Expect only one warning message produced - assert len(captured_warnings) == 1 + ), "Expected a RuntimeWarning due to invalid arcsin input value from the wavelength set to 1.54" + + # Ensure that exactly one warning was captured to confirm that no additional unexpected warnings are raised + assert len(captured_warnings) == 1, "Expected exactly one warning to be captured" + + # Patch the version lookup to control the external dependency in the test environment mocker.patch("importlib.metadata.version", return_value="3.3.0") + with freeze_time("2012-01-14"): test.dump(file, "q") From d65aa57402cb4114c896e50d835b3497cc875756 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:16:37 +0000 Subject: [PATCH 06/12] [pre-commit.ci] auto fixes from pre-commit hooks --- tests/test_diffraction_objects.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index aa99326..7a32b3b 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -262,7 +262,6 @@ def test_dump(tmp_path, mocker): # Patch the version lookup to control the external dependency in the test environment mocker.patch("importlib.metadata.version", return_value="3.3.0") - with freeze_time("2012-01-14"): test.dump(file, "q") From b9b05a505f06f00ee12638cc4b5fb6ae974ef371 Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Thu, 19 Sep 2024 07:18:51 -0400 Subject: [PATCH 07/12] Shorten comments for test_diffraction_objects --- tests/test_diffraction_objects.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index 7a32b3b..9e3abe3 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -241,7 +241,6 @@ def test_dump(tmp_path, mocker): test.name = "test" test.scat_quantity = "x-ray" - # Setup the testing environment to capture warnings triggered by an invalid arcsin input with warnings.catch_warnings(record=True) as captured_warnings: # Configure the warnings system to capture all warnings warnings.simplefilter("always") @@ -251,15 +250,14 @@ def test_dump(tmp_path, mocker): x, y, "q", metadata={"thing1": 1, "thing2": "thing2", "package_info": {"package2": "3.4.5"}} ) - # Verify that at least one RuntimeWarning is raised due to the arcsin domain error from wavelength 1.54 + # Verify that at least one RuntimeWarning is raised due to the arcsin error from wavelength 1.54 assert any( isinstance(w.message, RuntimeWarning) for w in captured_warnings ), "Expected a RuntimeWarning due to invalid arcsin input value from the wavelength set to 1.54" - # Ensure that exactly one warning was captured to confirm that no additional unexpected warnings are raised + # Ensure that exactly one warning was captured assert len(captured_warnings) == 1, "Expected exactly one warning to be captured" - # Patch the version lookup to control the external dependency in the test environment mocker.patch("importlib.metadata.version", return_value="3.3.0") with freeze_time("2012-01-14"): From 31f3c03b25e01341fc351deede00f368b6de3276 Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Fri, 25 Oct 2024 10:59:14 -0400 Subject: [PATCH 08/12] Setup requirements --- requirements/{run.txt => conda.txt} | 0 requirements/pip.txt | 1 + 2 files changed, 1 insertion(+) rename requirements/{run.txt => conda.txt} (100%) diff --git a/requirements/run.txt b/requirements/conda.txt similarity index 100% rename from requirements/run.txt rename to requirements/conda.txt diff --git a/requirements/pip.txt b/requirements/pip.txt index e69de29..24ce15a 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -0,0 +1 @@ +numpy From e69255afb24f01902f547bf3c38ef0bcb2b2a3cc Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Fri, 25 Oct 2024 10:59:39 -0400 Subject: [PATCH 09/12] Set valid q range for test dump function --- tests/test_diffraction_objects.py | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index 9e3abe3..8798930 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -233,31 +233,17 @@ def test_diffraction_objects_equality(inputs1, inputs2, expected): def test_dump(tmp_path, mocker): - x, y = np.linspace(0, 10, 11), np.linspace(0, 10, 11) + x, y = np.linspace(0, 5, 6), np.linspace(0, 5, 6) directory = Path(tmp_path) file = directory / "testfile" test = Diffraction_object() test.wavelength = 1.54 test.name = "test" test.scat_quantity = "x-ray" - - with warnings.catch_warnings(record=True) as captured_warnings: - # Configure the warnings system to capture all warnings - warnings.simplefilter("always") - - # Perform the method call that is expected to trigger the RuntimeWarning due to the specified wavelength - test.insert_scattering_quantity( + test.insert_scattering_quantity( x, y, "q", metadata={"thing1": 1, "thing2": "thing2", "package_info": {"package2": "3.4.5"}} - ) - - # Verify that at least one RuntimeWarning is raised due to the arcsin error from wavelength 1.54 - assert any( - isinstance(w.message, RuntimeWarning) for w in captured_warnings - ), "Expected a RuntimeWarning due to invalid arcsin input value from the wavelength set to 1.54" - - # Ensure that exactly one warning was captured - assert len(captured_warnings) == 1, "Expected exactly one warning to be captured" - + ) + mocker.patch("importlib.metadata.version", return_value="3.3.0") with freeze_time("2012-01-14"): @@ -275,11 +261,6 @@ def test_dump(tmp_path, mocker): "3.000000000000000000e+00 3.000000000000000000e+00\n" "4.000000000000000000e+00 4.000000000000000000e+00\n" "5.000000000000000000e+00 5.000000000000000000e+00\n" - "6.000000000000000000e+00 6.000000000000000000e+00\n" - "7.000000000000000000e+00 7.000000000000000000e+00\n" - "8.000000000000000000e+00 8.000000000000000000e+00\n" - "9.000000000000000000e+00 9.000000000000000000e+00\n" - "1.000000000000000000e+01 1.000000000000000000e+01\n" ) assert actual == expected From 7b12bafda78914961df782289ec92d689f3f17f0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:01:46 +0000 Subject: [PATCH 10/12] [pre-commit.ci] auto fixes from pre-commit hooks --- tests/test_diffraction_objects.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index 8798930..5658b9b 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -241,9 +241,9 @@ def test_dump(tmp_path, mocker): test.name = "test" test.scat_quantity = "x-ray" test.insert_scattering_quantity( - x, y, "q", metadata={"thing1": 1, "thing2": "thing2", "package_info": {"package2": "3.4.5"}} + x, y, "q", metadata={"thing1": 1, "thing2": "thing2", "package_info": {"package2": "3.4.5"}} ) - + mocker.patch("importlib.metadata.version", return_value="3.3.0") with freeze_time("2012-01-14"): From 0cb34e28641b44ae21826fa79a6e09faccac3e05 Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Fri, 25 Oct 2024 11:06:36 -0400 Subject: [PATCH 11/12] Pre-commit --- tests/test_diffraction_objects.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index 8798930..b558138 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -1,4 +1,3 @@ -import warnings from pathlib import Path import numpy as np From 859755e6b57c75a7b96bc3f750795fc7230e94d6 Mon Sep 17 00:00:00 2001 From: Sangjoon Bob Lee Date: Fri, 25 Oct 2024 11:07:08 -0400 Subject: [PATCH 12/12] Apply pre-commit --- tests/test_diffraction_objects.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index b558138..a155b95 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -240,9 +240,9 @@ def test_dump(tmp_path, mocker): test.name = "test" test.scat_quantity = "x-ray" test.insert_scattering_quantity( - x, y, "q", metadata={"thing1": 1, "thing2": "thing2", "package_info": {"package2": "3.4.5"}} + x, y, "q", metadata={"thing1": 1, "thing2": "thing2", "package_info": {"package2": "3.4.5"}} ) - + mocker.patch("importlib.metadata.version", return_value="3.3.0") with freeze_time("2012-01-14"):