Skip to content

Commit

Permalink
Use latest Python version by default in tests (#6448)
Browse files Browse the repository at this point in the history
## Summary

Use the same Python version by default for all tests (our
latest-supported version).

## Test Plan

`cargo test`

---------

Co-authored-by: Zanie <[email protected]>
  • Loading branch information
charliermarsh and zanieb authored Aug 9, 2023
1 parent 38b9fb8 commit 6acf07c
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 32 deletions.
6 changes: 2 additions & 4 deletions crates/ruff/src/rules/flake8_bugbear/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ mod tests {

use crate::assert_messages;
use crate::registry::Rule;
use crate::settings::types::PythonVersion;
use crate::settings::Settings;
use crate::test::test_path;

Expand Down Expand Up @@ -65,8 +64,7 @@ mod tests {
let snapshot = "B905.py";
let diagnostics = test_path(
Path::new("flake8_bugbear").join(snapshot).as_path(),
&Settings::for_rule(Rule::ZipWithoutExplicitStrict)
.with_target_version(PythonVersion::latest()),
&Settings::for_rule(Rule::ZipWithoutExplicitStrict),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
Expand All @@ -84,7 +82,7 @@ mod tests {
"fastapi.Query".to_string(),
],
},
..Settings::for_rules(vec![Rule::FunctionCallInDefaultArgument])
..Settings::for_rule(Rule::FunctionCallInDefaultArgument)
},
)?;
assert_messages!(snapshot, diagnostics);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
---
source: crates/ruff/src/rules/flake8_pyi/mod.rs
---
PYI050.py:13:24: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
|
13 | def foo_no_return(arg: NoReturn):
| ^^^^^^^^ PYI050
14 | ...
|

PYI050.py:23:44: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
|
23 | def foo_no_return_kwarg(arg: int, *, arg2: NoReturn):
| ^^^^^^^^ PYI050
24 | ...
|

PYI050.py:27:47: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
|
27 | def foo_no_return_pos_only(arg: int, /, arg2: NoReturn):
| ^^^^^^^^ PYI050
28 | ...
|


Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/ruff/src/rules/flake8_pyi/mod.rs
---
PYI050.pyi:6:24: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for argument annotations
PYI050.pyi:6:24: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
|
4 | def foo(arg): ...
5 | def foo_int(arg: int): ...
Expand All @@ -11,7 +11,7 @@ PYI050.pyi:6:24: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for arg
8 | arg: typing_extensions.NoReturn,
|

PYI050.pyi:10:44: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for argument annotations
PYI050.pyi:10:44: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
|
8 | arg: typing_extensions.NoReturn,
9 | ): ... # Error: PYI050
Expand All @@ -21,7 +21,7 @@ PYI050.pyi:10:44: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for ar
12 | def foo_never(arg: Never): ...
|

PYI050.pyi:11:47: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for argument annotations
PYI050.pyi:11:47: PYI050 Prefer `typing.Never` over `NoReturn` for argument annotations
|
9 | ): ... # Error: PYI050
10 | def foo_no_return_kwarg(arg: int, *, arg2: NoReturn): ... # Error: PYI050
Expand Down
6 changes: 2 additions & 4 deletions crates/ruff/src/rules/flake8_use_pathlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod tests {
use crate::assert_messages;
use crate::registry::Rule;
use crate::settings;
use crate::settings::types::PythonVersion;
use crate::test::test_path;

#[test_case(Path::new("full_name.py"))]
Expand Down Expand Up @@ -49,8 +48,7 @@ mod tests {
Rule::OsPathSamefile,
Rule::OsPathSplitext,
Rule::BuiltinOpen,
])
.with_target_version(PythonVersion::latest()),
]),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
Expand All @@ -69,7 +67,7 @@ mod tests {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("flake8_use_pathlib").join(path).as_path(),
&settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
&settings::Settings::for_rule(rule_code),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ if_elif_else.py:6:1: I001 [*] Import block is un-sorted or un-formatted
3 3 | elif "setuptools" in sys.modules:
4 4 | from setuptools.command.sdist import sdist as _sdist
5 5 | else:
6 |- from setuptools.command.sdist import sdist as _sdist
7 6 | from distutils.command.sdist import sdist as _sdist
7 |+
8 |+ from setuptools.command.sdist import sdist as _sdist
6 |+ from distutils.command.sdist import sdist as _sdist
6 7 | from setuptools.command.sdist import sdist as _sdist
7 |- from distutils.command.sdist import sdist as _sdist


3 changes: 2 additions & 1 deletion crates/ruff/src/rules/perflint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod tests {

use crate::assert_messages;
use crate::registry::Rule;
use crate::settings::types::PythonVersion;
use crate::settings::Settings;
use crate::test::test_path;

Expand All @@ -22,7 +23,7 @@ mod tests {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("perflint").join(path).as_path(),
&Settings::for_rule(rule_code),
&Settings::for_rule(rule_code).with_target_version(PythonVersion::Py310),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/pylint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mod tests {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("pylint").join(path).as_path(),
&Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
&Settings::for_rule(rule_code),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
Expand Down
16 changes: 2 additions & 14 deletions crates/ruff/src/rules/pyupgrade/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ mod tests {
#[test_case(Rule::UselessObjectInheritance, Path::new("UP004.py"))]
#[test_case(Rule::YieldInForLoop, Path::new("UP028_0.py"))]
#[test_case(Rule::YieldInForLoop, Path::new("UP028_1.py"))]
#[test_case(Rule::NonPEP695TypeAlias, Path::new("UP040.py"))]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = path.to_string_lossy().to_string();
let diagnostics = test_path(
Path::new("pyupgrade").join(path).as_path(),
&settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
&settings::Settings::for_rule(rule_code),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
Expand All @@ -100,19 +101,6 @@ mod tests {
Ok(())
}

#[test]
fn non_pep695_type_alias_py312() -> Result<()> {
let diagnostics = test_path(
Path::new("pyupgrade/UP040.py"),
&settings::Settings {
target_version: PythonVersion::Py312,
..settings::Settings::for_rule(Rule::NonPEP695TypeAlias)
},
)?;
assert_messages!(diagnostics);
Ok(())
}

#[test]
fn future_annotations_keep_runtime_typing_p37() -> Result<()> {
let diagnostics = test_path(
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/ruff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod tests {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Path::new("ruff").join(path).as_path(),
&settings::Settings::for_rule(rule_code).with_target_version(PythonVersion::latest()),
&settings::Settings::for_rule(rule_code),
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
Expand Down
2 changes: 2 additions & 0 deletions crates/ruff/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,15 @@ impl Settings {
pub fn for_rule(rule_code: Rule) -> Self {
Self {
rules: RuleTable::from_iter([rule_code]),
target_version: PythonVersion::latest(),
..Self::default()
}
}

pub fn for_rules(rules: impl IntoIterator<Item = Rule>) -> Self {
Self {
rules: RuleTable::from_iter(rules),
target_version: PythonVersion::latest(),
..Self::default()
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/ruff/src/settings/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl From<PythonVersion> for Pep440Version {
}

impl PythonVersion {
/// Return the latest supported Python version.
pub const fn latest() -> Self {
Self::Py312
}
Expand Down

0 comments on commit 6acf07c

Please sign in to comment.