6 new revisions:

Revision: 60bf89e5e0de
Author:   Pekka Klärck
Date:     Tue Jan  3 04:36:59 2012
Log:      windows test fix
http://code.google.com/p/robotframework/source/detail?r=60bf89e5e0de

Revision: c87a8ee29362
Author:   Pekka Klärck
Date:     Tue Jan  3 05:02:47 2012
Log:      test cleanup
http://code.google.com/p/robotframework/source/detail?r=c87a8ee29362

Revision: ddbe015ba7b1
Author:   Pekka Klärck
Date:     Tue Jan  3 05:54:37 2012
Log:      cleanup
http://code.google.com/p/robotframework/source/detail?r=ddbe015ba7b1

Revision: 608568f71f11
Author:   Pekka Klärck
Date:     Tue Jan  3 06:03:42 2012
Log: import by path: syslog message when module is removed from sys.modules...
http://code.google.com/p/robotframework/source/detail?r=608568f71f11

Revision: ab59e56bc306
Author:   Pekka Klärck
Date:     Tue Jan  3 06:03:57 2012
Log:      Automated merge with https://robotframework.googlecode.com/hg/
http://code.google.com/p/robotframework/source/detail?r=ab59e56bc306

Revision: 26bc023e2d31
Author:   Pekka Klärck
Date:     Tue Jan  3 06:05:18 2012
Log:      test fix
http://code.google.com/p/robotframework/source/detail?r=26bc023e2d31

==============================================================================
Revision: 60bf89e5e0de
Author:   Pekka Klärck
Date:     Tue Jan  3 04:36:59 2012
Log:      windows test fix
http://code.google.com/p/robotframework/source/detail?r=60bf89e5e0de

Modified:
 /utest/utils/test_importer_util.py

=======================================
--- /utest/utils/test_importer_util.py  Mon Jan  2 14:42:34 2012
+++ /utest/utils/test_importer_util.py  Tue Jan  3 04:36:59 2012
@@ -5,6 +5,7 @@
 import shutil
 import sys
 import os
+import re
 from os.path import abspath, dirname, exists, isabs, join, normpath

 from robot.errors import DataError
@@ -17,10 +18,13 @@
LIBDIR = normpath(join(CURDIR, '..', '..', 'atest', 'testresources', 'testlibs'))
 TEMPDIR = tempfile.gettempdir()
 TESTDIR = join(TEMPDIR, 'robot-importer-testing')
+WINDOWS_PATH_IN_ERROR = re.compile(r"'\w:\\")


 def assert_prefix(error, expected):
-    prefix = ':'.join(unicode(error).split(':')[:2]) + ':'
+    message = unicode(error)
+    count = 3 if WINDOWS_PATH_IN_ERROR.search(message) else 2
+    prefix = ':'.join(message.split(':')[:count]) + ':'
     assert_equals(prefix, expected)

 def create_temp_file(name, attr=42, extra_content=''):

==============================================================================
Revision: c87a8ee29362
Author:   Pekka Klärck
Date:     Tue Jan  3 05:02:47 2012
Log:      test cleanup
http://code.google.com/p/robotframework/source/detail?r=c87a8ee29362

Modified:
 /utest/utils/test_importer_util.py

=======================================
--- /utest/utils/test_importer_util.py  Tue Jan  3 04:36:59 2012
+++ /utest/utils/test_importer_util.py  Tue Jan  3 05:02:47 2012
@@ -93,16 +93,14 @@
         assert_prefix(error, "Importing '%s' failed: SyntaxError:" % path)

     def test_logging_when_importing_module(self):
-        logger = LoggerStub()
         path = join(LIBDIR, 'classes.py')
- Importer('test library', logger).import_class_or_module_by_path(path) - logger.assert_message("Imported test library module 'classes' from '%s'." % path)
+        self._import(path, name='lib')
+ self.logger.assert_message("Imported lib module 'classes' from '%s'." % path)

     def test_logging_when_importing_python_class(self):
-        logger = LoggerStub()
         path = join(LIBDIR, 'ExampleLibrary.py')
-        Importer(logger=logger).import_class_or_module_by_path(path)
- logger.assert_message("Imported class 'ExampleLibrary' from '%s'." % path)
+        self._import(path)
+ self.logger.assert_message("Imported class 'ExampleLibrary' from '%s'." % path)

     if sys.platform.startswith('java'):

