From 6e26fff583419ae65829c7820bcf788f8a4f1b31 Mon Sep 17 00:00:00 2001 From: Mark Graham Date: Thu, 19 Nov 2020 11:59:14 +0000 Subject: [PATCH 1/3] add messages to assert --- pandas/tests/io/pytables/test_timezones.py | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/pandas/tests/io/pytables/test_timezones.py b/pandas/tests/io/pytables/test_timezones.py index 8c8de77990a52..7103c4cfac8ea 100644 --- a/pandas/tests/io/pytables/test_timezones.py +++ b/pandas/tests/io/pytables/test_timezones.py @@ -1,4 +1,5 @@ import datetime +import re import numpy as np import pytest @@ -82,7 +83,13 @@ def test_append_with_timezones_dateutil(setup_path): ), index=range(5), ) - with pytest.raises(ValueError): + + msg = re.escape( + "invalid info for [values_block_1] for [tz], " + "existing_value [dateutil//usr/share/zoneinfo/US/Eastern] " + "conflicts with new value [dateutil//usr/share/zoneinfo/EET]" + ) + with pytest.raises(ValueError, match=msg): store.append("df_tz", df) # this is ok @@ -100,7 +107,13 @@ def test_append_with_timezones_dateutil(setup_path): ), index=range(5), ) - with pytest.raises(ValueError): + + msg = re.escape( + "invalid info for [B] for [tz], " + "existing_value [dateutil//usr/share/zoneinfo/EET] " + "conflicts with new value [dateutil//usr/share/zoneinfo/CET]" + ) + with pytest.raises(ValueError, match=msg): store.append("df_tz", df) # as index @@ -169,7 +182,12 @@ def test_append_with_timezones_pytz(setup_path): ), index=range(5), ) - with pytest.raises(ValueError): + + msg = re.escape( + "invalid info for [values_block_1] for [tz], " + "existing_value [US/Eastern] conflicts with new value [EET]" + ) + with pytest.raises(ValueError, match=msg): store.append("df_tz", df) # this is ok @@ -187,7 +205,12 @@ def test_append_with_timezones_pytz(setup_path): ), index=range(5), ) - with pytest.raises(ValueError): + + msg = re.escape( + "invalid info for [B] for [tz], " + "existing_value [EET] conflicts with new value [CET]" + ) + with pytest.raises(ValueError, match=msg): store.append("df_tz", df) # as index From 3f0da3356fb6853a9c9e2d3d60b87d7fe90d0d6a Mon Sep 17 00:00:00 2001 From: Mark Graham Date: Fri, 20 Nov 2020 11:13:07 +0000 Subject: [PATCH 2/3] generalise message to pass test --- pandas/tests/io/pytables/test_timezones.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/tests/io/pytables/test_timezones.py b/pandas/tests/io/pytables/test_timezones.py index 7103c4cfac8ea..1c039aa6437fe 100644 --- a/pandas/tests/io/pytables/test_timezones.py +++ b/pandas/tests/io/pytables/test_timezones.py @@ -84,10 +84,10 @@ def test_append_with_timezones_dateutil(setup_path): index=range(5), ) - msg = re.escape( - "invalid info for [values_block_1] for [tz], " - "existing_value [dateutil//usr/share/zoneinfo/US/Eastern] " - "conflicts with new value [dateutil//usr/share/zoneinfo/EET]" + msg = ( + r"invalid info for \[values_block_1\] for \[tz\], " + r"existing_value \[dateutil/.*US/Eastern\] " + r"conflicts with new value \[dateutil/.*EET\]" ) with pytest.raises(ValueError, match=msg): store.append("df_tz", df) @@ -108,10 +108,10 @@ def test_append_with_timezones_dateutil(setup_path): index=range(5), ) - msg = re.escape( - "invalid info for [B] for [tz], " - "existing_value [dateutil//usr/share/zoneinfo/EET] " - "conflicts with new value [dateutil//usr/share/zoneinfo/CET]" + msg = ( + r"invalid info for \[B\] for \[tz\], " + r"existing_value \[dateutil/.*EET\] " + r"conflicts with new value \[dateutil/.*CET\]" ) with pytest.raises(ValueError, match=msg): store.append("df_tz", df) From ed87d3094d80321064b7b6e0df580eb930e3900f Mon Sep 17 00:00:00 2001 From: Mark Graham Date: Fri, 20 Nov 2020 11:15:27 +0000 Subject: [PATCH 3/3] make regex consistent within file --- pandas/tests/io/pytables/test_timezones.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pandas/tests/io/pytables/test_timezones.py b/pandas/tests/io/pytables/test_timezones.py index 1c039aa6437fe..98a2b18d59b09 100644 --- a/pandas/tests/io/pytables/test_timezones.py +++ b/pandas/tests/io/pytables/test_timezones.py @@ -1,5 +1,4 @@ import datetime -import re import numpy as np import pytest @@ -183,9 +182,9 @@ def test_append_with_timezones_pytz(setup_path): index=range(5), ) - msg = re.escape( - "invalid info for [values_block_1] for [tz], " - "existing_value [US/Eastern] conflicts with new value [EET]" + msg = ( + r"invalid info for \[values_block_1\] for \[tz\], " + r"existing_value \[US/Eastern\] conflicts with new value \[EET\]" ) with pytest.raises(ValueError, match=msg): store.append("df_tz", df) @@ -206,9 +205,9 @@ def test_append_with_timezones_pytz(setup_path): index=range(5), ) - msg = re.escape( - "invalid info for [B] for [tz], " - "existing_value [EET] conflicts with new value [CET]" + msg = ( + r"invalid info for \[B\] for \[tz\], " + r"existing_value \[EET\] conflicts with new value \[CET\]" ) with pytest.raises(ValueError, match=msg): store.append("df_tz", df)