Exemple #1
0
 def test_get_set_combination(self):
     array = space.array()
     with self.assertRaises(KeyError):
         array.get(space.int(5))
     array.set(space.undefined(), space.int(1))
     value = array.get(space.int(0)).deref()
     self.assertTrue(value.equal(space.int(1)).is_true())
     with self.assertRaises(KeyError):
         array.get(space.string("7"))
     array.set(space.undefined(), space.int(2))
     value = array.get(space.int(1)).deref()
     self.assertTrue(value.equal(space.int(2)).is_true())
Exemple #2
0
 def GET_INDEX(self, value):
     name = self.frame.pop_name()
     w_array = self.frame.get_variable(name, self.context)
     w_index = self.frame.stack.pop()
     try:
         w_value = w_array.get(w_index)
     except KeyError:
         w_value = space.undefined()
     except IllegalOffsetType:
         #TODO: add illegal offset type message print
         w_value = space.null()
     self.frame.stack.append(w_value)
Exemple #3
0
 def test_array_creation_with_no_keys(self):
     raw = [space.undefined(), space.int(1),
            space.undefined(), space.int(2),
            space.float(6.0), space.int(3),
            space.undefined(), space.int(4),
            space.int(3), space.int(5),
            space.undefined(), space.int(6)]
     actual = space.array(raw)
     expected = {space.string('0'): space.int(1), space.string('1'): space.int(2),
                 space.string('6'): space.int(3), space.string('7'): space.int(4),
                 space.string('3'): space.int(5), space.string('8'): space.int(6)}
     for key, value in expected.iteritems():
         self.assertTrue(actual.get(key).deref().equal(value).is_true())
     raw = [space.string("6"), space.int(3),
            space.string("3"), space.int(5),
            space.undefined(), space.int(6)]
     actual = space.array(raw)
     expected = {space.string('6'): space.int(3),
                 space.string('3'): space.int(5),
                 space.string('7'): space.int(6)}
     for key, value in expected.iteritems():
         self.assertTrue(actual.get(key).deref().equal(value).is_true())
Exemple #4
0
 def test_set(self):
     array = space.array([space.int(5), space.int(1),
                          space.int(12), space.int(2)])
     array.set(space.int(2), space.int(3))
     value = array.get(space.int(2)).deref()
     self.assertTrue(value.equal(space.int(3)).is_true())
     array.set(space.string("4"), space.int(4))
     value = array.get(space.int(4)).deref()
     self.assertTrue(value.equal(space.int(4)).is_true())
     # no index test
     array.set(space.undefined(), space.int(13))
     value = array.get(space.int(13)).deref()
     self.assertTrue(value.equal(space.int(13)).is_true())
     array.set(space.int(15), space.int(15))
     array.set(space.undefined(), space.int(16))
     value = array.get(space.int(16)).deref()
     self.assertTrue(value.equal(space.int(16)).is_true())
     # now string
     array.set(space.string("20"), space.int(20))
     array.set(space.undefined(), space.int(21))
     value = array.get(space.int(21)).deref()
     self.assertTrue(value.equal(space.int(21)).is_true())
Exemple #5
0
 def get_compiled_value(self):
     return space.undefined()