@@ -118,10 +116,9 @@
                                    self._import, path)

         def test_logging_when_importing_java_class(self):
-            logger = LoggerStub()
             path = join(CURDIR, 'ImportByPath.java')
-            Importer('java', logger).import_class_or_module_by_path(path)
- logger.assert_message("Imported java class 'ImportByPath' from '%s'." % path)
+            self._import(path, name='java')
+ self.logger.assert_message("Imported java class 'ImportByPath' from '%s'." % path)

     def _import_and_verify(self, path, attr=42, directory=TESTDIR):
         module = self._import(path)
@@ -130,10 +127,12 @@
         if hasattr(module, '__file__'):
             assert_equals(dirname(abspath(module.__file__)), directory)

-    def _import(self, path):
+    def _import(self, path, name=None):
+        self.logger = LoggerStub()
+        importer = Importer(name, self.logger)
         sys_path_before = sys.path[:]
         try:
-            return Importer().import_class_or_module_by_path(path)
+            return importer.import_class_or_module_by_path(path)
         finally:
             assert_equals(sys.path, sys_path_before)


==============================================================================
Revision: ddbe015ba7b1
Author:   Pekka Klärck
Date:     Tue Jan  3 05:54:37 2012
Log:      cleanup
http://code.google.com/p/robotframework/source/detail?r=ddbe015ba7b1

Modified:
 /src/robot/utils/importer.py
 /utest/utils/test_importer_util.py

=======================================
--- /src/robot/utils/importer.py        Tue Jan  3 03:42:43 2012
+++ /src/robot/utils/importer.py        Tue Jan  3 05:54:37 2012
@@ -167,11 +167,9 @@

     def _import_by_path(self, path):
         module_dir, module_name = self._split_path_to_module(path)
-        if module_name in sys.modules:
-            del sys.modules[module_name]
         sys.path.insert(0, module_dir)
         try:
-            return self._import(module_name)
+            return self._import_fresh_module(module_name)
         finally:
             sys.path.pop(0)

@@ -180,6 +178,11 @@
         module_name = os.path.splitext(module_file)[0]
         return module_dir, module_name

+    def _import_fresh_module(self, name):
+        if name in sys.modules:
+            del sys.modules[name]
+        return self._import(name)
+

 class NonDottedImporter(_Importer):

=======================================
--- /utest/utils/test_importer_util.py  Tue Jan  3 05:02:47 2012
+++ /utest/utils/test_importer_util.py  Tue Jan  3 05:54:37 2012
@@ -70,13 +70,13 @@
         create_temp_file('__init__.py')
         self._import_and_verify(TESTDIR + os.sep)

-    def test_import_different_file_with_same_name(self):
+    def test_import_different_file_and_directory_with_same_name(self):
         path1 = create_temp_file('test.py', attr=1)
         self._import_and_verify(path1, attr=1)
         path2 = join(TESTDIR, 'test')
         os.mkdir(path2)
         create_temp_file(join(path2, '__init__.py'), attr=2)
-        self._import_and_verify(path2 + '/', attr=2, directory=path2)
+        self._import_and_verify(path2, attr=2, directory=path2)
         path3 = create_temp_file(join(path2, 'test.py'), attr=3)
         self._import_and_verify(path3, attr=3, directory=path2)


==============================================================================
Revision: 608568f71f11
Author:   Pekka Klärck
Date:     Tue Jan  3 06:03:42 2012
Log: import by path: syslog message when module is removed from sys.modules -- this makes debugging possible problems (like in issue 979) easier
http://code.google.com/p/robotframework/source/detail?r=608568f71f11

Modified:
 /src/robot/utils/importer.py
 /utest/utils/test_importer_util.py

=======================================
--- /src/robot/utils/importer.py        Tue Jan  3 05:54:37 2012
+++ /src/robot/utils/importer.py        Tue Jan  3 06:03:42 2012
@@ -38,7 +38,9 @@
             from robot.output import LOGGER as logger
         self._type = type or ''
         self._logger = logger
- self._importers = [ByPathImporter(), NonDottedImporter(), DottedImporter()]
+        self._importers = (ByPathImporter(logger),
+                           NonDottedImporter(logger),
+                           DottedImporter(logger))
         self._by_path_importer = self._importers[0]

     def import_class_or_module(self, name):
