Skip to content

Commit

Permalink
Use is_jupyter_notebook param
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Jul 27, 2023
1 parent d21a1af commit 4ce5c28
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,17 @@ fn get_parametrize_name_range(
decorator: &Decorator,
expr: &Expr,
locator: &Locator,
mode: Mode,
is_jupyter_notebook: bool,
) -> TextRange {
let mut locations = Vec::new();
let mut implicit_concat = None;

let mode = if is_jupyter_notebook {
Mode::Jupyter
} else {
Mode::Module
};

// The parenthesis are not part of the AST, so we need to tokenize the
// decorator to find them.
for (tok, range) in
Expand Down Expand Up @@ -132,11 +138,6 @@ fn get_parametrize_name_range(
/// PT006
fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
let names_type = checker.settings.flake8_pytest_style.parametrize_names_type;
let mode = if checker.is_jupyter_notebook {
Mode::Jupyter
} else {
Mode::Module
};

match expr {
Expr::Constant(ast::ExprConstant {
Expand All @@ -147,8 +148,12 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
if names.len() > 1 {
match names_type {
types::ParametrizeNameType::Tuple => {
let name_range =
get_parametrize_name_range(decorator, expr, checker.locator(), mode);
let name_range = get_parametrize_name_range(
decorator,
expr,
checker.locator(),
checker.is_jupyter_notebook,
);
let mut diagnostic = Diagnostic::new(
PytestParametrizeNamesWrongType {
expected: names_type,
Expand Down Expand Up @@ -178,8 +183,12 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
checker.diagnostics.push(diagnostic);
}
types::ParametrizeNameType::List => {
let name_range =
get_parametrize_name_range(decorator, expr, checker.locator(), mode);
let name_range = get_parametrize_name_range(
decorator,
expr,
checker.locator(),
checker.is_jupyter_notebook,
);
let mut diagnostic = Diagnostic::new(
PytestParametrizeNamesWrongType {
expected: names_type,
Expand Down

0 comments on commit 4ce5c28

Please sign in to comment.