Author: pekka.klarck
Date: Tue Mar 24 01:23:59 2009
New Revision: 1493

Modified:
   trunk/src/robot/variables/variables.py
   trunk/utest/variables/test_variables.py

Log:
Cleanup and better tests

Modified: trunk/src/robot/variables/variables.py
==============================================================================
--- trunk/src/robot/variables/variables.py      (original)
+++ trunk/src/robot/variables/variables.py      Tue Mar 24 01:23:59 2009
@@ -39,12 +39,9 @@
     }$           # "}" and end of the string
     ''', re.VERBOSE)

-    def __init__(self, identifiers=None):
-        if identifiers is None:
-            self._identifiers = ['$','@','%','&','*']
-        else:
-            self._identifiers = identifiers
+    def __init__(self, identifiers=['$','@','%','&','*']):
         utils.NormalizedDict.__init__(self, ignore=['_'])
+        self._identifiers = identifiers

     def __setitem__(self, name, value):
         if not is_var(name):
@@ -286,6 +283,8 @@
             return False
         else:
             return True
+
+    __contains__ = has_key


 class _VariableSplitter:

Modified: trunk/utest/variables/test_variables.py
==============================================================================
--- trunk/utest/variables/test_variables.py     (original)
+++ trunk/utest/variables/test_variables.py     Tue Mar 24 01:23:59 2009
@@ -97,9 +97,19 @@
             self.assertRaises(DataError, self.varz.__getitem__, var)

     def test_has_key(self):
-        # tested mainly in test_setitem
+        self.varz['${k}'] = 'v'
+        assert self.varz.has_key('${k}')
+        assert self.varz.has_key('${1}')
+        assert self.varz.has_key('${k.upper()}')
         assert not self.varz.has_key('${non-existing}')

+    def test_contains(self):
+        self.varz['${k}'] = 'v'
+        assert '${k}' in self.varz
+        assert '${-3}' in self.varz
+        assert '${k.upper()}' in self.varz
+        assert '${nok}' not in self.varz
+
     def test_replace_scalar(self):
         self.varz['${foo}'] = 'bar'
         self.varz['${a}'] = 'ari'
@@ -238,6 +248,13 @@
         assert_equals(self.varz.replace_list(['${name}', 42]), [exp, 42])
         assert_equals(self.varz.replace_string('${name}'), str(exp))
         assert_true(self.varz.has_key('${name}'))
+
+    def test_copy(self):
+        varz = variables.Variables(identifiers=['$'])
+        varz['${foo}'] = 'bar'
+        copy = varz.copy()
+        assert_equals(copy['${foo}'], 'bar')
+        assert_equals(copy._identifiers, ['$'])

     if utils.is_jython:

Reply via email to