Skip to content

Commit bfc8d68

Browse files
author
Andrew J Westlake
committed
Changed githooks, github actions to run tests with all features
1 parent 6b4937d commit bfc8d68

File tree

8 files changed

+67
-93
lines changed

8 files changed

+67
-93
lines changed

.githooks/pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
cargo check --all-targets --features testing
3+
cargo check --all-targets --all-features

.githooks/pre-push

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22

33
make clippy
4-
cargo test --features testing
4+
make test

.github/workflows/ci.yml

+3-16
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,16 @@ jobs:
8484
name: Prepare LD_LIBRARY_PATH (Ubuntu only)
8585
run: echo LD_LIBRARY_PATH=${pythonLocation}/lib >> $GITHUB_ENV
8686

87-
- name: Build docs
88-
run: cargo doc --no-default-features --features testing --verbose --target ${{ matrix.platform.rust-target }}
89-
9087
- name: Build (no features)
9188
run: cargo build --no-default-features --verbose --target ${{ matrix.platform.rust-target }}
9289

9390
- name: Build (all additive features)
94-
run: cargo build --no-default-features --features testing --verbose --target ${{ matrix.platform.rust-target }}
91+
run: cargo build --all-features --verbose --target ${{ matrix.platform.rust-target }}
9592

9693
# Run tests (except on PyPy, because no embedding API).
9794
- if: matrix.python-version != 'pypy-3.6'
9895
name: Test
99-
run: cargo test --no-default-features --features testing --target ${{ matrix.platform.rust-target }}
100-
101-
# Run tests again, but in abi3 mode
102-
- if: matrix.python-version != 'pypy-3.6'
103-
name: Test (abi3)
104-
run: cargo test --no-default-features --features testing --target ${{ matrix.platform.rust-target }}
105-
106-
# Run tests again, for abi3-py36 (the minimal Python version)
107-
- if: (matrix.python-version != 'pypy-3.6') && (matrix.python-version != '3.6')
108-
name: Test (abi3-py36)
109-
run: cargo test --no-default-features --features testing --target ${{ matrix.platform.rust-target }}
96+
run: cargo test --all-features --target ${{ matrix.platform.rust-target }}
11097

11198
- name: Install python test dependencies
11299
run: |
@@ -138,7 +125,7 @@ jobs:
138125
- uses: actions-rs/cargo@v1
139126
with:
140127
command: test
141-
args: --features testing
128+
args: --all-features
142129
env:
143130
CARGO_INCREMENTAL: 0
144131
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests"

.github/workflows/guide.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
# This adds the docs to gh-pages-build/doc
2222
- name: Build the doc
2323
run: |
24-
cargo doc --no-deps --features testing
24+
cargo doc --no-deps --all-features
2525
mkdir -p gh-pages-build
2626
cp -r target/doc gh-pages-build/doc
2727
echo "<meta http-equiv=refresh content=0;url=pyo3_asyncio/index.html>" > gh-pages-build/doc/index.html

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ lint: fmt clippy
1212
@true
1313

1414
test: lint
15-
cargo test --features async-std-runtime --features tokio-runtime --features testing
15+
cargo test --all-features
1616

1717
publish: test
1818
cargo publish

pytests/common/mod.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use std::{future::Future, thread, time::Duration};
2+
3+
use pyo3::prelude::*;
4+
5+
pub(super) const TEST_MOD: &'static str = r#"
6+
import asyncio
7+
8+
async def py_sleep(duration):
9+
await asyncio.sleep(duration)
10+
11+
async def sleep_for_1s(sleep_for):
12+
await sleep_for(1)
13+
"#;
14+
15+
pub(super) fn test_into_future(
16+
py: Python,
17+
) -> PyResult<impl Future<Output = PyResult<()>> + Send + 'static> {
18+
let test_mod: PyObject =
19+
PyModule::from_code(py, TEST_MOD, "test_rust_coroutine/test_mod.py", "test_mod")?.into();
20+
21+
Ok(async move {
22+
Python::with_gil(|py| {
23+
pyo3_asyncio::into_future(
24+
py,
25+
test_mod
26+
.call_method1(py, "py_sleep", (1.into_py(py),))?
27+
.as_ref(py),
28+
)
29+
})?
30+
.await?;
31+
Ok(())
32+
})
33+
}
34+
35+
pub(super) fn test_blocking_sleep() {
36+
thread::sleep(Duration::from_secs(1));
37+
}

pytests/test_async_std_asyncio.rs

+12-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use std::{future::Future, thread, time::Duration};
1+
mod common;
2+
3+
use std::{future::Future, time::Duration};
24

35
use async_std::task;
46
use pyo3::{prelude::*, wrap_pyfunction};
@@ -18,16 +20,6 @@ fn sleep_for(py: Python, secs: &PyAny) -> PyResult<PyObject> {
1820
})
1921
}
2022

