Fix make test

This is a follow-up to #147
This commit is contained in:
konstin 2018-05-01 20:15:43 +02:00
parent e3b74498c8
commit 5a8f5034d6
6 changed files with 24 additions and 6 deletions

2
.gitignore vendored
View File

@ -5,6 +5,8 @@ Cargo.lock
build/
__pycache__/
.cache
.pytest_cache/
dist/
*.so
*.out

View File

@ -23,7 +23,7 @@ log = "0.4"
libc = "0.2"
spin = "0.4.6"
num-traits = "0.2"
pyo3cls = { version = "^0.2.1" }
pyo3cls = { path = "pyo3cls", version = "^0.2.1" }
[build-dependencies]
regex = "0.2"

View File

@ -34,7 +34,7 @@ pub fn mod2init(attr: TokenStream, input: TokenStream) -> TokenStream {
let mut ast = syn::parse_item(&source).unwrap();
// Build the output
let init = module::build_py2_module_init(&mut ast, attr.to_string());
let init = module::build_py2_module_init(&mut ast, utils::attr_with_parentheses(attr));
// Return the generated impl as a TokenStream
let mut tokens = Tokens::new();
@ -53,7 +53,7 @@ pub fn mod3init(attr: TokenStream, input: TokenStream) -> TokenStream {
let mut ast = syn::parse_item(&source).unwrap();
// Build the output
let init = module::build_py3_module_init(&mut ast, attr.to_string());
let init = module::build_py3_module_init(&mut ast, utils::attr_with_parentheses(attr));
// Return the generated impl as a TokenStream
let mut tokens = Tokens::new();
@ -91,7 +91,7 @@ pub fn class(attr: TokenStream, input: TokenStream) -> TokenStream {
let mut ast = syn::parse_derive_input(&source).unwrap();
// Build the output
let expanded = py_class::build_py_class(&mut ast, attr.to_string());
let expanded = py_class::build_py_class(&mut ast, utils::attr_with_parentheses(attr));
// Return the generated impl as a TokenStream
let mut tokens = Tokens::new();

View File

@ -10,7 +10,7 @@ use utils;
pub fn build_py3_module_init(ast: &mut syn::Item, attr: String) -> Tokens {
let modname = &attr.to_string()[1..attr.to_string().len()-1].to_string();
let modname = &attr[1..attr.len()-1].to_string();
match ast.node {
syn::ItemKind::Fn(_, _, _, _, _, ref mut block) => {
@ -86,7 +86,7 @@ pub fn py3_init(fnname: &syn::Ident, name: &String, doc: syn::Lit) -> Tokens {
}
pub fn build_py2_module_init(ast: &mut syn::Item, attr: String) -> Tokens {
let modname = &attr.to_string()[1..attr.to_string().len()-1].to_string();
let modname = &attr[1..attr.len()-1].to_string();
match ast.node {
syn::ItemKind::Fn(_, _, _, _, _, ref mut block) => {

View File

@ -1,8 +1,23 @@
// Copyright (c) 2017-present PyO3 Project and Contributors
use syn;
use quote::{Tokens, ToTokens};
use proc_macro::TokenStream;
/// https://github.com/rust-lang/rust/pull/50120 removed the parantheses from
/// the attr TokenStream, so we need to re-add them manually.
///
/// nightly-2018-04-05: ( name=CustomName )
/// nightly-2018-04-28: name=CustomName
pub fn attr_with_parentheses(attr: TokenStream) -> String {
let attr = attr.to_string();
if attr.len() > 0 && !attr.starts_with("(") {
return format!("({})", attr);
} else {
return attr;
}
}
pub fn print_err(msg: String, t: Tokens) {
println!("Error: {} in '{}'", msg, t.to_string());
}

View File

@ -36,6 +36,7 @@ fn init_mod(py: Python, m: &PyModule) -> PyResult<()> {
}
#[test]
#[cfg(Py_3)]
fn test_module_with_functions() {
let gil = Python::acquire_gil();
let py = gil.python();