Revision d60946d9

b/lib/utils/algo.py
148 148
  return dict(zip(dict_in.values(), dict_in.keys()))
149 149

  
150 150

  
151
def InsertAtPos(src, pos, other):
152
  """Inserts C{other} at given C{pos} into C{src}.
153

  
154
  @note: This function does not modify C{src} in place but returns a new copy
155

  
156
  @type src: list
157
  @param src: The source list in which we want insert elements
158
  @type pos: int
159
  @param pos: The position where we want to start insert C{other}
160
  @type other: list
161
  @param other: The other list to insert into C{src}
162
  @return: A copy of C{src} with C{other} inserted at C{pos}
163

  
164
  """
165
  new = src[:pos]
166
  new.extend(other)
167
  new.extend(src[pos:])
168

  
169
  return new
170

  
171

  
151 172
class RunningTimeout(object):
152 173
  """Class to calculate remaining timeout when doing several operations.
153 174

  
b/test/ganeti.utils.algo_unittest.py
236 236
                     { 1: "foo", 2: "bar", 5: "baz"})
237 237

  
238 238

  
239
class TestInsertAtPos(unittest.TestCase):
240
  def test(self):
241
    a = [1, 5, 6]
242
    b = [2, 3, 4]
243
    self.assertEqual(algo.InsertAtPos(a, 1, b), [1, 2, 3, 4, 5, 6])
244
    self.assertEqual(algo.InsertAtPos(a, 0, b), b + a)
245
    self.assertEqual(algo.InsertAtPos(a, len(a), b), a + b)
246
    self.assertEqual(algo.InsertAtPos(a, 2, b), [1, 5, 2, 3, 4, 6])
247

  
248

  
239 249
class TimeMock:
240 250
  def __init__(self, values):
241 251
    self.values = values

Also available in: Unified diff