From 57cd80e4710cb8ab4a4c4aa188c354a29881019c Mon Sep 17 00:00:00 2001 From: Jonathan Foster Date: Tue, 19 Sep 2023 11:43:45 -0400 Subject: [PATCH 1/2] Make tests robust to plugins adding new translators --- glue/core/data_factories/tests/test_pandas.py | 6 +++--- glue/core/tests/test_data_translation.py | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/glue/core/data_factories/tests/test_pandas.py b/glue/core/data_factories/tests/test_pandas.py index 815be02d5..478a648cf 100644 --- a/glue/core/data_factories/tests/test_pandas.py +++ b/glue/core/data_factories/tests/test_pandas.py @@ -45,9 +45,9 @@ def test_translator_from_data(): with pytest.raises(ValueError) as exc: df = data.get_object() - assert exc.value.args[0] == ('Specify the object class to use with cls= - supported ' - 'classes are:\n\n* pandas.core.frame.DataFrame') - + # Do not specify full error message in case plugins add new translations + assert 'Specify the object class to use with cls' in exc.value.args[0] + df = data.get_object(cls=DataFrame) assert_equal(list(df.columns), ['a', 'b', 'c']) assert_equal(df['a'].values, [3, 5, 6, 7]) diff --git a/glue/core/tests/test_data_translation.py b/glue/core/tests/test_data_translation.py index 2956cb843..01e95e77b 100644 --- a/glue/core/tests/test_data_translation.py +++ b/glue/core/tests/test_data_translation.py @@ -112,9 +112,8 @@ def test_get_object_explicit_class(self): with pytest.raises(ValueError) as exc: data.get_object() - assert exc.value.args[0] == ('Specify the object class to use with cls= - ' - 'supported classes are:\n\n* pandas.core.frame.DataFrame\n' - '* glue.core.tests.test_data_translation.FakeDataObject') + assert 'Specify the object class to use with cls' in exc.value.args[0] + assert 'glue.core.tests.test_data_translation.FakeDataObject' in exc.value.args[0] obj = data.get_object(cls=FakeDataObject) assert isinstance(obj, FakeDataObject) @@ -142,9 +141,8 @@ def test_get_subset_object_explicit_class(self): with pytest.raises(ValueError) as exc: data.get_subset_object() - assert exc.value.args[0] == ('Specify the object class to use with cls= - ' - 'supported classes are:\n\n* pandas.core.frame.DataFrame\n' - '* glue.core.tests.test_data_translation.FakeDataObject') + assert 'Specify the object class to use with cls' in exc.value.args[0] + assert 'glue.core.tests.test_data_translation.FakeDataObject' in exc.value.args[0] subset = data.get_subset_object(subset_id=0, cls=FakeDataObject) From 298e6f792b495ea45f21de6a3ecc89e9f49cc6e3 Mon Sep 17 00:00:00 2001 From: Jonathan Foster Date: Tue, 19 Sep 2023 12:49:53 -0400 Subject: [PATCH 2/2] Fix codestyle --- glue/core/data_factories/tests/test_pandas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glue/core/data_factories/tests/test_pandas.py b/glue/core/data_factories/tests/test_pandas.py index 478a648cf..57c4d9aea 100644 --- a/glue/core/data_factories/tests/test_pandas.py +++ b/glue/core/data_factories/tests/test_pandas.py @@ -47,7 +47,7 @@ def test_translator_from_data(): df = data.get_object() # Do not specify full error message in case plugins add new translations assert 'Specify the object class to use with cls' in exc.value.args[0] - + df = data.get_object(cls=DataFrame) assert_equal(list(df.columns), ['a', 'b', 'c']) assert_equal(df['a'].values, [3, 5, 6, 7])