Skip to content
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

Add test coverage for the oldest supported Ruff version #270

Merged
merged 17 commits into from
Oct 11, 2023
Merged

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Oct 10, 2023

Adds test coverage for the oldest supported Ruff version by adding the Ruff version to the CI test matrix.

The Ruff versions in the matrix are generated by parsing the lower pin from our pyproject.toml and the latest release from GitHub. I opted for this approach because it's nice to see the version being tested in the CI job names and it does not require manual updates.

The just check job was split out from tests because it requires ruff format which is not available in old releases.

The tests did not pass on the old release of Ruff due missing format support and the new documentation domain. I've added toggles in the test to address those cases based on the Ruff version being tested.

Motivated by a desire for test coverage in #266

.github/workflows/ci.yaml Outdated Show resolved Hide resolved
@zanieb zanieb changed the title Add the latest and oldest Ruff versions to the CI test matrix Add test coverage for the oldest supported Ruff version Oct 10, 2023
| cut -c2- \
)
# Get the oldest supported version from the pyproject.toml
OLDEST=$(rg -No '"ruff>=(.*)"' -r '$1' pyproject.toml)
Copy link
Member Author

Choose a reason for hiding this comment

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

It's way more painful to extract the first matching group like this without ripgrep, afaict

Copy link
Member

Choose a reason for hiding this comment

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

I would honestly be fine hard-coding this and the latest version, since we already search-and-replace the latest version every time we upgrade the LSP. Fewer dependencies, easier to maintain (IMO). But of course I defer to you.

Copy link
Member

Choose a reason for hiding this comment

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

sed -rn 's/.*"ruff>=(.*).*",/\1/p' pyproject.toml works

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe it's just me but a sed invocation like that is entirely incomprehensible haha :)

I'd like to try this out since I wrote it up and haven't tried generating matrix test versions like this before, but at the first sign of trouble I'm happy to just switch to hard-coded versions.

Comment on lines +66 to +70
exclude:
- os: windows-latest
ruff-version: ${{ needs.ruff-versions.outputs.oldest }}
- os: macos-latest
ruff-version: ${{ needs.ruff-versions.outputs.oldest }}
Copy link
Member Author

Choose a reason for hiding this comment

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

It seemed overkill to include these in the matrix — it was a lot of testing

Copy link
Member

Choose a reason for hiding this comment

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

To me, lowest and highest python versions would be sufficient in general

Comment on lines -20 to +23
class TestServer(unittest.TestCase):
class TestServer:
Copy link
Member Author

Choose a reason for hiding this comment

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

I need the pytest fixture to be accessible here

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd like to follow-up with a pull request that removes the class, but want to keep the diff focused here.

@zanieb zanieb marked this pull request as ready for review October 10, 2023 16:01
@@ -149,7 +164,7 @@ def _handler(params):
{
"code": "F401",
"codeDescription": {
"href": "https://docs.astral.sh/ruff/rules/unused-import"
"href": expected_docs_url + "rules/unused-import"
Copy link
Member

Choose a reason for hiding this comment

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

I wish we could just store "fixtures by version" or something, rather than having to construct these and encode facts like "Which URL is present at which version?" in the test logic. Like, in Rust, we'd just run the command with different versions and snapshot the output, which feels easier to maintain and understand. I don't know if I have a concrete suggestion here -- more reacting to the increased logic in the tests now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm interesting yeah.. this whole bit would make more sense as a snapshot too.

A strong case for us building Python test tooling <3

| cut -c2- \
)
# Get the oldest supported version from the pyproject.toml
OLDEST=$(rg -No '"ruff>=(.*)"' -r '$1' pyproject.toml)
Copy link
Member

Choose a reason for hiding this comment

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

I would honestly be fine hard-coding this and the latest version, since we already search-and-replace the latest version every time we upgrade the LSP. Fewer dependencies, easier to maintain (IMO). But of course I defer to you.

| cut -c2- \
)
# Get the oldest supported version from the pyproject.toml
OLDEST=$(rg -No '"ruff>=(.*)"' -r '$1' pyproject.toml)
Copy link
Member

Choose a reason for hiding this comment

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

sed -rn 's/.*"ruff>=(.*).*",/\1/p' pyproject.toml works

Comment on lines +66 to +70
exclude:
- os: windows-latest
ruff-version: ${{ needs.ruff-versions.outputs.oldest }}
- os: macos-latest
ruff-version: ${{ needs.ruff-versions.outputs.oldest }}
Copy link
Member

Choose a reason for hiding this comment

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

To me, lowest and highest python versions would be sufficient in general

@zanieb zanieb merged commit 36c64f4 into main Oct 11, 2023
26 checks passed
@zanieb zanieb deleted the ruff-matrix-ci branch October 11, 2023 16:34
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.

None yet

3 participants