Skip to content

Commit

Permalink
Test escaping = in listener/modifier args. robotframework#3809
Browse files Browse the repository at this point in the history
  • Loading branch information
pekkaklarck committed Dec 22, 2020
1 parent 364da4a commit 561fe54
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions utest/utils/test_importer_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 561fe54

Please sign in to comment.