Adapt the Python test script to the new Ouch interface

This commit is contained in:
Vinícius Rodrigues Miguel 2021-04-05 20:57:18 -03:00
parent 94ecc63886
commit 1c5005f5a9
4 changed files with 19 additions and 19 deletions

View File

@ -12,9 +12,9 @@ def make_random_file():
def sanity_check_format(format: str): def sanity_check_format(format: str):
make_random_file() make_random_file()
md5sum = hashlib.md5(open('test-file', 'rb').read()).hexdigest() md5sum = hashlib.md5(open('test-file', 'rb').read()).hexdigest()
os.system(f"cargo run -- -i test-file -o test-file.{format}") os.system(f"cargo run -- compress test-file test-file.{format}")
os.remove('test-file') os.remove('test-file')
os.system(f"cargo run -- -i test-file.{format}") os.system(f"cargo run -- test-file.{format}")
if md5sum != hashlib.md5(open('test-file', 'rb').read()).hexdigest(): if md5sum != hashlib.md5(open('test-file', 'rb').read()).hexdigest():
print("Something went wrong with tar (de)compression.") print("Something went wrong with tar (de)compression.")
os._exit(2) os._exit(2)
@ -81,16 +81,16 @@ if __name__ == "__main__":
print(f"Failed while decompressing {file}") print(f"Failed while decompressing {file}")
os._exit(2) os._exit(2)
# os.chdir("..") os.chdir("..")
# os.system("rm -rf testbuilds") os.system("rm -rf testbuilds")
# # We'll now verify if ouch is not altering the data it is compressing # We'll now verify if ouch is not altering the data it is compressing
# # and decompressing # and decompressing
# sanity_check_format("zip") sanity_check_format("zip")
# sanity_check_format("tar") sanity_check_format("tar")
# sanity_check_format("tar.gz") sanity_check_format("tar.gz")
# sanity_check_format("tar.bz") sanity_check_format("tar.bz")
# sanity_check_format("tar.bz2") sanity_check_format("tar.bz2")
# sanity_check_format("tar.lz") sanity_check_format("tar.lz")
# sanity_check_format("tar.lzma") sanity_check_format("tar.lzma")

View File

@ -19,7 +19,8 @@ use crate::{
dialogs::Confirmation, dialogs::Confirmation,
extension::{CompressionFormat, Extension}, extension::{CompressionFormat, Extension},
file::File, file::File,
utils utils,
debug
}; };
pub struct Evaluator {} pub struct Evaluator {}
@ -213,7 +214,7 @@ impl Evaluator {
output: Option<&Path>, output: Option<&Path>,
flags: &oof::Flags, flags: &oof::Flags,
) -> crate::Result<()> { ) -> crate::Result<()> {
let file = File::from(file_path)?; let file = debug!(File::from(file_path)?);
let output = match output { let output = match output {
Some(inner) => Some(File::from(inner)?), Some(inner) => Some(File::from(inner)?),
None => None, None => None,

View File

@ -7,7 +7,7 @@ use std::{
use CompressionFormat::*; use CompressionFormat::*;
use crate::utils::to_utf; use crate::{debug, utils::to_utf};
/// Represents the extension of a file, but only really caring about /// Represents the extension of a file, but only really caring about
/// compression formats (and .tar). /// compression formats (and .tar).

View File

@ -19,13 +19,12 @@ pub struct File<'a> {
impl<'a> File<'a> { impl<'a> File<'a> {
pub fn from(path: &'a Path) -> crate::Result<Self> { pub fn from(path: &'a Path) -> crate::Result<Self> {
let extension = Extension::from(path.as_ref())?; let extension = Extension::from(path.as_ref()).ok();
eprintln!("dev warning: Should we really ignore the errors from the convertion above?");
Ok(File { Ok(File {
path, path,
contents_in_memory: None, contents_in_memory: None,
extension: Some(extension), extension
}) })
} }
} }