Skip to main content

TestSystem

Struct TestSystem 

Source
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

Source

pub fn new( inner: impl WritableSystem + RefUnwindSafe + Send + Sync + 'static, ) -> Self

Source

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.

Source

pub fn remove_env_var(&self, name: impl Into<String>)

Removes an environment variable override, making it appear as not set.

Source

pub fn in_memory(&self) -> &InMemorySystem

Returns the InMemorySystem.

§Panics

If the underlying test system isn’t the InMemorySystem.

Source

pub fn memory_file_system(&self) -> &MemoryFileSystem

Returns the memory file system.

§Panics

If the underlying test system isn’t the InMemorySystem.

Trait Implementations§

Source§

impl Clone for TestSystem

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TestSystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TestSystem

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl System for TestSystem

Source§

fn path_metadata(&self, path: &SystemPath) -> Result<Metadata>

Reads the metadata of the file or directory at path. Read more
Source§

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>

Returns true if both paths refer to the same file.
Source§

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>

Reads the content of the file at path as a Notebook. Read more
Source§

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>

Reads the content of the virtual file at path as a Notebook.
Source§

fn current_directory(&self) -> &SystemPath

Returns the current working directory
Source§

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>

Returns the directory path where cached files are stored. Read more
Source§

fn which(&self, _name: &str) -> WhichResult

Find an executable binary’s path by name.
Source§

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>>

Iterate over the contents of the directory at path. Read more
Source§

fn walk_directory(&self, path: &SystemPath) -> WalkDirectoryBuilder

Recursively walks the content of path. Read more
Source§

fn as_writable(&self) -> Option<&dyn WritableSystem>

Returns a handle to a WritableSystem if this system is writable.
Source§

fn as_any(&self) -> &dyn Any

Source§

fn as_any_mut(&mut self) -> &mut dyn Any

Source§

fn env_var(&self, name: &str) -> Result<String, VarError>

Fetches the environment variable key from the current process. Read more
Source§

fn dyn_clone(&self) -> Box<dyn System>

Source§

fn source_type(&self, path: &SystemPath) -> Option<PySourceType>

Returns the source type for path if known or None. Read more
Source§

fn virtual_path_source_type( &self, path: &SystemVirtualPath, ) -> Option<PySourceType>

Returns the source type for path if known or None. Read more
Source§

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

Returns true if path exists.
Source§

fn is_directory(&self, path: &SystemPath) -> bool

Returns true if path exists and is a directory.
Source§

fn is_file(&self, path: &SystemPath) -> bool

Returns true if path exists and is a file.
Source§

impl WritableSystem for TestSystem

Source§

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<()>

Writes the given content to the file at the given path.
Source§

fn create_directory_all(&self, path: &SystemPath) -> Result<()>

Creates a directory at path as well as any intermediate directories.
Source§

fn dyn_clone(&self) -> Box<dyn WritableSystem>

Source§

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>>

Reads the provided file from the system cache, or creates the file if necessary. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Lookup<T> for T

Source§

fn into_owned(self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more