diff --git a/CHANGELOG.md b/CHANGELOG.md index 799d4ba1758fb4735c35a7a7923e99fd767ee76b..04a5171184bb35417a6eb66aa0739f474adf8b7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Proof-of-concept integration with Bloxberg. - Introduce a cfood that can create a Record structure based on the contents of a hdf5 file h5py is now an optional dependency -- enum_converter for table imports +- string-in-list check for table imports ### Changed ### diff --git a/src/caosadvancedtools/table_importer.py b/src/caosadvancedtools/table_importer.py index 15fb89af503e108aed2343e3d50838b797e31369..dded9edf041a9f2619bd1076181b7c0a1c1c68f6 100755 --- a/src/caosadvancedtools/table_importer.py +++ b/src/caosadvancedtools/table_importer.py @@ -145,7 +145,7 @@ def win_path_converter(val): return path.as_posix() -def enum_converter(val, options, ignore_case=True): +def string_in_list(val, options, ignore_case=True): """Return the given value if it is contained in options, raise an error otherwise. diff --git a/unittests/test_table_importer.py b/unittests/test_table_importer.py index 671fcec61569f4802aa5db78a6b2283f54fb24f5..a360467383b1ec64007da1a0c7cb4657a6b53f28 100644 --- a/unittests/test_table_importer.py +++ b/unittests/test_table_importer.py @@ -33,7 +33,7 @@ from caosadvancedtools.table_importer import (XLSImporter, assure_name_format, incomplete_date_converter, win_path_converter, win_path_list_converter, - enum_converter, + string_in_list, yes_no_converter) @@ -50,14 +50,15 @@ class ConverterTest(unittest.TestCase): self.assertRaises(ValueError, yes_no_converter, "True") self.assertRaises(ValueError, yes_no_converter, "true") - def test_enum(self): - self.assertEqual("false", enum_converter("false", + def test_string_in_list(self): + self.assertEqual("false", string_in_list("false", ["FALSE", "TRUE"])) - self.assertEqual("FALSE", enum_converter("FALSE", + self.assertEqual("FALSE", string_in_list("FALSE", ["FALSE", "TRUE"], False)) - self.assertRaises(ValueError, enum_converter, "FALSE", []) - self.assertRaises(ValueError, enum_converter, "FALSE", ["fals"]) - self.assertRaises(ValueError, enum_converter, "FALSE", ["false"], False) + self.assertRaises(ValueError, string_in_list, "FALSE", []) + self.assertRaises(ValueError, string_in_list, "FALSE", ["fals"]) + self.assertRaises(ValueError, string_in_list, + "FALSE", ["false"], False) def test_assure_name_format(self): self.assertEqual(assure_name_format("Müstermann, Max"), @@ -72,7 +73,7 @@ class ConverterTest(unittest.TestCase): ["/this/computer"]) self.assertEqual(win_path_list_converter( r"\this\computer,\this\computer"), - ["/this/computer", "/this/computer"]) + ["/this/computer", "/this/computer"]) def test_datetime(self): test_file = os.path.join(os.path.dirname(__file__), "date.xlsx")