Skip to content

Commit 49a79b0

Browse files
authored
Merge pull request #114 from Synicix/test_split
Splitting test into unit and integration tests to match with Rust testing standards
2 parents dfdd36b + e185b65 commit 49a79b0

File tree

16 files changed

+475
-372
lines changed

16 files changed

+475
-372
lines changed

.vscode/settings.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
"files.insertFinalNewline": true,
1212
"gitlens.showWhatsNewAfterUpgrades": false,
1313
"lldb.consoleMode": "evaluate",
14-
"rust-analyzer.cargo.features": [
15-
"test"
16-
],
17-
"rust-analyzer.cargo.noDefaultFeatures": true,
1814
"rust-analyzer.check.command": "clippy",
1915
"rust-analyzer.runnables.extraTestBinaryArgs": [
2016
"--nocapture"

notebook.ipynb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "3ba2aae6",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import orcapod as op"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "4d867643",
17+
"metadata": {},
18+
"outputs": [
19+
{
20+
"ename": "TypeError",
21+
"evalue": "Pipeline.__init__() missing 4 required positional arguments: 'graph_dot', 'metadata', 'input_spec', and 'output_spec'",
22+
"output_type": "error",
23+
"traceback": [
24+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
25+
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
26+
"Cell \u001b[0;32mIn[3], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mop\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mPipeline\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
27+
"\u001b[0;31mTypeError\u001b[0m: Pipeline.__init__() missing 4 required positional arguments: 'graph_dot', 'metadata', 'input_spec', and 'output_spec'"
28+
]
29+
}
30+
],
31+
"source": [
32+
"op.Pipeline()"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"id": "7626744f",
39+
"metadata": {},
40+
"outputs": [],
41+
"source": []
42+
}
43+
],
44+
"metadata": {
45+
"kernelspec": {
46+
"display_name": "orcapod",
47+
"language": "python",
48+
"name": "python3"
49+
},
50+
"language_info": {
51+
"codemirror_mode": {
52+
"name": "ipython",
53+
"version": 3
54+
},
55+
"file_extension": ".py",
56+
"mimetype": "text/x-python",
57+
"name": "python",
58+
"nbconvert_exporter": "python",
59+
"pygments_lexer": "ipython3",
60+
"version": "3.10.18"
61+
}
62+
},
63+
"nbformat": 4,
64+
"nbformat_minor": 5
65+
}

src/core/crypto.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,43 @@ pub fn make_random_hash() -> String {
108108
rand::rng().fill_bytes(&mut bytes);
109109
hex::encode(bytes)
110110
}
111+
112+
#[cfg(test)]
113+
mod tests {
114+
#![expect(clippy::panic_in_result_fn, reason = "OK in tests.")]
115+
use crate::{
116+
core::crypto::{hash_buffer, hash_dir, hash_file},
117+
uniffi::error::Result,
118+
};
119+
use std::fs::read;
120+
121+
#[test]
122+
fn consistent_hash() -> Result<()> {
123+
let filepath = "./tests/extra/data/images/subject.jpeg";
124+
assert_eq!(
125+
hash_file(filepath)?,
126+
hash_buffer(&read(filepath)?),
127+
"Checksum not consistent."
128+
);
129+
Ok(())
130+
}
131+
132+
#[test]
133+
fn complex_hash() -> Result<()> {
134+
let dirpath = "./tests/extra/data/images";
135+
assert_eq!(
136+
hash_dir(dirpath)?,
137+
"6c96a478ea25e34fab045bc82858a2980b2cfb22db32e83c01349a8e7ed3b42c".to_owned(),
138+
"Directory checksum didn't match."
139+
);
140+
Ok(())
141+
}
142+
143+
#[test]
144+
fn internal_invalid_filepath() {
145+
assert!(
146+
hash_file("nonexistent_file.txt").is_err(),
147+
"Did not raise an invalid filepath error."
148+
);
149+
}
150+
}

src/core/mod.rs

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,14 @@
1-
macro_rules! inner_attr_to_each {
2-
{ #!$attr:tt $($it:item)* } => {
3-
$(
4-
#$attr
5-
$it
6-
)*
7-
}
8-
}
9-
101
pub(crate) mod error;
112
pub(crate) mod graph;
123
pub(crate) mod store;
134
pub(crate) mod util;
145
pub(crate) mod validation;
156

16-
inner_attr_to_each! {
17-
#![cfg(feature = "default")]
18-
pub(crate) mod crypto;
19-
pub(crate) mod model;
20-
pub(crate) mod operator;
21-
pub(crate) mod orchestrator;
22-
pub(crate) mod pipeline_runner;
23-
}
7+
pub(crate) mod crypto;
8+
/// Model definition for orcapod
9+
pub mod model;
10+
pub(crate) mod operator;
11+
pub(crate) mod orchestrator;
2412

25-
#[cfg(feature = "test")]
26-
inner_attr_to_each! {
27-
#![cfg_attr(
28-
feature = "test",
29-
allow(
30-
missing_docs,
31-
clippy::missing_errors_doc,
32-
clippy::missing_panics_doc,
33-
reason = "Documentation not necessary since private API.",
34-
),
35-
)]
36-
pub mod crypto;
37-
pub mod model;
38-
pub mod orchestrator;
39-
pub mod pipeline_runner;
40-
pub mod operator;
41-
}
13+
/// Pipeline runner module
14+
pub mod pipeline_runner;

src/core/model/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn to_yaml<T: Serialize>(instance: &T) -> Result<String> {
3232
Ok(yaml)
3333
}
3434

35-
pub fn serialize_hashmap<S, K: Ord + Serialize, V: Serialize, BH: BuildHasher>(
35+
pub(crate) fn serialize_hashmap<S, K: Ord + Serialize, V: Serialize, BH: BuildHasher>(
3636
map: &HashMap<K, V, BH>,
3737
serializer: S,
3838
) -> result::Result<S::Ok, S::Error>
@@ -44,7 +44,7 @@ where
4444
}
4545

4646
#[allow(clippy::ref_option, reason = "Serde requires this signature.")]
47-
pub fn serialize_hashmap_option<S, K: Ord + Serialize, V: Serialize, BH: BuildHasher>(
47+
pub(crate) fn serialize_hashmap_option<S, K: Ord + Serialize, V: Serialize, BH: BuildHasher>(
4848
map_option: &Option<HashMap<K, V, BH>>,
4949
serializer: S,
5050
) -> result::Result<S::Ok, S::Error>
@@ -57,5 +57,5 @@ where
5757
sorted.serialize(serializer)
5858
}
5959

60-
pub mod pipeline;
61-
pub mod pod;
60+
pub(crate) mod pipeline;
61+
pub(crate) mod pod;

0 commit comments

Comments
 (0)