From 561fe549a4e23f992f0124905a228dc05d3f7012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pekka=20Kl=C3=A4rck?= Date: Tue, 22 Dec 2020 18:56:30 +0200 Subject: [PATCH] Test escaping = in listener/modifier args. #3809 --- utest/utils/test_importer_util.py | 49 +++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/utest/utils/test_importer_util.py b/utest/utils/test_importer_util.py index c423b7383d9..12f8046918e 100644 --- a/utest/utils/test_importer_util.py +++ b/utest/utils/test_importer_util.py @@ -185,31 +185,43 @@ class TestInvalidImportPath(unittest.TestCase): def test_non_existing(self): path = 'non-existing.py' - assert_raises_with_msg(DataError, + assert_raises_with_msg( + DataError, "Importing '%s' failed: File or directory does not exist." % path, - Importer().import_class_or_module_by_path, path) + Importer().import_class_or_module_by_path, path + ) path = abspath(path) - assert_raises_with_msg(DataError, + assert_raises_with_msg( + DataError, "Importing test file '%s' failed: File or directory does not exist." % path, - Importer('test file').import_class_or_module_by_path, path) + Importer('test file').import_class_or_module_by_path, path + ) def test_non_absolute(self): path = os.listdir('.')[0] - assert_raises_with_msg(DataError, + assert_raises_with_msg( + DataError, "Importing '%s' failed: Import path must be absolute." % path, - Importer().import_class_or_module_by_path, path) - assert_raises_with_msg(DataError, + Importer().import_class_or_module_by_path, path + ) + assert_raises_with_msg( + DataError, "Importing file '%s' failed: Import path must be absolute." % path, - Importer('file').import_class_or_module_by_path, path) + Importer('file').import_class_or_module_by_path, path + ) def test_invalid_format(self): path = join(CURDIR, '..', '..', 'README.rst') - assert_raises_with_msg(DataError, + assert_raises_with_msg( + DataError, "Importing '%s' failed: Not a valid file or directory to import." % path, - Importer().import_class_or_module_by_path, path) - assert_raises_with_msg(DataError, + Importer().import_class_or_module_by_path, path + ) + assert_raises_with_msg( + DataError, "Importing xxx '%s' failed: Not a valid file or directory to import." % path, - Importer('xxx').import_class_or_module_by_path, path) + Importer('xxx').import_class_or_module_by_path, path + ) class TestImportClassOrModule(unittest.TestCase): @@ -473,6 +485,19 @@ def test_named_arguments(self): ['default=b', 'mandatory=a']) assert_equal(lib.get_args(), ('a', 'b', '')) + def test_escape_equals(self): + lib = Importer().import_class_or_module('libswithargs.Mixed', + ['default\=b', 'mandatory\=a']) + assert_equal(lib.get_args(), ('default\=b', 'mandatory\=a', '')) + lib = Importer().import_class_or_module('libswithargs.Mixed', + ['default\=b', 'default=a']) + assert_equal(lib.get_args(), ('default\=b', 'a', '')) + + def test_escaping_not_needed_if_args_do_not_match_names(self): + lib = Importer().import_class_or_module('libswithargs.Mixed', + ['foo=b', 'bar=a']) + assert_equal(lib.get_args(), ('foo=b', 'bar=a', '')) + def test_arguments_when_importing_by_path(self): path = create_temp_file('args.py', extra_content=''' class args: