pub struct TestSystem { /* private fields */ }Expand description
System implementation intended for testing.
It uses a memory-file system by default, but can be switched to the real file system for tests verifying more advanced file system features.
§Warning
Don’t use this system for production code. It’s intended for testing only.
Implementations§
Source§impl TestSystem
impl TestSystem
pub fn new( inner: impl WritableSystem + RefUnwindSafe + Send + Sync + 'static, ) -> Self
Sourcepub fn set_env_var(&self, name: impl Into<String>, value: impl Into<String>)
pub fn set_env_var(&self, name: impl Into<String>, value: impl Into<String>)
Sets an environment variable override. This takes precedence over the inner system.
Sourcepub fn remove_env_var(&self, name: impl Into<String>)
pub fn remove_env_var(&self, name: impl Into<String>)
Removes an environment variable override, making it appear as not set.
Sourcepub fn in_memory(&self) -> &InMemorySystem
pub fn in_memory(&self) -> &InMemorySystem
Sourcepub fn memory_file_system(&self) -> &MemoryFileSystem
pub fn memory_file_system(&self) -> &MemoryFileSystem
Trait Implementations§
Source§impl Clone for TestSystem
impl Clone for TestSystem
Source§impl Debug for TestSystem
impl Debug for TestSystem
Source§impl Default for TestSystem
impl Default for TestSystem
Source§impl System for TestSystem
impl System for TestSystem
Source§fn path_metadata(&self, path: &SystemPath) -> Result<Metadata>
fn path_metadata(&self, path: &SystemPath) -> Result<Metadata>
Reads the metadata of the file or directory at
path. Read moreSource§fn canonicalize_path(&self, path: &SystemPath) -> Result<SystemPathBuf>
fn canonicalize_path(&self, path: &SystemPath) -> Result<SystemPathBuf>
Returns the canonical, absolute form of a path with all intermediate components normalized
and symbolic links resolved. Read more
Source§fn is_same_file(&self, first: &SystemPath, second: &SystemPath) -> Result<bool>
fn is_same_file(&self, first: &SystemPath, second: &SystemPath) -> Result<bool>
Returns
true if both paths refer to the same file.Source§fn read_to_string(&self, path: &SystemPath) -> Result<String>
fn read_to_string(&self, path: &SystemPath) -> Result<String>
Reads the content of the file at
path into a String.Source§fn read_to_notebook(&self, path: &SystemPath) -> Result<Notebook, NotebookError>
fn read_to_notebook(&self, path: &SystemPath) -> Result<Notebook, NotebookError>
Reads the content of the file at
path as a Notebook. Read moreSource§fn read_virtual_path_to_string(
&self,
path: &SystemVirtualPath,
) -> Result<String>
fn read_virtual_path_to_string( &self, path: &SystemVirtualPath, ) -> Result<String>
Reads the content of the virtual file at
path into a String.Source§fn read_virtual_path_to_notebook(
&self,
path: &SystemVirtualPath,
) -> Result<Notebook, NotebookError>
fn read_virtual_path_to_notebook( &self, path: &SystemVirtualPath, ) -> Result<Notebook, NotebookError>
Reads the content of the virtual file at
path as a Notebook.Source§fn current_directory(&self) -> &SystemPath
fn current_directory(&self) -> &SystemPath
Returns the current working directory
Source§fn user_config_directory(&self) -> Option<SystemPathBuf>
fn user_config_directory(&self) -> Option<SystemPathBuf>
Returns the directory path where user configurations are stored. Read more
Source§fn cache_dir(&self) -> Option<SystemPathBuf>
fn cache_dir(&self) -> Option<SystemPathBuf>
Returns the directory path where cached files are stored. Read more
Source§fn which(&self, _name: &str) -> WhichResult
fn which(&self, _name: &str) -> WhichResult
Find an executable binary’s path by name.
Source§fn command_executor(&self) -> Option<&dyn CommandExecutor>
fn command_executor(&self) -> Option<&dyn CommandExecutor>
Returns the system’s command executor, if it supports running commands.
Source§fn read_directory<'a>(
&'a self,
path: &SystemPath,
) -> Result<Box<dyn Iterator<Item = Result<DirectoryEntry>> + 'a>>
fn read_directory<'a>( &'a self, path: &SystemPath, ) -> Result<Box<dyn Iterator<Item = Result<DirectoryEntry>> + 'a>>
Iterate over the contents of the directory at
path. Read moreSource§fn walk_directory(&self, path: &SystemPath) -> WalkDirectoryBuilder
fn walk_directory(&self, path: &SystemPath) -> WalkDirectoryBuilder
Recursively walks the content of
path. Read moreSource§fn as_writable(&self) -> Option<&dyn WritableSystem>
fn as_writable(&self) -> Option<&dyn WritableSystem>
Returns a handle to a
WritableSystem if this system is writable.fn as_any(&self) -> &dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Source§fn env_var(&self, name: &str) -> Result<String, VarError>
fn env_var(&self, name: &str) -> Result<String, VarError>
Fetches the environment variable
key from the current process. Read morefn dyn_clone(&self) -> Box<dyn System>
Source§fn source_type(&self, path: &SystemPath) -> Option<PySourceType>
fn source_type(&self, path: &SystemPath) -> Option<PySourceType>
Source§fn virtual_path_source_type(
&self,
path: &SystemVirtualPath,
) -> Option<PySourceType>
fn virtual_path_source_type( &self, path: &SystemVirtualPath, ) -> Option<PySourceType>
Source§fn run_command(&self, command: Command) -> Result<Output>
fn run_command(&self, command: Command) -> Result<Output>
Runs
command and captures its standard output and standard error.Source§fn path_exists(&self, path: &SystemPath) -> bool
fn path_exists(&self, path: &SystemPath) -> bool
Returns
true if path exists.Source§fn is_directory(&self, path: &SystemPath) -> bool
fn is_directory(&self, path: &SystemPath) -> bool
Returns
true if path exists and is a directory.Source§fn is_file(&self, path: &SystemPath) -> bool
fn is_file(&self, path: &SystemPath) -> bool
Returns
true if path exists and is a file.Source§impl WritableSystem for TestSystem
impl WritableSystem for TestSystem
Source§fn create_new_file(&self, path: &SystemPath) -> Result<()>
fn create_new_file(&self, path: &SystemPath) -> Result<()>
Creates a file at the given path. Read more
Source§fn write_file_bytes(&self, path: &SystemPath, content: &[u8]) -> Result<()>
fn write_file_bytes(&self, path: &SystemPath, content: &[u8]) -> Result<()>
Writes the given content to the file at the given path.
Source§fn create_directory_all(&self, path: &SystemPath) -> Result<()>
fn create_directory_all(&self, path: &SystemPath) -> Result<()>
Creates a directory at
path as well as any intermediate directories.fn dyn_clone(&self) -> Box<dyn WritableSystem>
Source§fn write_file(&self, path: &SystemPath, content: &str) -> Result<()>
fn write_file(&self, path: &SystemPath, content: &str) -> Result<()>
Writes the given content to the file at the given path.
Source§fn get_or_cache(
&self,
path: &SystemPath,
read_contents: &dyn Fn() -> Result<String>,
) -> Result<Option<SystemPathBuf>>
fn get_or_cache( &self, path: &SystemPath, read_contents: &dyn Fn() -> Result<String>, ) -> Result<Option<SystemPathBuf>>
Reads the provided file from the system cache, or creates the file if necessary. Read more
Auto Trait Implementations§
impl Freeze for TestSystem
impl RefUnwindSafe for TestSystem
impl Send for TestSystem
impl Sync for TestSystem
impl Unpin for TestSystem
impl UnsafeUnpin for TestSystem
impl UnwindSafe for TestSystem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more