@@ -117,6 +119,9 @@

 class _Importer(object):

+    def __init__(self, logger):
+        self._logger = logger
+
     def _import(self, name, fromlist=None, retry=True):
         try:
             try:
@@ -181,6 +186,8 @@
     def _import_fresh_module(self, name):
         if name in sys.modules:
             del sys.modules[name]
+ self._logger.info("Removed module '%s' from sys.modules to import "
+                              "fresh module." % name)
         return self._import(name)


=======================================
--- /utest/utils/test_importer_util.py  Tue Jan  3 05:54:37 2012
+++ /utest/utils/test_importer_util.py  Tue Jan  3 06:03:42 2012
@@ -49,8 +49,8 @@
                 msg = msg.replace(ext, '')
         self.messages.append(msg)

-    def assert_message(self, msg):
-        assert_equals(self.messages, [msg])
+    def assert_message(self, msg, index=0):
+        assert_equals(self.messages[index], msg)


 class TestImportByPath(unittest.TestCase):
@@ -71,14 +71,21 @@
         self._import_and_verify(TESTDIR + os.sep)

     def test_import_different_file_and_directory_with_same_name(self):
+ removed = "Removed module 'test' from sys.modules to import fresh module."
+        imported = "Imported module 'test' from '%s'."
         path1 = create_temp_file('test.py', attr=1)
         self._import_and_verify(path1, attr=1)
+        self.logger.assert_message(imported % path1, index=-1)
         path2 = join(TESTDIR, 'test')
         os.mkdir(path2)
         create_temp_file(join(path2, '__init__.py'), attr=2)
         self._import_and_verify(path2, attr=2, directory=path2)
+        self.logger.assert_message(removed)
+        self.logger.assert_message(imported % path2, index=1)
         path3 = create_temp_file(join(path2, 'test.py'), attr=3)
         self._import_and_verify(path3, attr=3, directory=path2)
+        self.logger.assert_message(removed)
+        self.logger.assert_message(imported % path3, index=1)

     def test_import_class_from_file(self):
path = create_temp_file('test.py', extra_content='class test:\n def m(s): return 1')

==============================================================================
Revision: ab59e56bc306
Author:   Pekka Klärck
Date:     Tue Jan  3 06:03:57 2012
Log:      Automated merge with https://robotframework.googlecode.com/hg/
http://code.google.com/p/robotframework/source/detail?r=ab59e56bc306



==============================================================================
Revision: 26bc023e2d31
Author:   Pekka Klärck
Date:     Tue Jan  3 06:05:18 2012
Log:      test fix
http://code.google.com/p/robotframework/source/detail?r=26bc023e2d31

Modified:
 /utest/utils/test_importer_util.py

=======================================
--- /utest/utils/test_importer_util.py  Tue Jan  3 06:03:42 2012
+++ /utest/utils/test_importer_util.py  Tue Jan  3 06:05:18 2012
@@ -49,7 +49,7 @@
                 msg = msg.replace(ext, '')
         self.messages.append(msg)

-    def assert_message(self, msg, index=0):
+    def assert_message(self, msg, index=-1):
         assert_equals(self.messages[index], msg)


@@ -75,16 +75,16 @@
         imported = "Imported module 'test' from '%s'."
         path1 = create_temp_file('test.py', attr=1)
         self._import_and_verify(path1, attr=1)
-        self.logger.assert_message(imported % path1, index=-1)
+        self.logger.assert_message(imported % path1)
         path2 = join(TESTDIR, 'test')
         os.mkdir(path2)
         create_temp_file(join(path2, '__init__.py'), attr=2)
         self._import_and_verify(path2, attr=2, directory=path2)
-        self.logger.assert_message(removed)
+        self.logger.assert_message(removed, index=0)
         self.logger.assert_message(imported % path2, index=1)
         path3 = create_temp_file(join(path2, 'test.py'), attr=3)
         self._import_and_verify(path3, attr=3, directory=path2)
-        self.logger.assert_message(removed)
+        self.logger.assert_message(removed, index=0)
         self.logger.assert_message(imported % path3, index=1)

     def test_import_class_from_file(self):

Reply via email to