Revision: 1315b15a894e
Author: Pekka Klärck
Date: Sun Jan 1 15:10:26 2012
Log: rename method
http://code.google.com/p/robotframework/source/detail?r=1315b15a894e
Modified:
/src/robot/utils/importer.py
/src/robot/variables/variables.py
/utest/utils/test_importer_util.py
=======================================
--- /src/robot/utils/importer.py Sun Jan 1 13:38:22 2012
+++ /src/robot/utils/importer.py Sun Jan 1 15:10:26 2012
@@ -26,7 +26,6 @@
# TODO:
-# - rename module
# - test and possibly prune tracebacks
# - test PYTHONPATH and CLASSPATH
# - split logic related to different import types to helper classes
@@ -42,7 +41,7 @@
self._type = type or ''
self._logger = logger
- def import_module_by_path(self, path):
+ def import_class_or_module_by_path(self, path):
"""Import a Python module or Java class using a file system path.
When importing a Python file, the path must end with '.py' and the
=======================================
--- /src/robot/variables/variables.py Thu Dec 22 04:36:26 2011
+++ /src/robot/variables/variables.py Sun Jan 1 15:10:26 2012
@@ -230,7 +230,7 @@
def set_from_file(self, path, args=None, overwrite=False):
LOGGER.info("Importing variable file '%s' with args %s" % (path,
args))
args = args or []
- module = self._importer.import_module_by_path(path)
+ module = self._importer.import_class_or_module_by_path(path)
try:
variables = self._get_variables_from_module(module, args)
self._set_from_file(variables, overwrite, path)
=======================================
--- /utest/utils/test_importer_util.py Sun Jan 1 13:38:22 2012
+++ /utest/utils/test_importer_util.py Sun Jan 1 15:10:26 2012
@@ -70,7 +70,7 @@
def test_import_class_from_file(self):
path = self._create_file('test.py', extra_content='class test:\n
def m(s): return 1')
- klass = Importer().import_module_by_path(path)
+ klass = Importer().import_class_or_module_by_path(path)
assert_true(inspect.isclass(klass))
assert_equals(klass.__name__, 'test')
assert_equals(klass().m(), 1)
@@ -83,13 +83,13 @@
def test_logging_when_importing_module(self):
logger = LoggerStub()
path = join(LIBDIR, 'classes.py')
- Importer('test library', logger).import_module_by_path(path)
+ Importer('test library',
logger).import_class_or_module_by_path(path)
logger.assert_message("Imported test library module 'classes'
from '%s'." % path)
def test_logging_when_importing_python_class(self):
logger = LoggerStub()
path = join(LIBDIR, 'ExampleLibrary.py')
- Importer(logger=logger).import_module_by_path(path)
+ Importer(logger=logger).import_class_or_module_by_path(path)
logger.assert_message("Imported class 'ExampleLibrary'
from '%s'." % path)
if sys.platform.startswith('java'):
@@ -108,7 +108,7 @@
def test_logging_when_importing_java_class(self):
logger = LoggerStub()
path = join(CURDIR, 'ImportByPath.java')
- Importer('java', logger).import_module_by_path(path)
+ Importer('java', logger).import_class_or_module_by_path(path)
logger.assert_message("Imported java class 'ImportByPath'
from '%s'." % path)
def _create_file(self, name, attr=42, extra_content=''):
@@ -129,7 +129,7 @@
def _import(self, path):
sys_path_before = sys.path[:]
try:
- return Importer().import_module_by_path(path)
+ return Importer().import_class_or_module_by_path(path)
finally:
assert_equals(sys.path, sys_path_before)
@@ -139,18 +139,18 @@
def test_non_existing(self):
assert_raises_with_msg(DataError,
"Importing 'non-existing.py' failed: File or directory does
not exist.",
- Importer().import_module_by_path, 'non-existing.py')
+ Importer().import_class_or_module_by_path, 'non-existing.py')
assert_raises_with_msg(DataError,
"Importing test file 'non-existing.py' failed: File or
directory does not exist.",
- Importer('test file').import_module_by_path, 'non-existing.py')
+ Importer('test
file').import_class_or_module_by_path, 'non-existing.py')
def test_invalid_format(self):
assert_raises_with_msg(DataError,
"Importing '%s' failed: Not a valid file or directory to
import." % CURDIR,
- Importer().import_module_by_path, CURDIR)
+ Importer().import_class_or_module_by_path, CURDIR)
assert_raises_with_msg(DataError,
"Importing xxx '%s' failed: Not a valid file or directory to
import." % CURDIR,
- Importer('xxx').import_module_by_path, CURDIR)
+ Importer('xxx').import_class_or_module_by_path, CURDIR)
class TestImportClassOrModule(unittest.TestCase):