-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from codecov/pr32
create test_utils crate to house all fixtures and reusable helpers
- Loading branch information
Showing
16 changed files
with
128 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,5 +72,5 @@ $ pytest | |
|
||
Run benchmarks with: | ||
``` | ||
$ cargo bench | ||
$ cargo bench --features testing | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "test_utils" | ||
version = "0.1.0" | ||
publish = false | ||
edition = "2021" | ||
|
||
[lib] | ||
name = "test_utils" | ||
|
||
[dependencies] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use std::{ | ||
fmt, | ||
fs::File, | ||
io::{Read, Seek}, | ||
path::PathBuf, | ||
}; | ||
|
||
#[derive(Copy, Clone)] | ||
pub enum FixtureFormat { | ||
Pyreport, | ||
} | ||
|
||
impl fmt::Display for FixtureFormat { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
FixtureFormat::Pyreport => write!(f, "pyreport"), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
pub enum FixtureSize { | ||
Large, | ||
Small, | ||
} | ||
|
||
impl fmt::Display for FixtureSize { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
FixtureSize::Large => write!(f, "large"), | ||
FixtureSize::Small => write!(f, ""), | ||
} | ||
} | ||
} | ||
|
||
fn fixture_dir(format: FixtureFormat, size: FixtureSize) -> PathBuf { | ||
PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
.join("fixtures") | ||
.join(format.to_string()) | ||
.join(size.to_string()) | ||
} | ||
|
||
#[track_caller] | ||
pub fn open_fixture( | ||
format: FixtureFormat, | ||
size: FixtureSize, | ||
name: &str, | ||
) -> Result<File, &'static str> { | ||
let path = fixture_dir(format, size).join(name); | ||
let mut file = File::open(path).map_err(|_| "failed to open file")?; | ||
|
||
let mut buf = [0; 50]; | ||
file.read(&mut buf) | ||
.map_err(|_| "failed to read beginning of file")?; | ||
if buf.starts_with(b"version https://git-lfs.github.com/spec/v1") { | ||
Err("fixture has not been pulled from Git LFS") | ||
} else { | ||
file.rewind().unwrap(); | ||
Ok(file) | ||
} | ||
} | ||
|
||
pub fn read_fixture( | ||
format: FixtureFormat, | ||
size: FixtureSize, | ||
name: &str, | ||
) -> Result<Vec<u8>, &'static str> { | ||
// Just make sure the file exists and that it has been pulled from Git LFS | ||
let _file = open_fixture(format, size, name)?; | ||
|
||
// Actually read and return the contents | ||
let path = fixture_dir(format, size).join(name); | ||
std::fs::read(path).map_err(|_| "failed to read file") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod fixtures; |