Esempio n. 1
0
 def test_returning_empty(self):
   d = OrderedDict([
       ('x', {'name': 'x', 'cmd': ['one', 'two', 'three']}),
       ('y', {'name': 'y', 'cmd': []}),
       ('z', {'name': 'z', 'cmd': ['foo', 'bar']}),
   ])
   test_data = self.mkApi().post_process(lambda check, steps: {})
   results = Outcome.Results()
   expectations = post_process(results, d, test_data)
   self.assertIsNone(expectations)
   self.assertEqual(len(results.check), 0)
Esempio n. 2
0
 def test_returning_nonsubset(self):
   d = OrderedDict([
       ('x', {'name': 'x', 'cmd': ['one', 'two', 'three']}),
       ('y', {'name': 'y', 'cmd': []}),
       ('z', {'name': 'z', 'cmd': ['foo', 'bar']}),
   ])
   test_data = self.mkApi().post_process(
       lambda check, steps:
       OrderedDict((k, dict(cwd='cwd', **v.to_step_dict()))
                   for k, v in steps.iteritems()))
   with self.assertRaises(PostProcessError):
     post_process(Outcome.Results(), d, test_data)
Esempio n. 3
0
 def test_key_error_followed_by_attribute(self):
   d = OrderedDict([('x', {'name': 'x'})])
   def body(check, steps):
     foo = steps['y'].env['foo']
   test_data = self.mkApi().post_process(body)
   results = Outcome.Results()
   post_process(results, d, test_data)
   self.assertEqual(len(results.check), 1)
   self.assertHas(
       results.check[0],
       "foo = steps['y'].env['foo']",
       "steps.keys(): ['x']",
       "raised exception: KeyError: 'y'")
Esempio n. 4
0
 def test_key_error_implicit_check(self):
   d = OrderedDict([('x', {'name': 'x'})])
   def body(check, steps):
     foo = steps['x'].env['foo']
   test_data = self.mkApi().post_process(body)
   results = Outcome.Results()
   expectations = post_process(results, d, test_data)
   self.assertEqual(len(results.check), 1)
   self.assertHas(
       results.check[0],
       "foo = steps['x'].env['foo']",
       "steps['x'].env.keys(): []",
       "raised exception: KeyError: 'foo'")
Esempio n. 5
0
 def test_returning_subset(self):
   d = OrderedDict([
       ('x', {'name': 'x', 'cmd': ['one', 'two', 'three']}),
       ('y', {'name': 'y', 'cmd': []}),
       ('z', {'name': 'z', 'cmd': ['foo', 'bar']}),
   ])
   test_data = self.mkApi().post_process(
       lambda check, steps:
       OrderedDict((k, {'name': v.name}) for k, v in steps.iteritems()))
   results = Outcome.Results()
   expectations = post_process(results, d, test_data)
   self.assertEqual(expectations, [{'name': 'x'}, {'name': 'y'}, {'name': 'z'}])
   self.assertEqual(len(results.check), 0)
Esempio n. 6
0
 def test_key_error_in_subscript_expression(self):
   d = OrderedDict([('x', {'name': 'x'})])
   def body(check, steps):
     d2 = {}
     foo = steps[d2['x']].env['foo']
   test_data = self.mkApi().post_process(body)
   results = Outcome.Results()
   expectations = post_process(results, d, test_data)
   self.assertEqual(len(results.check), 1)
   self.assertHas(
       results.check[0],
       "foo = steps[d2['x']].env['foo']",
       'd2.keys(): []',
       "raised exception: KeyError: 'x'")
Esempio n. 7
0
 def test_post_process_failure(self):
   d = OrderedDict([('x', {'name': 'x'})])
   def body(check, steps, *args, **kwargs):
     check('x' not in steps)
   test_data = self.mkApi().post_process(body, 'foo', 'bar', a=1, b=2)
   results = Outcome.Results()
   expectations = post_process(results, d, test_data)
   self.assertEqual(expectations, [{'name': 'x'}])
   self.assertEqual(len(results.check), 1)
   self.assertHas(results.check[0],
                  "body('foo', 'bar', a=1, b=2)")
   self.assertHas(
       results.check[0],
       "check(('x' not in steps))",
       "steps.keys(): ['x']")
Esempio n. 8
0
 def test_key_error_implicit_check_no_checker_in_frame(self):
   d = OrderedDict([('x', {'name': 'x'})])
   def body(check, steps_dict):
     # The failure backtrace for the implicit check should even include frames
     # where check isn't explicitly passed
     def inner(steps_dict):
       return steps_dict['x'].env['foo'] == 'bar'
     check(inner(steps_dict))
   test_data = self.mkApi().post_process(body)
   results = Outcome.Results()
   post_process(results, d, test_data)
   self.assertEqual(len(results.check), 1)
   self.assertHas(
       results.check[0],
       'check(inner(steps_dict))')
   self.assertHas(
       results.check[0],
       "return (steps_dict['x'].env['foo'] == 'bar')",
       "steps_dict['x'].env.keys(): []",
       "raised exception: KeyError: 'foo'")
Esempio n. 9
0
 def test_removing_name(self):
   d = OrderedDict([
       ('x', {'name': 'x', 'cmd': ['one', 'two', 'three']}),
       ('y', {'name': 'y', 'cmd': []}),
       ('z', {'name': 'z', 'cmd': ['foo', 'bar']}),
   ])
   test_data = self.mkApi().post_process(
       lambda check, steps:
       OrderedDict(
           (k, {a: value for a, value in v.to_step_dict().iteritems()
                if a != 'name'})
           for k,v in steps.iteritems()))
   results = Outcome.Results()
   expectations = post_process(results, d, test_data)
   self.assertEqual(expectations, [
       {'name': 'x', 'cmd': ['one', 'two', 'three']},
       {'name': 'y', 'cmd': []},
       {'name': 'z', 'cmd': ['foo', 'bar']},
   ])
   self.assertEqual(len(results.check), 0)
Esempio n. 10
0
 def test_post_process_failure_in_multiple_hooks(self):
   d = OrderedDict([('x', {'name': 'x'})])
   def body(check, steps, *args, **kwargs):
     check('x' not in steps)
   def body2(check, steps, *args, **kwargs):
     check('y' in steps)
   api = self.mkApi()
   test_data = (api.post_process(body, 'foo', a=1) +
                api.post_process(body2, 'bar', b=2))
   results = Outcome.Results()
   expectations = post_process(results, d, test_data)
   self.assertEqual(expectations, [{'name': 'x'}])
   self.assertEqual(len(results.check), 2)
   self.assertHas(
       results.check[0],
       "body('foo', a=1)",
       "check(('x' not in steps))",
       "steps.keys(): ['x']")
   self.assertHas(
       results.check[1],
       "body2('bar', b=2)",
       "check(('y' in steps))",
       "steps.keys(): ['x']")
Esempio n. 11
0
 def post_process(d, f, *args, **kwargs):
     test_data = RecipeTestApi().post_process(f, *args, **kwargs)
     results = Outcome.Results()
     expectations = magic_check_fn.post_process(results, d, test_data)
     return expectations, results.check