Skip to content

Conversation

@11happy
Copy link
Contributor

@11happy 11happy commented Oct 16, 2025

Summary

This PR refactors semantic error tests in each seperate file

Test Plan

CC

@11happy 11happy marked this pull request as draft October 16, 2025 18:36
@ntBre ntBre added the internal An internal refactor or improvement label Oct 16, 2025
@ntBre
Copy link
Contributor

ntBre commented Oct 16, 2025

Nice, thanks for working on this! Let me know when it's ready for review, or if you need any help. It looks like you're on the right track :)

@11happy 11happy marked this pull request as ready for review October 22, 2025 15:45
@11happy
Copy link
Contributor Author

11happy commented Oct 22, 2025

CI is green : ) , its ready for review.

Thank you

@github-actions
Copy link
Contributor

github-actions bot commented Oct 22, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thank you! I had a few small nits, but this looks great. I think this will make these tests a lot easier to work with.

..Default::default()
},
);
insta::with_settings!({filters => vec![(r"\\", "/")]}, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this filter? It looks like we use test_contents_syntax_errors in other tests in this file without the filter, so it would probably be okay to omit it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

},
);
insta::with_settings!({filters => vec![(r"\\", "/")]}, {
assert_diagnostics!(format!("{snapshot}_{python_version}"), diagnostics);
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we're adding the Python version twice, once here and once above on line 1033.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

let contents = std::fs::read_to_string(&path)?;
let source_kind = SourceKind::Python(contents);
for &python_version in python_versions {
let snapshot = format!("semantic_syntax_error_{error_type}_{python_version}");
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 we could probably omit the error_type and just use the path instead. That seems closer to what we do for lint rules, and it will make the test_case entries a bit shorter.

Looking back at the blame, I'm actually not sure why we added error_type in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

path is causing windows test to fail .

PythonVersion::PY312,
"InvalidExpression"
Path::new("global_parameter.py"),
&[PythonVersion::PY312],
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like most of these only have one Python version, so I'd probably just pass a single Python version, like we had before. And then we can duplicate the test_case like:

#[test_case(Path::new("some_file.py"), PythonVersion::PY311)]
#[test_case(Path::new("some_file.py"), PythonVersion::PY312)]

I think that looks a bit neater.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ntBre ntBre added the testing Related to testing Ruff itself label Oct 22, 2025
@AlexWaygood AlexWaygood changed the title [semantic error tests]: refactor semantic error tests to seperate files [semantic error tests]: refactor semantic error tests to separate files Oct 27, 2025
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thank you! I had a handful of additional naming/version nits, but I think this is good to go otherwise.

@ntBre ntBre enabled auto-merge (squash) October 27, 2025 21:14
@ntBre ntBre merged commit 7fee62b into astral-sh:main Oct 27, 2025
36 checks passed
dcreager added a commit that referenced this pull request Oct 28, 2025
…l-constraint-sets

* dcreager/refactor-constraint-mdtests: (60 commits)
  add static_asserts
  move all reveal diagnostics to separate line
  add more gradual tests
  better comment
  restructure a bit
  better names/comments
  simplify before implication
  two typevars!
  mdformat
  rename mdtest
  move is_subtype_of_given into ConstraintSet
  move where we grab these
  add ConstraintSet.{always,never}
  move range_constraint into ConstraintSet class
  [ty] Rename `inner` query for better debugging experience (#21106)
  [ty] Add new "constraint implication" typing relation (#21010)
  [semantic error tests]: refactor semantic error tests to separate files (#20926)
  Respect `--output-format` with `--watch` (#21097)
  [`pyflakes`] Revert to stable behavior if imports for module lie in alternate branches for `F401` (#20878)
  Fix finding keyword range for clause header after statement ending with semicolon (#21067)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement testing Related to testing Ruff itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants