File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 11//! Contains the Python3 student file policy
22
3+ use std:: ffi:: OsStr ;
34use std:: path:: { Path , PathBuf } ;
45use tmc_langs_framework:: policy:: StudentFilePolicy ;
56
@@ -22,5 +23,35 @@ impl StudentFilePolicy for Python3StudentFilePolicy {
2223
2324 fn is_student_source_file ( & self , path : & Path ) -> bool {
2425 path. starts_with ( "src" )
26+ && path. extension ( ) != Some ( OsStr :: new ( "pyc" ) )
27+ && !path
28+ . components ( )
29+ . any ( |c| c. as_os_str ( ) == OsStr :: new ( "__pycache__" ) )
30+ }
31+ }
32+
33+ #[ cfg( test) ]
34+ mod test {
35+ use super :: * ;
36+
37+ #[ test]
38+ fn in_src_is_source_file ( ) {
39+ let policy = Python3StudentFilePolicy :: new ( PathBuf :: from ( "" ) ) ;
40+ assert ! ( policy. is_student_source_file( Path :: new( "src/some_file.py" ) ) ) ;
41+ }
42+
43+ #[ test]
44+ fn pycache_is_not_source_file ( ) {
45+ let policy = Python3StudentFilePolicy :: new ( PathBuf :: from ( "" ) ) ;
46+ assert ! ( !policy. is_student_source_file( Path :: new( "__pycache__" ) ) ) ;
47+ assert ! ( !policy. is_student_source_file( Path :: new( "__pycache__/cachefile" ) ) ) ;
48+ assert ! ( !policy. is_student_source_file( Path :: new( "src/__pycache__" ) ) ) ;
49+ }
50+
51+ #[ test]
52+ fn pyc_is_not_source_file ( ) {
53+ let policy = Python3StudentFilePolicy :: new ( PathBuf :: from ( "" ) ) ;
54+ assert ! ( !policy. is_student_source_file( Path :: new( "some.pyc" ) ) ) ;
55+ assert ! ( !policy. is_student_source_file( Path :: new( "src/other.pyc" ) ) ) ;
2556 }
2657}
You can’t perform that action at this time.
0 commit comments