Add tests for resolve_codes (#498)

This commit is contained in:
Charlie Marsh 2022-10-28 18:58:46 -04:00 committed by GitHub
parent 7df903dc4d
commit 782a90b584
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 2 deletions

View file

@ -5,13 +5,14 @@ use std::path::Path;
use anyhow::Result;
use log::debug;
use rustpython_parser::lexer::LexResult;
use settings::pyproject;
use settings::Settings;
use crate::autofix::fixer::Mode;
use crate::linter::{check_path, tokenize};
use crate::message::Message;
use crate::settings::configuration::Configuration;
use settings::Settings;
mod ast;
mod autofix;

View file

@ -1,8 +1,8 @@
use crate::ast::operations::SourceCodeLocator;
use itertools::izip;
use rustpython_ast::Location;
use rustpython_parser::ast::{Cmpop, Constant, Expr, ExprKind, Unaryop};
use crate::ast::operations::SourceCodeLocator;
use crate::ast::types::{CheckLocator, Range};
use crate::checks::{Check, CheckKind, RejectedCmpop};

View file

@ -1,3 +1,6 @@
//! User-provided program settings, taking into account pyproject.toml and command-line options.
//! Structure mirrors the user-facing representation of the various parameters.
use std::path::PathBuf;
use anyhow::{anyhow, Result};

View file

@ -131,3 +131,31 @@ fn resolve_codes(
}
codes
}
#[cfg(test)]
mod tests {
use std::collections::BTreeSet;
use crate::checks::CheckCode;
use crate::checks_gen::CheckCodePrefix;
use crate::settings::resolve_codes;
#[test]
fn resolver() {
let actual = resolve_codes(&[CheckCodePrefix::W], &[], &[], &[]);
let expected = BTreeSet::from_iter([CheckCode::W292, CheckCode::W605]);
assert_eq!(actual, expected);
let actual = resolve_codes(&[CheckCodePrefix::W6], &[], &[], &[]);
let expected = BTreeSet::from_iter([CheckCode::W605]);
assert_eq!(actual, expected);
let actual = resolve_codes(&[CheckCodePrefix::W], &[], &[CheckCodePrefix::W292], &[]);
let expected = BTreeSet::from_iter([CheckCode::W605]);
assert_eq!(actual, expected);
let actual = resolve_codes(&[CheckCodePrefix::W605], &[], &[CheckCodePrefix::W605], &[]);
let expected = BTreeSet::from_iter([]);
assert_eq!(actual, expected);
}
}