From 7d565d3a78876dbebd9711c9720364fe9eba7915 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sun, 17 Jun 2018 22:55:48 -0400 Subject: [PATCH] Ignore tests needing relativedelta --- build_pycompat.py | 31 +++++++- src/lib.rs | 14 ++-- tests/pycompat.rs | 190 +++++++++++++++++++++++----------------------- 3 files changed, 134 insertions(+), 101 deletions(-) diff --git a/build_pycompat.py b/build_pycompat.py index 48bd89a..03a6c1d 100644 --- a/build_pycompat.py +++ b/build_pycompat.py @@ -3,12 +3,12 @@ from datetime import datetime tests = { 'test_parse_default': [ - "Thu Sep 25 10:36:28", "Thu Sep 10:36:28", "Thu 10:36:28", + "Thu Sep 25 10:36:28", "Sep 10:36:28", "10:36:28", "10:36", "Sep 2003", "Sep", "2003", "10h36m28.5s", "10h36m28s", "10h36m", "10h", "10 h 36", "10 h 36.5", "36 m 5", "36 m 5 s", "36 m 05", "36 m 05 s", "10h am", "10h pm", "10am", "10pm", "10:00 am", "10:00 pm", "10:00am", "10:00pm", - "10:00a.m", "10:00p.m", "10:00a.m.", "10:00p.m.", "Wed", "Wednesday", + "10:00a.m", "10:00p.m", "10:00a.m.", "10:00p.m.", "October", "31-Dec-00", "0:01:02", "12h 01m02s am", "12:08 PM", "01h02m03", "01h02", "01h02s", "01m02", "01m02h", "2004 10 Apr 11h30m", # testPertain @@ -77,7 +77,10 @@ tests = { 'November 5, 1994, 8:15:30 am EST', '1994-11-05T08:15:30-05:00', '1994-11-05T08:15:30Z', '1976-07-04T00:01:02Z', 'Tue Apr 4 00:22:12 PDT 1995' - ] + ], + 'test_parse_default_ignore': [ + "Thu Sep 10:36:28", "Thu 10:36:28", "Wed", "Wednesday" + ], } def main(): @@ -138,6 +141,13 @@ def test_parse_ignoretz(i, s): d = parse(s, ignoretz=True) return TEST_PARSE_IGNORETZ.format(i=i, d=d, s=s) + +def test_parse_default_ignore(i, s): + default = datetime(2003, 9, 25) + d = parse(s, default=default) + + return TEST_PARSE_DEFAULT_IGNORE.format(i=i, d=d, s=s) + # Here lies all the ugly junk. TEST_HEADER = ''' extern crate chrono; @@ -338,6 +348,21 @@ fn test_parse_ignoretz{i}() {{ None, true, HashMap::new()); }}\n''' +TEST_PARSE_DEFAULT_IGNORE = ''' +#[test] +#[ignore] +fn test_parse_default_ignore{i}() {{ + let info = ParserInfo::default(); + let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); + let pdt = PyDateTime {{ + year: {d.year}, month: {d.month}, day: {d.day}, + hour: {d.hour}, minute: {d.minute}, second: {d.second}, + micros: {d.microsecond}, tzo: None + }}; + parse_and_assert(pdt, info, "{s}", None, None, false, false, + Some(default_rsdate), false, HashMap::new()); +}}\n''' + if __name__ == '__main__': main() \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index ba7a80c..ddd3bf9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,6 +60,7 @@ impl From for ParseInternalError { #[derive(Debug)] pub enum ParseError { + AmbiguousWeekday, InternalError(ParseInternalError), InvalidMonth, UnrecognizedToken(String), @@ -791,7 +792,7 @@ impl Parser { default: Option<&NaiveDateTime>, ignoretz: bool, tzinfos: HashMap, - ) -> Result<(NaiveDateTime, Option, Option>), ParseError> { + ) -> ParseResult<(NaiveDateTime, Option, Option>)> { let default_date = default.unwrap_or(&Local::now().naive_local()).date(); let default_ts = NaiveDateTime::new(default_date, NaiveTime::from_hms(0, 0, 0)); @@ -800,7 +801,7 @@ impl Parser { let (res, tokens) = self.parse_with_tokens(timestr, dayfirst, yearfirst, fuzzy, fuzzy_with_tokens)?; - let naive = self.build_naive(&res, &default_ts); + let naive = self.build_naive(&res, &default_ts)?; if !ignoretz { let offset = self.build_tzaware(&naive, &res, tzinfos)?; @@ -1011,8 +1012,11 @@ impl Parser { } } - fn build_naive(&self, res: &ParsingResult, default: &NaiveDateTime) -> NaiveDateTime { - // TODO: Handle weekday here + fn build_naive(&self, res: &ParsingResult, default: &NaiveDateTime) -> ParseResult { + // TODO: Handle weekday here - dateutils uses relativedelta to accomplish this + if res.weekday.is_some() && res.day.is_none() { + return Err(ParseError::AmbiguousWeekday); + } let y = res.year.unwrap_or(default.year()); let m = res.month.unwrap_or(default.month() as i32) as u32; @@ -1032,7 +1036,7 @@ impl Parser { .unwrap_or(default.timestamp_subsec_micros() as i32) as u32, ); - NaiveDateTime::new(d, t) + Ok(NaiveDateTime::new(d, t)) } fn build_tzaware( diff --git a/tests/pycompat.rs b/tests/pycompat.rs index 288e076..9118b4b 100644 --- a/tests/pycompat.rs +++ b/tests/pycompat.rs @@ -102,38 +102,12 @@ fn test_parse_default1() { hour: 10, minute: 36, second: 28, micros: 0, tzo: None }; - parse_and_assert(pdt, info, "Thu Sep 10:36:28", None, None, false, false, + parse_and_assert(pdt, info, "Sep 10:36:28", None, None, false, false, Some(default_rsdate), false, HashMap::new()); } #[test] fn test_parse_default2() { - let info = ParserInfo::default(); - let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); - let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 28, - micros: 0, tzo: None - }; - parse_and_assert(pdt, info, "Thu 10:36:28", None, None, false, false, - Some(default_rsdate), false, HashMap::new()); -} - -#[test] -fn test_parse_default3() { - let info = ParserInfo::default(); - let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); - let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 28, - micros: 0, tzo: None - }; - parse_and_assert(pdt, info, "Sep 10:36:28", None, None, false, false, - Some(default_rsdate), false, HashMap::new()); -} - -#[test] -fn test_parse_default4() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -146,7 +120,7 @@ fn test_parse_default4() { } #[test] -fn test_parse_default5() { +fn test_parse_default3() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -159,7 +133,7 @@ fn test_parse_default5() { } #[test] -fn test_parse_default6() { +fn test_parse_default4() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -172,7 +146,7 @@ fn test_parse_default6() { } #[test] -fn test_parse_default7() { +fn test_parse_default5() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -185,7 +159,7 @@ fn test_parse_default7() { } #[test] -fn test_parse_default8() { +fn test_parse_default6() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -198,7 +172,7 @@ fn test_parse_default8() { } #[test] -fn test_parse_default9() { +fn test_parse_default7() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -211,7 +185,7 @@ fn test_parse_default9() { } #[test] -fn test_parse_default10() { +fn test_parse_default8() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -224,7 +198,7 @@ fn test_parse_default10() { } #[test] -fn test_parse_default11() { +fn test_parse_default9() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -237,7 +211,7 @@ fn test_parse_default11() { } #[test] -fn test_parse_default12() { +fn test_parse_default10() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -250,7 +224,7 @@ fn test_parse_default12() { } #[test] -fn test_parse_default13() { +fn test_parse_default11() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -263,7 +237,7 @@ fn test_parse_default13() { } #[test] -fn test_parse_default14() { +fn test_parse_default12() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -276,7 +250,7 @@ fn test_parse_default14() { } #[test] -fn test_parse_default15() { +fn test_parse_default13() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -289,7 +263,7 @@ fn test_parse_default15() { } #[test] -fn test_parse_default16() { +fn test_parse_default14() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -302,7 +276,7 @@ fn test_parse_default16() { } #[test] -fn test_parse_default17() { +fn test_parse_default15() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -315,7 +289,7 @@ fn test_parse_default17() { } #[test] -fn test_parse_default18() { +fn test_parse_default16() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -328,7 +302,7 @@ fn test_parse_default18() { } #[test] -fn test_parse_default19() { +fn test_parse_default17() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -341,7 +315,7 @@ fn test_parse_default19() { } #[test] -fn test_parse_default20() { +fn test_parse_default18() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -354,7 +328,7 @@ fn test_parse_default20() { } #[test] -fn test_parse_default21() { +fn test_parse_default19() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -367,7 +341,7 @@ fn test_parse_default21() { } #[test] -fn test_parse_default22() { +fn test_parse_default20() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -380,7 +354,7 @@ fn test_parse_default22() { } #[test] -fn test_parse_default23() { +fn test_parse_default21() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -393,7 +367,7 @@ fn test_parse_default23() { } #[test] -fn test_parse_default24() { +fn test_parse_default22() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -406,7 +380,7 @@ fn test_parse_default24() { } #[test] -fn test_parse_default25() { +fn test_parse_default23() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -419,7 +393,7 @@ fn test_parse_default25() { } #[test] -fn test_parse_default26() { +fn test_parse_default24() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -432,7 +406,7 @@ fn test_parse_default26() { } #[test] -fn test_parse_default27() { +fn test_parse_default25() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -445,7 +419,7 @@ fn test_parse_default27() { } #[test] -fn test_parse_default28() { +fn test_parse_default26() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -458,7 +432,7 @@ fn test_parse_default28() { } #[test] -fn test_parse_default29() { +fn test_parse_default27() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -471,7 +445,7 @@ fn test_parse_default29() { } #[test] -fn test_parse_default30() { +fn test_parse_default28() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -484,33 +458,7 @@ fn test_parse_default30() { } #[test] -fn test_parse_default31() { - let info = ParserInfo::default(); - let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); - let pdt = PyDateTime { - year: 2003, month: 10, day: 1, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None - }; - parse_and_assert(pdt, info, "Wed", None, None, false, false, - Some(default_rsdate), false, HashMap::new()); -} - -#[test] -fn test_parse_default32() { - let info = ParserInfo::default(); - let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); - let pdt = PyDateTime { - year: 2003, month: 10, day: 1, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None - }; - parse_and_assert(pdt, info, "Wednesday", None, None, false, false, - Some(default_rsdate), false, HashMap::new()); -} - -#[test] -fn test_parse_default33() { +fn test_parse_default29() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -523,7 +471,7 @@ fn test_parse_default33() { } #[test] -fn test_parse_default34() { +fn test_parse_default30() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -536,7 +484,7 @@ fn test_parse_default34() { } #[test] -fn test_parse_default35() { +fn test_parse_default31() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -549,7 +497,7 @@ fn test_parse_default35() { } #[test] -fn test_parse_default36() { +fn test_parse_default32() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -562,7 +510,7 @@ fn test_parse_default36() { } #[test] -fn test_parse_default37() { +fn test_parse_default33() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -575,7 +523,7 @@ fn test_parse_default37() { } #[test] -fn test_parse_default38() { +fn test_parse_default34() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -588,7 +536,7 @@ fn test_parse_default38() { } #[test] -fn test_parse_default39() { +fn test_parse_default35() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -601,7 +549,7 @@ fn test_parse_default39() { } #[test] -fn test_parse_default40() { +fn test_parse_default36() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -614,7 +562,7 @@ fn test_parse_default40() { } #[test] -fn test_parse_default41() { +fn test_parse_default37() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -627,7 +575,7 @@ fn test_parse_default41() { } #[test] -fn test_parse_default42() { +fn test_parse_default38() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -640,7 +588,7 @@ fn test_parse_default42() { } #[test] -fn test_parse_default43() { +fn test_parse_default39() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -653,7 +601,7 @@ fn test_parse_default43() { } #[test] -fn test_parse_default44() { +fn test_parse_default40() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -666,7 +614,7 @@ fn test_parse_default44() { } #[test] -fn test_parse_default45() { +fn test_parse_default41() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -679,7 +627,7 @@ fn test_parse_default45() { } #[test] -fn test_parse_default46() { +fn test_parse_default42() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { @@ -1697,3 +1645,59 @@ fn test_parse_ignoretz7() { parse_and_assert(pdt, info, "Tue Apr 4 00:22:12 PDT 1995", None, None, false, false, None, true, HashMap::new()); } + +#[test] +#[ignore] +fn test_parse_default_ignore0() { + let info = ParserInfo::default(); + let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); + let pdt = PyDateTime { + year: 2003, month: 9, day: 25, + hour: 10, minute: 36, second: 28, + micros: 0, tzo: None + }; + parse_and_assert(pdt, info, "Thu Sep 10:36:28", None, None, false, false, + Some(default_rsdate), false, HashMap::new()); +} + +#[test] +#[ignore] +fn test_parse_default_ignore1() { + let info = ParserInfo::default(); + let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); + let pdt = PyDateTime { + year: 2003, month: 9, day: 25, + hour: 10, minute: 36, second: 28, + micros: 0, tzo: None + }; + parse_and_assert(pdt, info, "Thu 10:36:28", None, None, false, false, + Some(default_rsdate), false, HashMap::new()); +} + +#[test] +#[ignore] +fn test_parse_default_ignore2() { + let info = ParserInfo::default(); + let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); + let pdt = PyDateTime { + year: 2003, month: 10, day: 1, + hour: 0, minute: 0, second: 0, + micros: 0, tzo: None + }; + parse_and_assert(pdt, info, "Wed", None, None, false, false, + Some(default_rsdate), false, HashMap::new()); +} + +#[test] +#[ignore] +fn test_parse_default_ignore3() { + let info = ParserInfo::default(); + let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); + let pdt = PyDateTime { + year: 2003, month: 10, day: 1, + hour: 0, minute: 0, second: 0, + micros: 0, tzo: None + }; + parse_and_assert(pdt, info, "Wednesday", None, None, false, false, + Some(default_rsdate), false, HashMap::new()); +}