def test_current_directory(self): with patch("os.environ", {"PYTHONPATH": "."}): self.assertTrue( file_util.file_in_pythonpath( self._make_it_absolute("something/dir1/dir2/module"))) self.assertTrue( file_util.file_in_pythonpath( self._make_it_absolute("something_else/module"))) self.assertFalse( file_util.file_in_pythonpath( self._make_it_absolute("../something_else/module")))
def test_python_path_mixed(self): with patch( "os.environ", { "PYTHONPATH": os.pathsep.join( [self._make_it_absolute("something"), "something"]) }, ): self.assertTrue( file_util.file_in_pythonpath( self._make_it_absolute("something/dir1/dir2/module"))) self.assertFalse( file_util.file_in_pythonpath( self._make_it_absolute("something_else/module")))
def test_empty_pythonpath(self): with patch("os.environ", {"PYTHONPATH": ""}): self.assertFalse( file_util.file_in_pythonpath( self._make_it_absolute("something/dir1/dir2/module") ) )
def test_no_pythonpath(self): with patch("os.environ", {}) as d: self.assertFalse( file_util.file_in_pythonpath( self._make_it_absolute("../something/dir1/dir2/module") ) )
def _file_should_be_hashed(self, filename): filepath = os.path.abspath(filename) file_is_blacklisted = self._folder_black_list.is_blacklisted(filepath) # Short circuiting for performance. if file_is_blacklisted: return False return file_util.file_is_in_folder_glob( filepath, self._get_main_script_directory() ) or file_util.file_in_pythonpath(filepath)
def _file_should_be_hashed(self, filename: str) -> bool: global _FOLDER_BLACK_LIST if not _FOLDER_BLACK_LIST: _FOLDER_BLACK_LIST = FolderBlackList( config.get_option("server.folderWatchBlacklist")) filepath = os.path.abspath(filename) file_is_blacklisted = _FOLDER_BLACK_LIST.is_blacklisted(filepath) # Short circuiting for performance. if file_is_blacklisted: return False return file_util.file_is_in_folder_glob( filepath, self._get_main_script_directory() ) or file_util.file_in_pythonpath(filepath)
def _file_should_be_watched(self, filepath): # Using short circuiting for performance. return self._file_is_new(filepath) and ( file_util.file_is_in_folder_glob(filepath, self._session_data.script_folder) or file_util.file_in_pythonpath(filepath))