Use latest Python version by default in tests (#6448)

## Summary

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

## Test Plan

`cargo test`

---------

Co-authored-by: Zanie <contact@zanie.dev>
This commit is contained in:
Charlie Marsh 2023-08-09 11:22:39 -04:00 committed by GitHub
parent 38b9fb8bbd
commit 6acf07c5c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 40 additions and 32 deletions

View File

@ -11,7 +11,6 @@ mod tests {
use crate::assert_messages; use crate::assert_messages;
use crate::registry::Rule; use crate::registry::Rule;
use crate::settings::types::PythonVersion;
use crate::settings::Settings; use crate::settings::Settings;
use crate::test::test_path; use crate::test::test_path;
@ -65,8 +64,7 @@ mod tests {
let snapshot = "B905.py"; let snapshot = "B905.py";
let diagnostics = test_path( let diagnostics = test_path(
Path::new("flake8_bugbear").join(snapshot).as_path(), Path::new("flake8_bugbear").join(snapshot).as_path(),
&Settings::for_rule(Rule::ZipWithoutExplicitStrict) &Settings::for_rule(Rule::ZipWithoutExplicitStrict),
.with_target_version(PythonVersion::latest()),
)?; )?;
assert_messages!(snapshot, diagnostics); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())
@ -84,7 +82,7 @@ mod tests {
"fastapi.Query".to_string(), "fastapi.Query".to_string(),
], ],
}, },
..Settings::for_rules(vec![Rule::FunctionCallInDefaultArgument]) ..Settings::for_rule(Rule::FunctionCallInDefaultArgument)
}, },
)?; )?;
assert_messages!(snapshot, diagnostics); assert_messages!(snapshot, diagnostics);

View File

@ -1,4 +1,25 @@
--- ---
source: crates/ruff/src/rules/flake8_pyi/mod.rs 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 | ...
|

View File

@ -1,7 +1,7 @@
--- ---
source: crates/ruff/src/rules/flake8_pyi/mod.rs 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): ... 4 | def foo(arg): ...
5 | def foo_int(arg: int): ... 5 | def foo_int(arg: int): ...
@ -11,7 +11,7 @@ PYI050.pyi:6:24: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for arg
8 | arg: typing_extensions.NoReturn, 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, 8 | arg: typing_extensions.NoReturn,
9 | ): ... # Error: PYI050 9 | ): ... # Error: PYI050
@ -21,7 +21,7 @@ PYI050.pyi:10:44: PYI050 Prefer `typing_extensions.Never` over `NoReturn` for ar
12 | def foo_never(arg: Never): ... 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 9 | ): ... # Error: PYI050
10 | def foo_no_return_kwarg(arg: int, *, arg2: NoReturn): ... # Error: PYI050 10 | def foo_no_return_kwarg(arg: int, *, arg2: NoReturn): ... # Error: PYI050

View File

@ -12,7 +12,6 @@ mod tests {
use crate::assert_messages; use crate::assert_messages;
use crate::registry::Rule; use crate::registry::Rule;
use crate::settings; use crate::settings;
use crate::settings::types::PythonVersion;
use crate::test::test_path; use crate::test::test_path;
#[test_case(Path::new("full_name.py"))] #[test_case(Path::new("full_name.py"))]
@ -49,8 +48,7 @@ mod tests {
Rule::OsPathSamefile, Rule::OsPathSamefile,
Rule::OsPathSplitext, Rule::OsPathSplitext,
Rule::BuiltinOpen, Rule::BuiltinOpen,
]) ]),
.with_target_version(PythonVersion::latest()),
)?; )?;
assert_messages!(snapshot, diagnostics); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())
@ -69,7 +67,7 @@ mod tests {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path( let diagnostics = test_path(
Path::new("flake8_use_pathlib").join(path).as_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); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())

View File

@ -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: 3 3 | elif "setuptools" in sys.modules:
4 4 | from setuptools.command.sdist import sdist as _sdist 4 4 | from setuptools.command.sdist import sdist as _sdist
5 5 | else: 5 5 | else:
6 |- from setuptools.command.sdist import sdist as _sdist 6 |+ from distutils.command.sdist import sdist as _sdist
7 6 | from distutils.command.sdist import sdist as _sdist 6 7 | from setuptools.command.sdist import sdist as _sdist
7 |+ 7 |- from distutils.command.sdist import sdist as _sdist
8 |+ from setuptools.command.sdist import sdist as _sdist

View File

@ -10,6 +10,7 @@ mod tests {
use crate::assert_messages; use crate::assert_messages;
use crate::registry::Rule; use crate::registry::Rule;
use crate::settings::types::PythonVersion;
use crate::settings::Settings; use crate::settings::Settings;
use crate::test::test_path; use crate::test::test_path;
@ -22,7 +23,7 @@ mod tests {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path( let diagnostics = test_path(
Path::new("perflint").join(path).as_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); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())

View File

@ -130,7 +130,7 @@ mod tests {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path( let diagnostics = test_path(
Path::new("pylint").join(path).as_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); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())

View File

@ -77,11 +77,12 @@ mod tests {
#[test_case(Rule::UselessObjectInheritance, Path::new("UP004.py"))] #[test_case(Rule::UselessObjectInheritance, Path::new("UP004.py"))]
#[test_case(Rule::YieldInForLoop, Path::new("UP028_0.py"))] #[test_case(Rule::YieldInForLoop, Path::new("UP028_0.py"))]
#[test_case(Rule::YieldInForLoop, Path::new("UP028_1.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<()> { fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = path.to_string_lossy().to_string(); let snapshot = path.to_string_lossy().to_string();
let diagnostics = test_path( let diagnostics = test_path(
Path::new("pyupgrade").join(path).as_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); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())
@ -100,19 +101,6 @@ mod tests {
Ok(()) 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] #[test]
fn future_annotations_keep_runtime_typing_p37() -> Result<()> { fn future_annotations_keep_runtime_typing_p37() -> Result<()> {
let diagnostics = test_path( let diagnostics = test_path(

View File

@ -44,7 +44,7 @@ mod tests {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path( let diagnostics = test_path(
Path::new("ruff").join(path).as_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); assert_messages!(snapshot, diagnostics);
Ok(()) Ok(())

View File

@ -298,6 +298,7 @@ impl Settings {
pub fn for_rule(rule_code: Rule) -> Self { pub fn for_rule(rule_code: Rule) -> Self {
Self { Self {
rules: RuleTable::from_iter([rule_code]), rules: RuleTable::from_iter([rule_code]),
target_version: PythonVersion::latest(),
..Self::default() ..Self::default()
} }
} }
@ -305,6 +306,7 @@ impl Settings {
pub fn for_rules(rules: impl IntoIterator<Item = Rule>) -> Self { pub fn for_rules(rules: impl IntoIterator<Item = Rule>) -> Self {
Self { Self {
rules: RuleTable::from_iter(rules), rules: RuleTable::from_iter(rules),
target_version: PythonVersion::latest(),
..Self::default() ..Self::default()
} }
} }

View File

@ -53,6 +53,7 @@ impl From<PythonVersion> for Pep440Version {
} }
impl PythonVersion { impl PythonVersion {
/// Return the latest supported Python version.
pub const fn latest() -> Self { pub const fn latest() -> Self {
Self::Py312 Self::Py312
} }