Add tox config for word-count
This commit is contained in:
parent
39fa3dbbb4
commit
4da9110489
|
@ -8,6 +8,9 @@ __pycache__/
|
||||||
.cache
|
.cache
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
dist/
|
dist/
|
||||||
|
.tox/
|
||||||
|
.mypy_cache/
|
||||||
|
.hypothesis/
|
||||||
|
|
||||||
*.so
|
*.so
|
||||||
*.out
|
*.out
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/PyO3/pyo3.svg?branch=master)](https://travis-ci.org/PyO3/pyo3)
|
[![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)
|
[![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)
|
[![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)
|
[![Join the dev chat](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/PyO3/Lobby)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
.pytest_cache
|
|
||||||
.mypy_cache
|
|
||||||
.hypothesis
|
|
||||||
.tox
|
|
||||||
|
|
||||||
*.py[co]
|
|
|
@ -24,4 +24,12 @@ There is a benchmark in `tests/test_word_count.py`:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
pytest -v tests
|
pytest -v tests
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
To test python 2.7, 3.5, 3.6 and 3.7, install tox globally and run
|
||||||
|
|
||||||
|
```shell
|
||||||
|
tox
|
||||||
```
|
```
|
|
@ -0,0 +1,3 @@
|
||||||
|
pytest>=3.5.0
|
||||||
|
setuptools-rust>=0.10.2
|
||||||
|
pytest-benchmark>=3.1.1
|
|
@ -11,8 +11,8 @@ use rayon::prelude::*;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[pyclass]
|
|
||||||
/// Represents a file that can be searched
|
/// Represents a file that can be searched
|
||||||
|
#[pyclass]
|
||||||
struct WordCounter {
|
struct WordCounter {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,8 @@ fn matches(word: &str, needle: &str) -> bool {
|
||||||
return needle.next().is_none();
|
return needle.next().is_none();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyfunction]
|
|
||||||
/// Count the occurences of needle in line, case insensitive
|
/// Count the occurences of needle in line, case insensitive
|
||||||
|
#[pyfunction]
|
||||||
fn count_line(line: &str, needle: &str) -> usize {
|
fn count_line(line: &str, needle: &str) -> usize {
|
||||||
let mut total = 0;
|
let mut total = 0;
|
||||||
for word in line.split(' ') {
|
for word in line.split(' ') {
|
||||||
|
|
|
@ -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
|
|
@ -1,12 +1,9 @@
|
||||||
// Copyright (c) 2017-present PyO3 Project and Contributors
|
// Copyright (c) 2017-present PyO3 Project and Contributors
|
||||||
|
|
||||||
use std;
|
|
||||||
use std::ffi::CString;
|
|
||||||
|
|
||||||
use ffi;
|
use ffi;
|
||||||
use libc::c_int;
|
use libc::c_int;
|
||||||
|
use std;
|
||||||
static NO_PY_METHODS: &'static [PyMethodDefType] = &[];
|
use std::ffi::CString;
|
||||||
|
|
||||||
/// `PyMethodDefType` represents different types of python callable objects.
|
/// `PyMethodDefType` represents different types of python callable objects.
|
||||||
/// It is used by `#[pymethods]` and `#[pyproto]` annotations.
|
/// It is used by `#[pymethods]` and `#[pyproto]` annotations.
|
||||||
|
@ -123,9 +120,10 @@ impl PySetterDef {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
/// The pymethods macro implements this trait so the methods are added to the object
|
||||||
pub trait PyMethodsProtocolImpl {
|
pub trait PyMethodsProtocolImpl {
|
||||||
fn py_methods() -> &'static [PyMethodDefType] {
|
fn py_methods() -> &'static [PyMethodDefType] {
|
||||||
NO_PY_METHODS
|
&[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +132,7 @@ impl<T> PyMethodsProtocolImpl for T {}
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub trait PyPropMethodsProtocolImpl {
|
pub trait PyPropMethodsProtocolImpl {
|
||||||
fn py_methods() -> &'static [PyMethodDefType] {
|
fn py_methods() -> &'static [PyMethodDefType] {
|
||||||
NO_PY_METHODS
|
&[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue