<commit_before>use ::internal_prelude::works_everywhere::*;
use ::clients::stateless;


pub mod process_testing {
    use ::internal_prelude::works_everywhere::*;
    use ::imageflow_helpers::process_testing::*;
    use super::*;
    use ::clients::stateless;


    pub trait ProcTestContextExtras {
        fn write_json<T, P: AsRef<Path>>(&self, filename: P, info: &T)
            where T: serde::Serialize;

        fn create_blank_image_here<P: AsRef<Path>>(&self,
                                                   filename_without_ext: P,
                                                   w: u32,
                                                   h: u32,
                                                   encoder: s::EncoderPreset);
    }

    pub trait ProcOutputExtras {
        fn parse_stdout_as<'de, T>(&'de self) -> std::result::Result<T, serde_json::error::Error>
            where T: serde::Deserialize<'de>;
    }

    impl ProcOutputExtras for ProcOutput {
        fn parse_stdout_as<'de, T>(&'de self) -> std::result::Result<T, serde_json::error::Error>
            where T: serde::Deserialize<'de>
        {
            serde_json::from_slice(self.stdout_bytes())
        }
    }

    impl ProcTestContextExtras for ProcTestContext {
        fn write_json<T, P: AsRef<Path>>(&self, filename: P, info: &T)
            where T: serde::Serialize
        {
            let bytes = ::serde_json::to_vec_pretty(info).unwrap();
            self.write_file(filename, &bytes);
        }

        fn create_blank_image_here<P: AsRef<Path>>(&self,
                                                   filename_without_ext: P,
                                                   w: u32,
                                                   h: u32,
                                                   encoder: s::EncoderPreset) {
            let out = BlankImage {
                w: w,
                h: h,
                encoding: encoder,
                color: s::Color::Black
            }.generate();


            let mut path = self.working_dir().join(filename_without_ext);
            path.set_extension(&out.file_ext);

            self.write_file(path.file_name().unwrap().to_str().unwrap(), &out.bytes);
        }
    }
}

#[derive(Clone,Debug,PartialEq)]
pub enum TestImageSource {
    Url(String),
    Blank(BlankImage)
}

impl TestImageSource{
    pub fn get_bytes(&self) -> Vec<u8>{
        match *self{
            TestImageSource::Url(ref url) => {
                ::imageflow_helpers::fetching::fetch_bytes(url).unwrap()
            },
            TestImageSource::Blank(ref blank) => {
                blank.generate().bytes
            }
        }
    }
}
#[derive(Clone,Debug,PartialEq)]
pub struct BlankImage{
    pub w: u32,
    pub h: u32,
    pub color: s::Color,
    pub encoding: s::EncoderPreset
}

impl BlankImage{
    fn generate(&self) -> stateless::BuildOutput{
        // Invalid read here; the result of create_canvas is not being accessed correctly.
        let req = stateless::BuildRequest {
            inputs: vec![],
            framewise: s::Framewise::Steps(vec![s::Node::CreateCanvas {
                w: self.w as usize,
                h: self.h as usize,
                format: s::PixelFormat::Bgr24,
                color: self.color.clone(),
            },
            s::Node::Encode {
                io_id: 0,
                preset: self.encoding.clone(),
            }]),
            export_graphs_to: None, /* Some(std::path::PathBuf::from(format!("./{}/{}_debug", dir, filename_without_ext))) */
        };

        let result = ::clients::stateless::LibClient::new().build(req).unwrap();
        result.outputs.into_iter().next().unwrap()
    }
}<commit_msg>Fix test_helpers - don't use bgr24<commit_after>use ::internal_prelude::works_everywhere::*;
use ::clients::stateless;


pub mod process_testing {
    use ::internal_prelude::works_everywhere::*;
    use ::imageflow_helpers::process_testing::*;
    use super::*;
    use ::clients::stateless;


    pub trait ProcTestContextExtras {
        fn write_json<T, P: AsRef<Path>>(&self, filename: P, info: &T)
            where T: serde::Serialize;

        fn create_blank_image_here<P: AsRef<Path>>(&self,
                                                   filename_without_ext: P,
                                                   w: u32,
                                                   h: u32,
                                                   encoder: s::EncoderPreset);
    }

    pub trait ProcOutputExtras {
        fn parse_stdout_as<'de, T>(&'de self) -> std::result::Result<T, serde_json::error::Error>
            where T: serde::Deserialize<'de>;
    }

    impl ProcOutputExtras for ProcOutput {
        fn parse_stdout_as<'de, T>(&'de self) -> std::result::Result<T, serde_json::error::Error>
            where T: serde::Deserialize<'de>
        {
            serde_json::from_slice(self.stdout_bytes())
        }
    }

    impl ProcTestContextExtras for ProcTestContext {
        fn write_json<T, P: AsRef<Path>>(&self, filename: P, info: &T)
            where T: serde::Serialize
        {
            let bytes = ::serde_json::to_vec_pretty(info).unwrap();
            self.write_file(filename, &bytes);
        }

        fn create_blank_image_here<P: AsRef<Path>>(&self,
                                                   filename_without_ext: P,
                                                   w: u32,
                                                   h: u32,
                                                   encoder: s::EncoderPreset) {
            let out = BlankImage {
                w: w,
                h: h,
                encoding: encoder,
                color: s::Color::Black
            }.generate();


            let mut path = self.working_dir().join(filename_without_ext);
            path.set_extension(&out.file_ext);

            self.write_file(path.file_name().unwrap().to_str().unwrap(), &out.bytes);
        }
    }
}

#[derive(Clone,Debug,PartialEq)]
pub enum TestImageSource {
    Url(String),
    Blank(BlankImage)
}

impl TestImageSource{
    pub fn get_bytes(&self) -> Vec<u8>{
        match *self{
            TestImageSource::Url(ref url) => {
                ::imageflow_helpers::fetching::fetch_bytes(url).unwrap()
            },
            TestImageSource::Blank(ref blank) => {
                blank.generate().bytes
            }
        }
    }
}
#[derive(Clone,Debug,PartialEq)]
pub struct BlankImage{
    pub w: u32,
    pub h: u32,
    pub color: s::Color,
    pub encoding: s::EncoderPreset
}

impl BlankImage{
    fn generate(&self) -> stateless::BuildOutput{
        // Invalid read here; the result of create_canvas is not being accessed correctly.
        let req = stateless::BuildRequest {
            inputs: vec![],
            framewise: s::Framewise::Steps(vec![s::Node::CreateCanvas {
                w: self.w as usize,
                h: self.h as usize,
                format: s::PixelFormat::Bgr32,
                color: self.color.clone(),
            },
            s::Node::Encode {
                io_id: 0,
                preset: self.encoding.clone(),
            }]),
            export_graphs_to: None, /* Some(std::path::PathBuf::from(format!("./{}/{}_debug", dir, filename_without_ext))) */
        };

        let result = ::clients::stateless::LibClient::new().build(req).unwrap();
        result.outputs.into_iter().next().unwrap()
    }
}
{'fraction_non_alphanumeric': 0.12702666488007502, 'fraction_numerical': 0.004555808656036446, 'mean_word_length': 1.6533949520085318, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5544572', 'n_tokens_mistral': 2131, 'n_tokens_neox': 2080, 'n_words': 408}