5 new revisions:

Revision: 49f0138dbbfe
Author:   Janne Härkönen <[email protected]>
Date:     Wed Apr 20 03:10:54 2011
Log:      refactoring
http://code.google.com/p/robotframework/source/detail?r=49f0138dbbfe

Revision: 4bc2a40e5d58
Author:   Janne Härkönen <[email protected]>
Date:     Wed Apr 20 03:45:30 2011
Log:      log types of arguments to Should (Not) Be Equal
http://code.google.com/p/robotframework/source/detail?r=4bc2a40e5d58

Revision: 151abcd4e1f7
Author:   Janne Härkönen <[email protected]>
Date:     Wed Apr 20 03:52:57 2011
Log:      assert: Better error message for fail_unless...
http://code.google.com/p/robotframework/source/detail?r=151abcd4e1f7

Revision: eb982a60ffcc
Author:   Janne Härkönen <[email protected]>
Date:     Wed Apr 20 03:53:18 2011
Log:      test for having types in error messages of fail_unless()
http://code.google.com/p/robotframework/source/detail?r=eb982a60ffcc

Revision: c66da8787c2c
Author:   Janne Härkönen <[email protected]>
Date:     Wed Apr 20 03:53:30 2011
Log:      merge
http://code.google.com/p/robotframework/source/detail?r=c66da8787c2c

==============================================================================
Revision: 49f0138dbbfe
Author:   Janne Härkönen <[email protected]>
Date:     Wed Apr 20 03:10:54 2011
Log:      refactoring
http://code.google.com/p/robotframework/source/detail?r=49f0138dbbfe

Modified:
 /src/robot/utils/asserts.py

=======================================
--- /src/robot/utils/asserts.py Sun Feb  6 01:24:10 2011
+++ /src/robot/utils/asserts.py Wed Apr 20 03:10:54 2011
@@ -233,10 +233,13 @@
     raise Exception(msg)

 def _report_unequality_failure(obj1, obj2, msg, values, delim, extra=None):
-    if msg is None:
-        msg = '%s %s %s' % (obj1, delim, obj2)
-    elif values is True:
-        msg = '%s: %s %s %s' % (msg, obj1, delim, obj2)
-    if values is True and extra is not None:
+    if not msg:
+        msg = _get_default_message(obj1, obj2, delim)
+    elif values:
+        msg = '%s: %s' % (msg, _get_default_message(obj1, obj2, delim))
+    if values and extra:
         msg += ' ' + extra
     _report_failure(msg)
+
+def _get_default_message(obj1, obj2, delim):
+    return '%s %s %s' % (obj1, delim, obj2)

==============================================================================
Revision: 4bc2a40e5d58
Author:   Janne Härkönen <[email protected]>
Date:     Wed Apr 20 03:45:30 2011
Log:      log types of arguments to Should (Not) Be Equal
http://code.google.com/p/robotframework/source/detail?r=4bc2a40e5d58

Modified:
 /src/robot/libraries/BuiltIn.py

=======================================
--- /src/robot/libraries/BuiltIn.py     Sun Feb  6 01:24:10 2011
+++ /src/robot/libraries/BuiltIn.py     Wed Apr 20 03:45:30 2011
@@ -199,8 +199,13 @@
           string 'False' or 'No Values', the error message is simply `msg`.
         - Otherwise the error message is '`msg`: `first` != `second`'.
         """
+        self._log_types(first, second)
asserts.fail_unless_equal(first, second, msg, self._include_values(values))

+    def _log_types(self, *args):
+        msg = ["Argument types are:"] + [str(type(a)) for a in args]
+        self.log('\n'.join(msg))
+
     def _include_values(self, values):
         if isinstance(values, basestring):
             return values.lower() not in ['no values', 'false']
@@ -212,6 +217,7 @@
See `Should Be Equal` for an explanation on how to override the default
         error message with `msg` and `values`.
         """
+        self._log_types(first, second)
asserts.fail_if_equal(first, second, msg, self._include_values(values))

def should_not_be_equal_as_integers(self, first, second, msg=None, values=True):
@@ -857,7 +863,7 @@
         | Log | This keyword is executed |

         This keyword was added in Robot Framework 2.5. The execution is not