21-
const TEST_MOD: &'static str = r#"
22-
import asyncio
23-
24-
async def py_sleep(duration):
25-
await asyncio.sleep(duration)
26-
27-
async def sleep_for_1s(sleep_for):
28-
await sleep_for(1)
29-
"#;
30-
3123
fn test_into_coroutine(
3224
py: Python,
3325
) -> PyResult<impl Future<Output = PyResult<()>> + Send + 'static> {
@@ -37,8 +29,13 @@ fn test_into_coroutine(
3729
.as_ref(py)
3830
.add_wrapped(wrap_pyfunction!(sleep_for))?;
3931

40-
let test_mod: PyObject =
41-
PyModule::from_code(py, TEST_MOD, "test_rust_coroutine/test_mod.py", "test_mod")?.into();
32+
let test_mod: PyObject = PyModule::from_code(
33+
py,
34+
common::TEST_MOD,
35+
"test_rust_coroutine/test_mod.py",
36+
"test_mod",
37+
)?
38+
.into();
4239

4340
Ok(async move {
4441
Python::with_gil(|py| {
@@ -54,24 +51,6 @@ fn test_into_coroutine(
5451
})
5552
}
5653

57-
fn test_into_future(py: Python) -> PyResult<impl Future<Output = PyResult<()>> + Send + 'static> {
58-
let test_mod: PyObject =
59-
PyModule::from_code(py, TEST_MOD, "test_rust_coroutine/test_mod.py", "test_mod")?.into();
60-
61-
Ok(async move {
62-
Python::with_gil(|py| {
63-
pyo3_asyncio::into_future(
64-
py,
65-
test_mod
66-
.call_method1(py, "py_sleep", (1.into_py(py),))?
67-
.as_ref(py),
68-
)
69-
})?
70-
.await?;
71-
Ok(())
72-
})
73-
}
74-
7554
fn test_async_sleep<'p>(
7655
py: Python<'p>,
7756
) -> PyResult<impl Future<Output = PyResult<()>> + Send + 'static> {
@@ -89,10 +68,6 @@ fn test_async_sleep<'p>(
8968
})
9069
}
9170

92-
fn test_blocking_sleep() {
93-
thread::sleep(Duration::from_secs(1));
94-
}
95-
9671
fn main() {
9772
test_main(
9873
"PyO3 Asyncio Test Suite",
@@ -108,7 +83,7 @@ fn main() {
10883
}),
10984
),
11085
new_sync_test("test_blocking_sleep".into(), || {
111-
test_blocking_sleep();
86+
common::test_blocking_sleep();
11287
Ok(())
11388
}),
11489
Test::new_async(
@@ -124,7 +99,7 @@ fn main() {
12499
Test::new_async(
125100
"test_into_future".into(),
126101
Python::with_gil(|py| {
127-
test_into_future(py)
102+
common::test_into_future(py)
128103
.map_err(|e| {
129104
e.print_and_set_sys_last_vars(py);
130105
})

pytests/test_tokio_asyncio.rs

+11-36
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
mod common;
2+
13
use std::{
24
future::{pending, Future},
35
thread,
@@ -32,16 +34,6 @@ fn sleep_for(py: Python, secs: &PyAny) -> PyResult<PyObject> {
3234
})
3335
}
3436

35-
const TEST_MOD: &'static str = r#"
36-
import asyncio
37-
38-
async def py_sleep(duration):
39-
await asyncio.sleep(duration)
40-
41-
async def sleep_for_1s(sleep_for):
42-
await sleep_for(1)
43-
"#;
44-
4537
fn test_into_coroutine(
4638
py: Python,
4739
) -> PyResult<impl Future<Output = PyResult<()>> + Send + 'static> {
@@ -51,8 +43,13 @@ fn test_into_coroutine(
5143
.as_ref(py)
5244
.add_wrapped(wrap_pyfunction!(sleep_for))?;
5345

54-
let test_mod: PyObject =
55-
PyModule::from_code(py, TEST_MOD, "test_rust_coroutine/test_mod.py", "test_mod")?.into();
46+
let test_mod: PyObject = PyModule::from_code(
47+
py,
48+
common::TEST_MOD,
49+
"test_rust_coroutine/test_mod.py",
50+
"test_mod",
51+
)?
52+
.into();
5653

5754
Ok(async move {
5855
Python::with_gil(|py| {
@@ -68,24 +65,6 @@ fn test_into_coroutine(
6865
})
6966
}
7067

71-
fn test_into_future(py: Python) -> PyResult<impl Future<Output = PyResult<()>> + Send + 'static> {
72-
let test_mod: PyObject =
73-
PyModule::from_code(py, TEST_MOD, "test_rust_coroutine/test_mod.py", "test_mod")?.into();
74-
75-
Ok(async move {
76-
Python::with_gil(|py| {
77-
pyo3_asyncio::into_future(
78-
py,
79-
test_mod
80-
.call_method1(py, "py_sleep", (1.into_py(py),))?
81-
.as_ref(py),
82-
)
83-
})?
84-
.await?;
85-
Ok(())
86-
})
87-
}
88-
8968
fn test_async_sleep<'p>(
9069
py: Python<'p>,
9170
) -> PyResult<impl Future<Output = PyResult<()>> + Send + 'static> {
@@ -103,10 +82,6 @@ fn test_async_sleep<'p>(
10382
})
10483
}
10584

106-
fn test_blocking_sleep() {
107-
thread::sleep(Duration::from_secs(1));
108-
}
109-
11085
fn main() {
11186
thread::spawn(|| {
11287
CURRENT_THREAD_RUNTIME.block_on(pending::<()>());
@@ -127,7 +102,7 @@ fn main() {
127102
}),
128103
),
129104
new_sync_test("test_blocking_sleep".into(), || {
130-
test_blocking_sleep();
105+
common::test_blocking_sleep();
131106
Ok(())
132107
}),
133108
Test::new_async(
@@ -143,7 +118,7 @@ fn main() {
143118
Test::new_async(
144119
"test_into_future".into(),
145120
Python::with_gil(|py| {
146-
test_into_future(py)
121+
common::test_into_future(py)
147122
.map_err(|e| {
148123
e.print_and_set_sys_last_vars(py);
149124
})

0 commit comments

Comments
 (0)