def test_integer_range_up_skip(self) : """Test IntRange skipping some values.""" jr = rangetools.IntRange(1, 4, 2) js = [j for j in jr.values()] self.assertEqual(2, len(js)) self.assertEqual(1, js[ 0]) self.assertEqual(3, js[-1])
def test_integer_range_up(self) : """Test IntRange.""" jr = rangetools.IntRange(1, 4) js = [j for j in jr.values()] self.assertEqual(4, len(js)) self.assertEqual(1, js[ 0]) self.assertEqual(4, js[-1])
def test_integer_range_down_skip(self) : """Test IntRange going down skipping some values.""" jr = rangetools.IntRange(4, 1, -2) js = [j for j in jr.values()] self.assertEqual(2, len(js)) self.assertEqual(4, js[ 0]) self.assertEqual(2, js[-1])
def test_integer_down(self) : """Test IntRange going down.""" jr = rangetools.IntRange(4, 1, -1) js = [j for j in jr.values()] self.assertEqual(4, len(js)) self.assertEqual(4, js[ 0]) self.assertEqual(1, js[-1])
def process_loop(self, bounds, rest, context) : env = {} env.update(context) env.update(self.env) try : (start, stop, step) = [eval(f, env, None) for f in bounds] except Exception as e : msg = 'Unable to evaluate loop bounds \'%s\',\n' % str(bounds) self.log.write(msg) self.log.write('\t%s\n' % str(e)) self.log.write('\tenv = %s\n' % str(env)) return False vals = list(rangetools.IntRange(start, stop, step).values()) xvals = [dict([x]) for x in zip(itertools.cycle(['loop_index']), vals)] expanded = self.expand_output_rows(context, xvals) return self.produce_output(expanded, rest)
def test_integer_range_error(self) : """Test IntRange with invalid constructor arguments.""" with self.assertRaises(Exception) : js = rangetools.IntRange(1, 1, 0)