Skip to content

Improve test comments under @pytest.mark.parametrize in test_diffraction_objects.py - #273

Merged
sbillinge merged 8 commits into
diffpy:mainfrom
bobleesj:pytest-reformat
Dec 25, 2024
Merged

Improve test comments under @pytest.mark.parametrize in test_diffraction_objects.py#273
sbillinge merged 8 commits into
diffpy:mainfrom
bobleesj:pytest-reformat

Conversation

@bobleesj

@bobleesjbobleesj commented Dec 23, 2024

Copy link
Copy Markdown
Contributor

Some battle-tested practices being adopted:

  • Replace UC to C
  • Add higher-level test function comment before starting "C"
  • Use "x, y, z (provided), expect blah blah blah" format for consistency

cc' @yucongalicechen

@codecov

codecovBot commented Dec 23, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.68%. Comparing base (8107874) to head (499a1c3).
Report is 15 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #273 +/- ##
=======================================
Coverage 98.68% 98.68% =======================================
Files 8 8 Lines 379 379 =======================================
Hits 374 374 Misses 5 5 
Files with missing linesCoverage Δ
tests/test_diffraction_objects.py100.00% <100.00%> (ø)

@bobleesj

Copy link
Copy Markdown
ContributorAuthor

@sbillinge ready for review.

@yucongalicechen , the part that is remaining is the test_scale_to function.

The existing comments like# C2: Same length x-arrays with exact x-value match, # C3: Same length x-arrays with approximate x-value match were abit hard for me to understand what's being tested. Would you mind improving this test comments for test_scale_to using the above format?

@bobleesj

Copy link
Copy Markdown
ContributorAuthor

(Just added a quick fix) pls see my comments right above

@sbillingesbillinge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please see my comment. I guess this may not be liked by one of our linters or something, but I think I prefer the more compact formatting. Not a huge deal though. Let's just decide which we like and adopt it in future. It is such a small point we don't need to redo things here. Let's dicsus it. But I will merge this.

(4 * np.pi, np.array([0.25, 0.5, 0.71]), np.array([1, 2, 3]), "q", "q", 0.1, [0]),
(4 * np.pi, np.array([30, 60]), np.array([1, 2]), "tth", "tth", 63, [1]),
# Test get_array_index() returns the expected index given xtype and value
# C1: Target value is in the xarray and xtype is identical, expect exact index match

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's not modify this PR again, but I do wonder whether it would be more compact as

 ( # C1: Target value is in the xarray and xtype is identical, expect exact index match
{
"wavelength": 4 * np.pi,
"xarray": np.array([30.005, 60]),
"yarray": np.array([1, 2]),
"xtype": "tth",
},
{
"xtype": "tth",
"value": 30.005,
},
[0],
),

than the current

 # C1: Target value is in the xarray and xtype is identical, expect exact index match
(
{
"wavelength": 4 * np.pi,
"xarray": np.array([30.005, 60]),
"yarray": np.array([1, 2]),
"xtype": "tth",
},
{
"xtype": "tth",
"value": 30.005,
},
[0],
),

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Screenshot 2024-12-25 at 10 07 41 AM

@sbillinge yeah I like that! The automatic indentation also provides a good visual hierarchy!

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Screenshot 2024-12-25 at 10 11 26 AM

For single-lined cases, I think we still want to maintain this format right?

Sign up for freeto 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

@bobleesj@sbillinge