Add tox config for word-count

This commit is contained in:
konstin 2018-10-09 18:21:52 +02:00
parent 39fa3dbbb4
commit 4da9110489
8 changed files with 35 additions and 16 deletions

3
.gitignore vendored
View File

@ -8,6 +8,9 @@ __pycache__/
.cache
.pytest_cache/
dist/
.tox/
.mypy_cache/
.hypothesis/
*.so
*.out

View File

@ -2,7 +2,6 @@
[![Build Status](https://travis-ci.org/PyO3/pyo3.svg?branch=master)](https://travis-ci.org/PyO3/pyo3)
[![Build Status](https://ci.appveyor.com/api/projects/status/github/PyO3/pyo3?branch=master&svg=true)](https://ci.appveyor.com/project/fafhrd91/pyo3)
[![codecov](https://codecov.io/gh/PyO3/pyo3/branch/master/graph/badge.svg)](https://codecov.io/gh/PyO3/pyo3)
[![crates.io](http://meritbadge.herokuapp.com/pyo3)](https://crates.io/crates/pyo3)
[![Join the dev chat](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/PyO3/Lobby)

View File

@ -1,6 +0,0 @@
.pytest_cache
.mypy_cache
.hypothesis
.tox
*.py[co]

View File

@ -24,4 +24,12 @@ There is a benchmark in `tests/test_word_count.py`:
```shell
pytest -v tests
```
## Testing
To test python 2.7, 3.5, 3.6 and 3.7, install tox globally and run
```shell
tox
```

View File

@ -0,0 +1,3 @@
pytest>=3.5.0
setuptools-rust>=0.10.2
pytest-benchmark>=3.1.1

View File

@ -11,8 +11,8 @@ use rayon::prelude::*;
use std::fs;
use std::path::PathBuf;
#[pyclass]
/// Represents a file that can be searched
#[pyclass]
struct WordCounter {
path: PathBuf,
}
@ -66,8 +66,8 @@ fn matches(word: &str, needle: &str) -> bool {
return needle.next().is_none();
}
#[pyfunction]
/// Count the occurences of needle in line, case insensitive
#[pyfunction]
fn count_line(line: &str, needle: &str) -> usize {
let mut total = 0;
for word in line.split(' ') {

View File

@ -0,0 +1,14 @@
[tox]
envlist = py27,
py35,
py36,
py37,
minversion = 3.4.0
skip_missing_interpreters = true
[testenv]
description = Run the unit tests under {basepython}
deps = -rrequirements-dev.txt
usedevelop = True
commands = pip install -e .
pytest tests

View File

@ -1,12 +1,9 @@
// Copyright (c) 2017-present PyO3 Project and Contributors
use std;
use std::ffi::CString;
use ffi;
use libc::c_int;
static NO_PY_METHODS: &'static [PyMethodDefType] = &[];
use std;
use std::ffi::CString;
/// `PyMethodDefType` represents different types of python callable objects.
/// It is used by `#[pymethods]` and `#[pyproto]` annotations.
@ -123,9 +120,10 @@ impl PySetterDef {
}
#[doc(hidden)]
/// The pymethods macro implements this trait so the methods are added to the object
pub trait PyMethodsProtocolImpl {
fn py_methods() -> &'static [PyMethodDefType] {
NO_PY_METHODS
&[]
}
}
@ -134,7 +132,7 @@ impl<T> PyMethodsProtocolImpl for T {}
#[doc(hidden)]
pub trait PyPropMethodsProtocolImpl {
fn py_methods() -> &'static [PyMethodDefType] {
NO_PY_METHODS
&[]
}
}