From cfbd7bd18bd7190c0005174f39993e44ddd08f71 Mon Sep 17 00:00:00 2001 From: Mabroor Ahmed Date: Wed, 19 Feb 2020 12:50:20 +0000 Subject: [PATCH 1/3] Fix bare pytest.raises in test_parsing.py --- pandas/tests/tslibs/test_parsing.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tslibs/test_parsing.py b/pandas/tests/tslibs/test_parsing.py index 1ba7832c47e6c..b322299a9167d 100644 --- a/pandas/tests/tslibs/test_parsing.py +++ b/pandas/tests/tslibs/test_parsing.py @@ -24,7 +24,8 @@ def test_parse_time_string(): def test_parse_time_string_invalid_type(): # Raise on invalid input, don't just return it - with pytest.raises(TypeError): + msg = "Invalid time string provided, unable to parse" + with pytest.raises(TypeError, match=msg): parse_time_string((4, 5)) @@ -217,7 +218,8 @@ def test_try_parse_dates(): def test_parse_time_string_check_instance_type_raise_exception(): # issue 20684 - with pytest.raises(TypeError): + msg = "Invalid time string provided, unable to parse" + with pytest.raises(TypeError, match=msg): parse_time_string((1, 2, 3)) result = parse_time_string("2019") From ca8dd2be22d60fe4c88505a8148ac85b16b73143 Mon Sep 17 00:00:00 2001 From: Mabroor Ahmed Date: Wed, 19 Feb 2020 23:19:37 +0000 Subject: [PATCH 2/3] escape message using regex package --- pandas/tests/tslibs/test_parsing.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/tslibs/test_parsing.py b/pandas/tests/tslibs/test_parsing.py index b322299a9167d..d0e8ec3933edf 100644 --- a/pandas/tests/tslibs/test_parsing.py +++ b/pandas/tests/tslibs/test_parsing.py @@ -2,6 +2,7 @@ Tests for Timestamp parsing, aimed at pandas/_libs/tslibs/parsing.pyx """ from datetime import datetime +import re from dateutil.parser import parse import numpy as np @@ -24,7 +25,7 @@ def test_parse_time_string(): def test_parse_time_string_invalid_type(): # Raise on invalid input, don't just return it - msg = "Invalid time string provided, unable to parse" + msg = re.escape("Argument 'arg' has incorrect type (expected str, got tuple)") with pytest.raises(TypeError, match=msg): parse_time_string((4, 5)) @@ -218,7 +219,7 @@ def test_try_parse_dates(): def test_parse_time_string_check_instance_type_raise_exception(): # issue 20684 - msg = "Invalid time string provided, unable to parse" + msg = re.escape("Argument 'arg' has incorrect type (expected str, got tuple)") with pytest.raises(TypeError, match=msg): parse_time_string((1, 2, 3)) From d9d047e5d1850eeb23637ef166fe3f88db4809d6 Mon Sep 17 00:00:00 2001 From: Mabroor Ahmed Date: Thu, 20 Feb 2020 15:52:52 +0000 Subject: [PATCH 3/3] left message intact and moved escape function --- pandas/tests/tslibs/test_parsing.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/tslibs/test_parsing.py b/pandas/tests/tslibs/test_parsing.py index d0e8ec3933edf..dc7421ea63464 100644 --- a/pandas/tests/tslibs/test_parsing.py +++ b/pandas/tests/tslibs/test_parsing.py @@ -25,8 +25,8 @@ def test_parse_time_string(): def test_parse_time_string_invalid_type(): # Raise on invalid input, don't just return it - msg = re.escape("Argument 'arg' has incorrect type (expected str, got tuple)") - with pytest.raises(TypeError, match=msg): + msg = "Argument 'arg' has incorrect type (expected str, got tuple)" + with pytest.raises(TypeError, match=re.escape(msg)): parse_time_string((4, 5)) @@ -219,8 +219,8 @@ def test_try_parse_dates(): def test_parse_time_string_check_instance_type_raise_exception(): # issue 20684 - msg = re.escape("Argument 'arg' has incorrect type (expected str, got tuple)") - with pytest.raises(TypeError, match=msg): + msg = "Argument 'arg' has incorrect type (expected str, got tuple)" + with pytest.raises(TypeError, match=re.escape(msg)): parse_time_string((1, 2, 3)) result = parse_time_string("2019")