Skip to content

Continue refactor test functions, replace UC to C in test_transforms.py #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 22, 2024

Conversation

bobleesj
Copy link
Contributor

No description provided.

Copy link

codecov bot commented Dec 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (ce6c9cc) to head (17c87f0).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #266   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         8           
  Lines          404       402    -2     
=========================================
- Hits           404       402    -2     
Files with missing lines Coverage Δ
tests/test_diffraction_objects.py 100.00% <100.00%> (ø)
tests/test_transforms.py 100.00% <ø> (ø)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the group, do we want to call it "C" instead of "Case"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think either can work

(
None,
np.array([0, 30, 60, 90, 120, 180]),
np.array([0, 1, 2, 3, 4, 5]),
),
# UC3: user specified valid tth values between 0-180 degrees (with wavelength)
# C3: valid tth values between 0-180 degrees (with wavelength)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to call it UC right? Since this is testing actual_q = tth_to_q(tth, wavelength)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We basically never want to see UCs in tests. UCs are enumerated lists of actions that describe user behavior when using an app.

@@ -94,14 +96,14 @@ def test_tth_to_q(wavelength, tth, expected_q, wavelength_warning_msg):
@pytest.mark.parametrize(
"wavelength, tth, expected_error_type, expected_error_msg",
[
# UC0: user specified an invalid tth value of > 180 degrees (without wavelength)
# C1: invalid tth value of > 180 degrees, no wavelength, expect two theta ValueError
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above - testing tth_to_q(tth, wavelength)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, no UC

@@ -171,13 +173,13 @@ def test_d_to_q(d, expected_q, zero_divide_error_expected):
"wavelength, tth, expected_d, divide_by_zero_warning_expected",
[
# Test conversion of q to d with valid values
# Case 1: empty tth values, no, expect empty d values
# C1: empty tth values, no, expect empty d values
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment - testing tth_to_d

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either is fine

)


params_index = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just moving params_index under @pytest.mark.parametrize

@@ -406,7 +411,7 @@ def test_dump(tmp_path, mocker):
@pytest.mark.parametrize(
"do_init_args, expected_do_dict, divide_by_zero_warning_expected",
[
( # instantiate just array attributes
( # Instantiate just array attributes
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick PEP8 standard, starting each comment with a cap letter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's use that convention. For the test cases I don't mind if they are full sentences or not tbh as long as the intent is clear.

# 2. Empty q values, wavelength specified, return empty arrays
# Test conversion of q to tth with valid values
# C1: Allow empty array q to compute tth with or without wavelength
# 1. Wavelength provided, expect empty array of tth
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the word expect is better than return since expect can be used for warnings too.

Would you have any further feedback on this refactored version?

Copy link
Contributor Author

@bobleesj bobleesj Dec 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flow is like..

"The overall goal is toTest conversion of q to tth with valid values. For the first case, we want to see if it Allows empty array q to compute tth with or without wavelength. Then, for the first case of Wavelength provided, expect empty array of tth. For the second case of No wavelength provided, still expect an empty tth but hey you will also get a warning!"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your version looks great here
Very clear

@bobleesj
Copy link
Contributor Author

@sbillinge ready for review

Copy link
Contributor

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see inline. It looks great. I will go ahead and merge.

@pytest.mark.parametrize(
"org_do_args, target_do_args, scale_inputs",
[
# UC1: User did not specify anything
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UC -> C. Also these comments don't seem to correspond to the tests. Not sure what is going on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I read above... You will do these on separate PRs, sorry!

(
None,
np.array([0, 30, 60, 90, 120, 180]),
np.array([0, 1, 2, 3, 4, 5]),
),
# UC3: user specified valid tth values between 0-180 degrees (with wavelength)
# C3: valid tth values between 0-180 degrees (with wavelength)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We basically never want to see UCs in tests. UCs are enumerated lists of actions that describe user behavior when using an app.

@@ -94,14 +96,14 @@ def test_tth_to_q(wavelength, tth, expected_q, wavelength_warning_msg):
@pytest.mark.parametrize(
"wavelength, tth, expected_error_type, expected_error_msg",
[
# UC0: user specified an invalid tth value of > 180 degrees (without wavelength)
# C1: invalid tth value of > 180 degrees, no wavelength, expect two theta ValueError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, no UC

@@ -171,13 +173,13 @@ def test_d_to_q(d, expected_q, zero_divide_error_expected):
"wavelength, tth, expected_d, divide_by_zero_warning_expected",
[
# Test conversion of q to d with valid values
# Case 1: empty tth values, no, expect empty d values
# C1: empty tth values, no, expect empty d values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either is fine

@@ -406,7 +411,7 @@ def test_dump(tmp_path, mocker):
@pytest.mark.parametrize(
"do_init_args, expected_do_dict, divide_by_zero_warning_expected",
[
( # instantiate just array attributes
( # Instantiate just array attributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's use that convention. For the test cases I don't mind if they are full sentences or not tbh as long as the intent is clear.

# 2. Empty q values, wavelength specified, return empty arrays
# Test conversion of q to tth with valid values
# C1: Allow empty array q to compute tth with or without wavelength
# 1. Wavelength provided, expect empty array of tth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your version looks great here
Very clear

@sbillinge sbillinge merged commit c67fec3 into diffpy:main Dec 22, 2024
5 checks passed
@bobleesj
Copy link
Contributor Author

bobleesj commented Dec 22, 2024

Yes, let's use that convention. For the test cases I don't mind if they are full sentences or not tbh as long as the intent is clear.

Right, method docstring also doesn't have to start with a complete "noun-verb" sentences anyway.. so i agree.

@bobleesj bobleesj deleted the runtime-warning branch December 22, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants