1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use inline_python::{ python, Context };
pub fn is_installed() -> bool {
let context: Context = python! {
try:
import RPi.GPIO
was_installed = True
except Exception as e:
was_installed = False
};
context.get::<bool>("was_installed")
}
pub mod gpio;
#[cfg(test)]
mod tests {
use crate::is_installed;
use crate::gpio;
use std::time::Duration;
use std::thread;
#[test]
fn is_installed_test() {
assert_eq!(is_installed(), true);
}
#[test]
#[cfg(target_os="linux")]
fn basic_on_off_test() {
gpio::turn_on(18);
thread::sleep(Duration::from_secs(30));
gpio::turn_off(18);
}
#[test]
#[cfg(target_os="linux")]
fn cleanup_test() {
match gpio::cleanup() {
Ok(_) => {
assert_eq!(true, true);
},
Err(msg) => {
assert_eq!(false, true);
}
};
}
}