Exemple #1
0
 def test_iadd(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     array += array
     self.assertEqual(array[2], 'value1')
     self.assertEqual(array[3], {'foo': 'bar'})
     self.assertEqual(len(array), 4)
     array += jsonobj.JSONarray([{'key': 'value'}])
     self.assertEqual(array.seq[4], {'key': 'value'})
     self.assertEqual(len(array), 5)
Exemple #2
0
 def test_pop(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     pop = array.pop()
     self.assertEqual(pop, {'foo': 'bar'})
     self.assertIsInstance(pop, jsonobj.JSONobj)
     self.assertEqual(len(array), 1)
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     self.assertEqual(array.pop(0), 'value1')
     self.assertEqual(array[0], {'foo': 'bar'})
     self.assertEqual(len(array), 1)
Exemple #3
0
 def test_str(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     self.assertEqual(str(array), '["value1", {"foo": "bar"}]')
Exemple #4
0
 def test_repr(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     self.assertEqual(eval(repr(array)), array)
Exemple #5
0
 def test_remove(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     array.remove('value1')
     self.assertEqual(array[0], {'foo': 'bar'})
     self.assertEqual(len(array), 1)
Exemple #6
0
 def test_setitem(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     array[0] = 'update'
     self.assertEqual(array[0], 'update')
Exemple #7
0
 def test_reverse(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     array.reverse()
     self.assertEqual(array[1], 'value1')
     self.assertEqual(array[0], {'foo': 'bar'})
Exemple #8
0
 def test_insert(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     array.insert(0, 'insert')
     self.assertEqual(array[0], 'insert')
     self.assertEqual(array[1], 'value1')
     self.assertEqual(len(array), 3)
Exemple #9
0
 def test_append(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     array.append('append')
     self.assertEqual(array[2], 'append')
     self.assertEqual(len(array), 3)
Exemple #10
0
 def test_index(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     self.assertEqual(array.index('value1'), 0)
     with self.assertRaises(ValueError):
         array.index('value2')
Exemple #11
0
 def test_count(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     self.assertEqual(array.count('value1'), 1)
     self.assertEqual(array.count(jsonobj.JSONobj({'foo': 'bar'})), 1)
     self.assertEqual(array.count('value2'), 0)
Exemple #12
0
 def test_reversed(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     r = [e for e in reversed(array)]
     self.assertEqual(r[1], 'value1')
     self.assertIsInstance(r[0], jsonobj.JSONobj)
     self.assertEqual(r[0], jsonobj.JSONobj({'foo': 'bar'}))
Exemple #13
0
 def test_iter(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     a = [e for e in array]
     self.assertEqual(a[0], 'value1')
     self.assertIsInstance(a[1], jsonobj.JSONobj)
     self.assertEqual(a[1], jsonobj.JSONobj({'foo': 'bar'}))
Exemple #14
0
 def test_delitem(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     del array[0]
     self.assertNotIn('value1', array)
     self.assertEqual(len(array), 1)
Exemple #15
0
 def test_len(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     self.assertEqual(len(array), 2)
Exemple #16
0
 def test_clear(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     array.clear()
     self.assertEqual(len(array), 0)
Exemple #17
0
 def test_contains(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     self.assertIn('value1', array)
     self.assertIn({'foo': 'bar'}, array)
     self.assertIn(jsonobj.JSONobj({'foo': 'bar'}), array)
     self.assertNotIn('value2', array)
Exemple #18
0
 def test_getitem(self):
     array = jsonobj.JSONarray(['value1', {'foo': 'bar'}])
     self.assertEqual(array[0], 'value1')
     self.assertIsInstance(array[1], jsonobj.JSONobj)
     with self.assertRaises(IndexError):
         array[2]