Skip to content

Commit 4fa9eca

Browse files
author
Andrew J Westlake
committed
Discovered that doctests can actually run, tested all feature combinations with cargo hack test --feature-powerset, edited some testing documentation
1 parent f21deac commit 4fa9eca

File tree

8 files changed

+119
-66
lines changed

8 files changed

+119
-66
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ required-features = ["attributes", "tokio-runtime"]
4747
name = "test_async_std_asyncio"
4848
path = "pytests/test_async_std_asyncio.rs"
4949
harness = false
50-
required-features = ["async-std-runtime", "testing"]
50+
required-features = ["async-std-runtime", "testing", "attributes"]
5151

5252
[[test]]
5353
name = "test_async_std_run_forever"
@@ -59,7 +59,7 @@ required-features = ["async-std-runtime", "testing"]
5959
name = "test_tokio_current_thread_asyncio"
6060
path = "pytests/test_tokio_current_thread_asyncio.rs"
6161
harness = false
62-
required-features = ["tokio-runtime", "testing"]
62+
required-features = ["tokio-runtime", "testing", "attributes"]
6363

6464
[[test]]
6565
name = "test_tokio_current_thread_run_forever"
@@ -71,7 +71,7 @@ required-features = ["tokio-runtime", "testing"]
7171
name = "test_tokio_multi_thread_asyncio"
7272
path = "pytests/test_tokio_multi_thread_asyncio.rs"
7373
harness = false
74-
required-features = ["tokio-runtime", "testing"]
74+
required-features = ["tokio-runtime", "testing", "attributes"]
7575

7676
[[test]]
7777
name = "test_tokio_multi_thread_run_forever"

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ lint: fmt clippy
1414
test: lint
1515
cargo test --all-features
1616

17-
publish: test
17+
test-feature-powerset:
18+
cargo install cargo-hack
19+
cargo hack test --feature-powerset
20+
21+
publish: test-feature-powerset
1822
cargo publish

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Here we initialize the runtime, import Python's `asyncio` library and run the gi
2828

2929
More details on the usage of this library can be found in the [API docs](https://awestlake87.github.io/pyo3-asyncio/master/doc).
3030

31-
```rust no_run
31+
```rust
3232
use pyo3::prelude::*;
3333

3434
#[pyo3_asyncio::async_std::main]

src/async_std.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Runtime for AsyncStdRuntime {
5151
///
5252
/// # Examples
5353
///
54-
/// ```no_run
54+
/// ```
5555
/// # use std::time::Duration;
5656
/// #
5757
/// # use pyo3::prelude::*;
@@ -85,7 +85,7 @@ where
8585
///
8686
/// # Examples
8787
///
88-
/// ```no_run
88+
/// ```
8989
/// use std::time::Duration;
9090
///
9191
/// use pyo3::prelude::*;

src/generic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub trait Runtime {
7777
/// #
7878
/// # Python::with_gil(|py| {
7979
/// # pyo3_asyncio::with_runtime(py, || {
80+
/// # #[cfg(feature = "tokio-runtime")]
8081
/// pyo3_asyncio::generic::run_until_complete::<MyCustomRuntime, _>(py, async move {
8182
/// tokio::time::sleep(Duration::from_secs(1)).await;
8283
/// Ok(())

src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,22 @@ use pyo3::{exceptions::PyKeyboardInterrupt, prelude::*, PyNativeType};
115115
/// Test README
116116
#[doc(hidden)]
117117
pub mod doc_test {
118+
#[allow(unused)]
118119
macro_rules! doc_comment {
119120
($x:expr, $module:item) => {
120121
#[doc = $x]
121122
$module
122123
};
123124
}
124125

126+
#[allow(unused)]
125127
macro_rules! doctest {
126128
($x:expr, $y:ident) => {
127129
doc_comment!(include_str!($x), mod $y {});
128130
};
129131
}
130132

133+
#[cfg(feature = "async-std-runtime attributes")]
131134
doctest!("../README.md", readme_md);
132135
}
133136

@@ -151,7 +154,7 @@ static CREATE_FUTURE: OnceCell<PyObject> = OnceCell::new();
151154
///
152155
/// # Examples
153156
///
154-
/// ```no_run
157+
/// ```
155158
/// use pyo3::prelude::*;
156159
///
157160
/// fn main() {
@@ -225,12 +228,13 @@ pub fn get_event_loop(py: Python) -> &PyAny {
225228
///
226229
/// # Examples
227230
///
228-
/// ```no_run
231+
/// ```
229232
/// # use std::time::Duration;
230233
/// # use pyo3::prelude::*;
231234
/// # Python::with_gil(|py| {
232235
/// # pyo3_asyncio::with_runtime(py, || {
233236
/// // Wait 1 second, then stop the event loop
237+
/// # #[cfg(feature = "async-std-runtime")]
234238
/// async_std::task::spawn(async move {
235239
/// async_std::task::sleep(Duration::from_secs(1)).await;
236240
/// Python::with_gil(|py| {
@@ -250,6 +254,7 @@ pub fn get_event_loop(py: Python) -> &PyAny {
250254
/// });
251255
///
252256
/// // block until stop is called
257+
/// # #[cfg(feature = "async-std-runtime")]
253258
/// pyo3_asyncio::run_forever(py)?;
254259
/// # Ok(())
255260
/// # })
@@ -324,7 +329,7 @@ impl PyTaskCompleter {
324329
///
325330
/// # Examples
326331
///
327-
/// ```no_run
332+
/// ```
328333
/// use std::time::Duration;
329334
///
330335
/// use pyo3::prelude::*;
@@ -398,10 +403,10 @@ fn dump_err(py: Python<'_>) -> impl FnOnce(PyErr) + '_ {
398403

399404
/// Alias crate as pyo3_asyncio for test_structs! macro expansion
400405
#[cfg(test)]
401-
#[cfg(feature = "testing")]
406+
#[cfg(feature = "testing attributes")]
402407
use crate as pyo3_asyncio;
403408

404409
// Expand test structs in crate root to allow lib tests to be compile-checked (but not ran)
405410
#[cfg(test)]
406-
#[cfg(feature = "testing")]
411+
#[cfg(feature = "testing attributes")]
407412
testing::test_structs!();

0 commit comments

Comments
 (0)