Skip to content

Commit e8706f5

Browse files
committed
consider non-test and non-tmc subdirectories to be student files in python policy
1 parent 83362e4 commit e8706f5

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

plugins/python3/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The plugin creates a warning when the Python used is detected to be older than t
44

55
## Student file policy
66

7-
All files inside `./src` are considered student files, except for files with a `pyc` extension and files inside a `__pycache__` directory. In addition, all files in the project root with a `.py` extension are considered student files.
7+
All files inside `./src` are considered student files, except for files with a `pyc` extension and files inside a `__pycache__` directory. In addition, all files in the project root with a `.py` extension are considered student files. All files in directories other than `./test` and `./tmc` are considered student files, except for files with a `pyc` extension and files inside a `__pycache__` directory.
88

99
### Example
1010

@@ -13,11 +13,15 @@ All files inside `./src` are considered student files, except for files with a `
1313
./src/file
1414
./src/subdirectory/file
1515
./root.py
16+
./dir/any_non_cache_file
1617

1718
# Not student files
18-
./tests/test_file
19+
./test/test_file
1920
./src/file.pyc
2021
./src/__pycache__/file
22+
./file_in_root
23+
./dir/cache_file.pyc
24+
./dir/__pycache__/cache_file
2125
```
2226

2327
## Environment variables

plugins/python3/src/policy.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ impl StudentFilePolicy for Python3StudentFilePolicy {
3636
};
3737
let is_py_file = path.extension() == Some(OsStr::new("py"));
3838

39-
in_src && !is_cache_file || is_in_project_root && is_py_file
39+
// all files in non-tmc and non-test subdirectories are considered student files
40+
let is_in_exercise_subdir = path.starts_with("test") || path.starts_with("tmc");
41+
42+
in_src && !is_cache_file
43+
|| is_in_project_root && is_py_file
44+
|| !is_in_exercise_subdir && !is_in_project_root && !is_cache_file
4045
}
4146
}
4247

@@ -76,4 +81,25 @@ mod test {
7681
assert!(!policy.is_student_source_file(Path::new("some.pyc")));
7782
assert!(!policy.is_student_source_file(Path::new("src/other.pyc")));
7883
}
84+
85+
#[test]
86+
fn subdirs_are_student_files() {
87+
let policy = Python3StudentFilePolicy::new(PathBuf::from(""));
88+
assert!(policy.is_student_source_file(Path::new("subdir/something")));
89+
assert!(policy.is_student_source_file(Path::new("another/mid/else")));
90+
}
91+
92+
#[test]
93+
fn tmc_and_test_are_not_student_files() {
94+
let policy = Python3StudentFilePolicy::new(PathBuf::from(""));
95+
assert!(policy.is_student_source_file(Path::new("subdir/something")));
96+
assert!(policy.is_student_source_file(Path::new("another/mid/else")));
97+
}
98+
99+
#[test]
100+
fn non_py_file_in_root_is_not_student_file() {
101+
let policy = Python3StudentFilePolicy::new(PathBuf::from(""));
102+
assert!(!policy.is_student_source_file(Path::new("test")));
103+
assert!(!policy.is_student_source_file(Path::new("root_file")));
104+
}
79105
}

0 commit comments

Comments
 (0)