Skip to content

Commit

Permalink
integrate validation failure into py test
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Jul 9, 2024
1 parent 0da3807 commit 4f742e7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 122 deletions.
16 changes: 14 additions & 2 deletions miniconf_mqtt/examples/mqtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std_embedded_time::StandardClock;

#[derive(Clone, Default, Tree, Debug)]
struct Inner {
frame_rate: u32,
a: u32,
}

#[derive(Copy, Clone, Default, Debug, Serialize, Deserialize)]
Expand All @@ -26,13 +26,25 @@ struct Settings {
#[tree(depth = 1)]
inner: Inner,
#[tree(depth = 1)]
amplitude: [f32; 2],
values: [f32; 2],
array: [i32; 4],
#[tree(depth = 1)]
opt: Option<i32>,
#[tree(validate=Self::validate_four)]
four: f32,
exit: bool,
}

impl Settings {
fn validate_four(&mut self, new: f32) -> Result<f32, &'static str> {
if new < 4.0 {
Err("Less than four")
} else {
Ok(new)
}
}
}

#[tokio::main]
async fn main() {
env_logger::init();
Expand Down
112 changes: 0 additions & 112 deletions miniconf_mqtt/tests/validation_failure.rs

This file was deleted.

2 changes: 1 addition & 1 deletion py/miniconf-mqtt/miniconf/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def main():
epilog="""Examples:
%(prog)s dt/sinara/dual-iir/01-02-03-04-05-06 '/stream="192.0.2.16:9293"'
%(prog)s -d dt/sinara/dual-iir/+ '/afe/0' # GET
%(prog)s -d dt/sinara/dual-iir/+ '/afe/0="G1"' # SET
%(prog)s -d dt/sinara/dual-iir/+ '/afe/0="G10"' # SET
%(prog)s -d dt/sinara/dual-iir/+ '/afe/0=' # CLEAR
%(prog)s -d dt/sinara/dual-iir/+ '/afe?' '?' # LIST-GET
%(prog)s -d dt/sinara/dual-iir/+ '/afe!' # DUMP
Expand Down
20 changes: 13 additions & 7 deletions py/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -e
set -x
trap 'jobs -p | xargs -r kill' EXIT

python -m venv .venv
. .venv/bin/activate
Expand All @@ -11,12 +12,17 @@ cargo build -p miniconf_mqtt --example mqtt
cargo run -p miniconf_mqtt --example mqtt &
sleep 3 # > REPUBLISH_TIMEOUT_SECONDS

MC="python -m miniconf -b localhost -d dt/sinara/dual-iir/+"

python -m miniconf -b localhost dt/sinara/dual-iir/01-02-03-04-05-06 '/stream="192.0.2.16:9293"'
python -m miniconf -b localhost -d dt/sinara/dual-iir/+ '/afe/0' # GET
python -m miniconf -b localhost -d dt/sinara/dual-iir/+ '/afe/0="G1"' # SET
python -m miniconf -b localhost -d dt/sinara/dual-iir/+ '/afe/0=' # CLEAR
python -m miniconf -b localhost -d dt/sinara/dual-iir/+ '/afe?' '?' # LIST-GET
python -m miniconf -b localhost -d dt/sinara/dual-iir/+ '/afe!' # DUMP
sleep 1 # dump is asynchronous
# GET SET CLEAR LIST DUMP
$MC '/afe/0' '/afe/0="G10"' '/afe/0=' '/afe?' '?' '/afe!'
sleep 1 # DUMP is asynchronous

$MC '/four=5'
set +e
$MC '/four=2'
test $? -ne 1 && exit 1
set -e

python -m miniconf -b localhost -d dt/sinara/dual-iir/+ '/exit=true'
$MC '/exit=true'

0 comments on commit 4f742e7

Please sign in to comment.