mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:26:23 +00:00
Add tests for python version compatibility (#14430)
This commit is contained in:
parent
d81b6cd334
commit
1f07880d5c
5 changed files with 80 additions and 2 deletions
|
@ -4,8 +4,8 @@
|
||||||
#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq, PartialOrd, Ord, Default, clap::ValueEnum)]
|
#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq, PartialOrd, Ord, Default, clap::ValueEnum)]
|
||||||
pub enum TargetVersion {
|
pub enum TargetVersion {
|
||||||
Py37,
|
Py37,
|
||||||
#[default]
|
|
||||||
Py38,
|
Py38,
|
||||||
|
#[default]
|
||||||
Py39,
|
Py39,
|
||||||
Py310,
|
Py310,
|
||||||
Py311,
|
Py311,
|
||||||
|
@ -46,3 +46,17 @@ impl From<TargetVersion> for red_knot_python_semantic::PythonVersion {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::target_version::TargetVersion;
|
||||||
|
use red_knot_python_semantic::PythonVersion;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn same_default_as_python_version() {
|
||||||
|
assert_eq!(
|
||||||
|
PythonVersion::from(TargetVersion::default()),
|
||||||
|
PythonVersion::default()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -184,8 +184,8 @@ impl Settings {
|
||||||
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Default)]
|
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Default)]
|
||||||
pub enum TargetVersion {
|
pub enum TargetVersion {
|
||||||
Py37,
|
Py37,
|
||||||
#[default]
|
|
||||||
Py38,
|
Py38,
|
||||||
|
#[default]
|
||||||
Py39,
|
Py39,
|
||||||
Py310,
|
Py310,
|
||||||
Py311,
|
Py311,
|
||||||
|
@ -291,3 +291,17 @@ impl System for WasmSystem {
|
||||||
fn not_found() -> std::io::Error {
|
fn not_found() -> std::io::Error {
|
||||||
std::io::Error::new(std::io::ErrorKind::NotFound, "No such file or directory")
|
std::io::Error::new(std::io::ErrorKind::NotFound, "No such file or directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::TargetVersion;
|
||||||
|
use red_knot_python_semantic::PythonVersion;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn same_default_as_python_version() {
|
||||||
|
assert_eq!(
|
||||||
|
PythonVersion::from(TargetVersion::default()),
|
||||||
|
PythonVersion::default()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -68,6 +68,10 @@ impl PythonVersion {
|
||||||
Self::Py313
|
Self::Py313
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const fn minimal_supported() -> Self {
|
||||||
|
Self::Py37
|
||||||
|
}
|
||||||
|
|
||||||
pub const fn as_tuple(&self) -> (u8, u8) {
|
pub const fn as_tuple(&self) -> (u8, u8) {
|
||||||
match self {
|
match self {
|
||||||
Self::Py37 => (3, 7),
|
Self::Py37 => (3, 7),
|
||||||
|
|
|
@ -475,4 +475,24 @@ impl PythonVersion {
|
||||||
pub fn supports_pep_701(self) -> bool {
|
pub fn supports_pep_701(self) -> bool {
|
||||||
self >= Self::Py312
|
self >= Self::Py312
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_tuple(self) -> (u8, u8) {
|
||||||
|
match self {
|
||||||
|
Self::Py37 => (3, 7),
|
||||||
|
Self::Py38 => (3, 8),
|
||||||
|
Self::Py39 => (3, 9),
|
||||||
|
Self::Py310 => (3, 10),
|
||||||
|
Self::Py311 => (3, 11),
|
||||||
|
Self::Py312 => (3, 12),
|
||||||
|
Self::Py313 => (3, 13),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn latest() -> Self {
|
||||||
|
Self::Py313
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn minimal_supported() -> Self {
|
||||||
|
Self::Py37
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3408,7 +3408,9 @@ pub struct AnalyzeOptions {
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::options::Flake8SelfOptions;
|
use crate::options::Flake8SelfOptions;
|
||||||
use ruff_linter::rules::flake8_self;
|
use ruff_linter::rules::flake8_self;
|
||||||
|
use ruff_linter::settings::types::PythonVersion as LinterPythonVersion;
|
||||||
use ruff_python_ast::name::Name;
|
use ruff_python_ast::name::Name;
|
||||||
|
use ruff_python_formatter::PythonVersion as FormatterPythonVersion;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn flake8_self_options() {
|
fn flake8_self_options() {
|
||||||
|
@ -3456,4 +3458,28 @@ mod tests {
|
||||||
vec![Name::new_static("_foo"), Name::new_static("_bar")]
|
vec![Name::new_static("_foo"), Name::new_static("_bar")]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn formatter_and_linter_target_version_have_same_default() {
|
||||||
|
assert_eq!(
|
||||||
|
FormatterPythonVersion::default().as_tuple(),
|
||||||
|
LinterPythonVersion::default().as_tuple()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn formatter_and_linter_target_version_have_same_latest() {
|
||||||
|
assert_eq!(
|
||||||
|
FormatterPythonVersion::latest().as_tuple(),
|
||||||
|
LinterPythonVersion::latest().as_tuple()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn formatter_and_linter_target_version_have_same_minimal_supported() {
|
||||||
|
assert_eq!(
|
||||||
|
FormatterPythonVersion::minimal_supported().as_tuple(),
|
||||||
|
LinterPythonVersion::minimal_supported().as_tuple()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue