Fix conversions.md stubs to work with Py2 as well

This commit is contained in:
Martin Larralde 2018-04-22 01:45:57 +02:00
parent 0963a6052c
commit 4dccd556b7
5 changed files with 43 additions and 31 deletions

View file

@ -26,7 +26,7 @@ num-traits = "0.2"
pyo3cls = { path = "pyo3cls", version = "^0.2.1" }
[dev-dependencies]
docmatic = "^0.1"
docmatic = { version = "^0.1", git = "https://github.com/althonos/docmatic" }
[build-dependencies]
regex = "0.2"

View file

@ -43,13 +43,10 @@ extern crate pyo3;
use pyo3::prelude::*;
# struct SomeObject;
#
# impl SomeObject {
# fn new(py: Python) -> PyObject {
# let builtins = py.import("builtins").unwrap();
# let print = builtins.get("print").unwrap();
# print.to_object(py)
# }
# pyo3::PyDict::new(py).to_object(py)
# }
# }
#
fn main() {
@ -83,19 +80,16 @@ no keywords arguments are provided.
```rust
extern crate pyo3;
use std::collections::HashMap;
use pyo3::prelude::*;
# use std::collections::HashMap;
# struct SomeObject;
#
# impl SomeObject {
# fn new(py: Python) -> PyObject {
# let builtins = py.import("builtins").unwrap();
# let print = builtins.get("print").unwrap();
# print.to_object(py)
# }
# pyo3::PyDict::new(py).to_object(py)
# }
# }
#
fn main() {
# let key1 = "key1";
# let val1 = 1;

View file

@ -5,7 +5,8 @@
You can use the `py_exception!` macro to define a new exception type:
```rust
# #[macro_use] extern crate pyo3;
#[macro_use] extern crate pyo3;
py_exception!(module, MyError);
```
@ -66,7 +67,6 @@ have rust type as well.
# extern crate pyo3;
# use pyo3::prelude::*;
# fn check_for_error() -> bool {false}
#
fn my_func(arg: PyObject) -> PyResult<()> {
if check_for_error() {
Err(exc::ValueError::new("argument is wrong"))
@ -173,7 +173,7 @@ It is possible to use exception defined in python code as native rust types.
for that exception.
```rust
# #[macro_use] extern crate pyo3;
#[macro_use] extern crate pyo3;
use pyo3::prelude::*;
import_exception!(io, UnsupportedOperation);

View file

@ -1,15 +0,0 @@
#![allow(dead_code, unused_variables)]
#![feature(proc_macro, specialization, const_fn, const_align_of, const_size_of)]
extern crate docmatic;
#[test]
fn test_guide() {
let mut guide_path = ::std::path::PathBuf::new();
guide_path.push("guide");
guide_path.push("src");
for entry in guide_path.read_dir().unwrap() {
docmatic::assert_file(entry.unwrap().path());
}
}

33
tests/test_doc.rs Normal file
View file

@ -0,0 +1,33 @@
extern crate docmatic;
use std::path::{Path, PathBuf};
use docmatic::assert_file_with;
fn pypath() -> Option<PathBuf> {
option_env!("PYTHON").map(|py| PathBuf::from(py).join("libs"))
}
fn test_file<P: AsRef<Path>>(path: P) {
let args = if cfg!(windows) {
vec![("--library-path", pypath().unwrap())]
} else {
Vec::new()
};
docmatic::assert_file_with(path, &args);
}
#[test]
fn test_guide() {
let mut guide_path = PathBuf::from("guide").join("src");
for entry in guide_path.read_dir().unwrap() {
test_file(entry.unwrap().path())
}
}
#[test]
fn test_readme() {
test_file(PathBuf::from("README.md"));
}