1
0
mirror of https://github.com/bspeice/dtparse synced 2025-07-01 13:56:12 -04:00

Move tests to pyo3

Codegen wasn't doing much for me
This commit is contained in:
Bradlee Speice
2018-05-27 13:51:23 -04:00
parent b2626d971a
commit 17b8b8af36
7 changed files with 35 additions and 173 deletions

View File

@ -8,6 +8,9 @@ extern crate chrono;
extern crate num_traits;
extern crate rust_decimal;
#[cfg(test)]
extern crate pyo3;
use chrono::DateTime;
use chrono::Datelike;
use chrono::FixedOffset;

28
src/tests.rs Normal file
View File

@ -0,0 +1,28 @@
use pyo3::ObjectProtocol;
use pyo3::PyDict;
use pyo3::PyList;
use pyo3::PyObject;
use pyo3::Python;
use pyo3::FromPyObject;
macro_rules! test_split {
($py: ident, $timelex: ident, $s: expr, $expected: expr) => {
let f = $timelex.call_method1($py, "split", $s).unwrap();
let l: &PyList = f.extract($py).unwrap();
let s: Vec<String> = l.iter().map(|i| format!("{}", i)).collect();
assert_eq!(s, $expected);
};
}
#[test]
fn test_split() {
let gil = Python::acquire_gil();
let py = gil.python();
let module = py.import("dateutil.parser").unwrap();
let t: PyObject = module.get("_timelex").unwrap().extract().unwrap();
test_split!(py, t, "24, 50, ABC", vec!["24", ",", " ", "50", ",", " ", "ABC"]);
test_split!(py, t, "2018.5.15", vec!["2018", ".", "5", ".", "15"]);
}

View File

@ -1,41 +0,0 @@
// WARNING
// This file was auto-generated using the `build_tests.py` script.
// Please do not edit it manually.
use chrono::SecondsFormat;
use parse;
#[test]
fn test_python_compat() {
assert_eq!(
parse("2018.5.15".to_owned())
.unwrap()
.to_rfc3339_opts(SecondsFormat::Micros, false),
"2018-05-15 04:00:00+00:00"
);
assert_eq!(
parse("May 5, 2018".to_owned())
.unwrap()
.to_rfc3339_opts(SecondsFormat::Micros, false),
"2018-05-05 04:00:00+00:00"
);
assert_eq!(
parse("Mar. 5, 2018".to_owned())
.unwrap()
.to_rfc3339_opts(SecondsFormat::Micros, false),
"2018-03-05 05:00:00+00:00"
);
assert_eq!(
parse("19990101T23".to_owned())
.unwrap()
.to_rfc3339_opts(SecondsFormat::Micros, false),
"1999-01-02 04:00:00+00:00"
);
assert_eq!(
parse("19990101T2359".to_owned())
.unwrap()
.to_rfc3339_opts(SecondsFormat::Micros, false),
"1999-01-02 04:59:00+00:00"
);
}

View File

@ -1,50 +0,0 @@
// WARNING
// This file was auto-generated using the `build_tests.py` script.
// Please do not edit it manually.
use tokenize;
#[test]
fn test_python_compat() {
assert_eq!(
tokenize("2018.5.15"),
vec![
"2018".to_owned(),
".".to_owned(),
"5".to_owned(),
".".to_owned(),
"15".to_owned(),
]
);
assert_eq!(
tokenize("May 5, 2018"),
vec![
"May".to_owned(),
" ".to_owned(),
"5".to_owned(),
",".to_owned(),
" ".to_owned(),
"2018".to_owned(),
]
);
assert_eq!(
tokenize("Mar. 5, 2018"),
vec![
"Mar".to_owned(),
".".to_owned(),
" ".to_owned(),
"5".to_owned(),
",".to_owned(),
" ".to_owned(),
"2018".to_owned(),
]
);
assert_eq!(
tokenize("19990101T23"),
vec!["19990101".to_owned(), "T".to_owned(), "23".to_owned()]
);
assert_eq!(
tokenize("19990101T2359"),
vec!["19990101".to_owned(), "T".to_owned(), "2359".to_owned()]
);
}

View File

@ -1,2 +0,0 @@
mod compat_parse;
mod compat_split_string;