-        continued if the failure is caused by invalid syntax, timeout, or
+        continued if the failure is caused by invalid syntax, timeout, or
         fatal exception.
         """
         try:
@@ -1285,7 +1291,7 @@

Resources imported with this keyword are set into the test suite scope similarly when importing them in the Setting table using the Resource
-        setting.
+        setting.

The given path must be absolute. Forward slashes can be used as path
         separator regardless the operating system.
@@ -1354,7 +1360,7 @@
         argument is only available in Robot Framework 2.1.1 and newer.

         1) If `time` is a floating point number, it is interpreted as
-           seconds since the epoch. This documentation is written about
+           seconds since the epoch. This documentation is written about
            1177654467 seconds after the epoch.

         2) If `time` is a valid timestamp, that time will be used. Valid

==============================================================================
Revision: 151abcd4e1f7
Author:   Janne Härkönen <[email protected]>
Date:     Wed Apr 20 03:52:57 2011
Log:      assert: Better error message for fail_unless

Add type information to error message when values are
different but their string representations are same.
http://code.google.com/p/robotframework/source/detail?r=151abcd4e1f7

Modified:
 /src/robot/utils/asserts.py

=======================================
--- /src/robot/utils/asserts.py Wed Apr 20 03:10:54 2011
+++ /src/robot/utils/asserts.py Wed Apr 20 03:52:57 2011
@@ -242,4 +242,12 @@
     _report_failure(msg)

 def _get_default_message(obj1, obj2, delim):
+    if delim == '!=' and unicode(obj1) == unicode(obj2):
+        return '%s (%s) != %s (%s)' % (obj1, _type_name(obj1),
+                                       obj2, _type_name(obj2))
     return '%s %s %s' % (obj1, delim, obj2)
+
+def _type_name(val):
+    known_types = {int: 'number', long: 'number', float: 'number',
+                   str: 'string', unicode: 'string', bool: 'boolean'}
+    return known_types.get(type(val), type(val).__name__)

==============================================================================
Revision: eb982a60ffcc
Author:   Janne Härkönen <[email protected]>
Date:     Wed Apr 20 03:53:18 2011
Log:      test for having types in error messages of fail_unless()
http://code.google.com/p/robotframework/source/detail?r=eb982a60ffcc

Modified:
 /utest/utils/test_asserts.py

=======================================
--- /utest/utils/test_asserts.py        Sat May 31 07:42:03 2008
+++ /utest/utils/test_asserts.py        Wed Apr 20 03:53:18 2011
@@ -11,11 +11,14 @@
 class MyExc(Exception):
     pass

-class MyEqual:
+class MyEqual(object):
     def __init__(self, attr=None):
         self.attr = attr
     def __eq__(self, obj):
-        return self.attr == obj.attr
+        try:
+            return self.attr == obj.attr
+        except AttributeError:
+            return False
     def __str__(self):
         return str(self.attr)
     __repr__ = __str__
@@ -23,7 +26,7 @@
 def func(msg=None):
     if msg is not None:
         raise ValueError, msg
-
+

 class TestAsserts(unittest.TestCase):

@@ -47,7 +50,7 @@
         except AE, err:
             expected = "Correct exception but wrong message: msg1 != msg2"
             assert_equal(str(err), expected)
-
+
     def test_fail_unless_equal(self):
         fail_unless_equal('str', 'str')
         fail_unless_equal(42, 42, 'hello', True)
@@ -57,7 +60,16 @@
         assert_raises(AE, fail_unless_equal, 42, 43)
         assert_raises(AE, assert_equal, MyEqual('hello'), MyEqual('world'))
         assert_raises(AE, assert_equals, None, True)
-
+
+    def test_fail_unless_equal_with_values_having_same_string_repr(self):
+ for val, type_ in [(1, 'number'), (1L, 'number'), (MyEqual(1), 'MyEqual')]:
+            assert_raises_with_msg(AE, '1 (string) != 1 (%s)' % type_,
+                                   fail_unless_equal, '1', val)
+        assert_raises_with_msg(AE, '1.0 (number) != 1.0 (string)',
+                               fail_unless_equal, 1.0, u'1.0')
+        assert_raises_with_msg(AE, 'True (string) != True (boolean)',
+                               fail_unless_equal, 'True', True)
+
     def test_fail_if_equal(self):
         fail_if_equal('abc', 'ABC')
         fail_if_equal(42, -42, 'hello', True)
@@ -68,11 +80,11 @@
         raise_msg(AE, "hello: 42 == 42", fail_if_equal, 42, 42, 'hello')
raise_msg(AE, "hello", fail_if_equal, MyEqual('cat'), MyEqual('cat'),
                   'hello', False)
-
+
     def test_fail(self):
         assert_raises(AE, fail)
         assert_raises_with_msg(AE, 'hello', fail, 'hello')
-
+
     def test_error(self):
         assert_raises(Exception, error)
         assert_raises_with_msg(Exception, 'hello', error, 'hello')
@@ -84,7 +96,7 @@
         assert_raises(AE, fail_unless, False)
         assert_raises(AE, assert_true, '')
         assert_raises_with_msg(AE, 'message', assert_, 1 < 0, 'message')
-
+
     def test_fail_if(self):
         fail_if(False)
         assert_false('')
@@ -106,7 +118,7 @@
                                assert_not_none, None, 'message')
         assert_raises_with_msg(AE, "message",
                                assert_not_none, None, 'message', False)
-
+
     def test_fail_unless_almost_equal(self):
         fail_unless_almost_equal(1.0, 1.00000001)
         assert_almost_equal(10, 10.01, 1)
@@ -122,8 +134,8 @@
                                assert_not_almost_equals, 1, 1, msg='hello')
         assert_raises_with_msg(AE, 'hi',
assert_not_almost_equals, 1, 1.1, 0, 'hi', False)
-
+

 if __name__ == '__main__':
     unittest.main()
-
+

==============================================================================
Revision: c66da8787c2c
Author:   Janne Härkönen <[email protected]>
Date:     Wed Apr 20 03:53:30 2011
Log:      merge
http://code.google.com/p/robotframework/source/detail?r=c66da8787c2c


Reply via email to