muse2/example/
patches.rs

1//! File patches to be used in integration tests.
2//!
3//! This is used to test small variations on existing example models.
4use crate::patch::FilePatch;
5use anyhow::{Context, Result};
6use std::{collections::BTreeMap, sync::LazyLock};
7
8/// A map of file patches, keyed by name
9type PatchMap = BTreeMap<&'static str, Vec<FilePatch>>;
10
11/// The file patches, keyed by name
12static PATCHES: LazyLock<PatchMap> = LazyLock::new(get_all_patches);
13
14/// Get all patches
15fn get_all_patches() -> PatchMap {
16    [(
17        // The simple example with gas boiler process made divisible
18        "simple_divisible",
19        vec![
20            FilePatch::new("processes.csv")
21                .with_deletion("RGASBR,Gas boiler,all,RSHEAT,2020,2040,1.0,")
22                .with_addition("RGASBR,Gas boiler,all,RSHEAT,2020,2040,1.0,1000"),
23        ],
24    )]
25    .into_iter()
26    .collect()
27}
28
29/// Get the names for all the patches
30pub fn get_patch_names() -> impl Iterator<Item = &'static str> {
31    PATCHES.keys().copied()
32}
33
34/// Get patches for the named patched example
35pub fn get_patches(name: &str) -> Result<&[FilePatch]> {
36    Ok(PATCHES
37        .get(name)
38        .with_context(|| format!("Patched example '{name}' not found"))?)
39}