Exemplo n.º 1
0
 def test_set_call(self):
     loader = phase2.Phase2()
     loader.load_one(
         phase2.SCHEMA,
         [types.Step('set', {'foo': types.Call('env',
                                               ('key', ))}, None)], [])
     self.assertEqual(loader.variables, {'foo': types.Kind.String})
Exemplo n.º 2
0
 def test_run(self):
     cls = attr.make_class('MockSet', ['a'])
     recipe = cls(types.Value('b'))
     steps = [types.Step('set', recipe, None)]
     ctx = phase3.Context()
     phase3.run(steps, ctx)
     self.assertEqual(ctx.variables, {'a': 'b'})
Exemplo n.º 3
0
 def test_set(self):
     loader = phase2.Phase2()
     loader.load_one(phase2.SCHEMA, [
         types.Step('set', {
             'a': 'x',
             'b': True,
             'c': types.Call('env', ('x', ))
         }, None)
     ], [])
     self.assertEqual(loader.variables, {
         'a': types.Kind.String,
         'b': types.Kind.Bool,
         'c': types.Kind.String
     })
Exemplo n.º 4
0
 def load_step(self, schema, val, path):
     self.step = val
     fields = self.load_one(schema.fields[Key(val.name)], val.recipe,
                            path + [val.name])
     # TODO, might be better to encode this in the schema somehow
     if val.name == 'create-temp-dir':
         self.variables[fields.var.data] = types.Kind.Path
     elif val.name == 'set':
         for key in val.recipe:
             if isinstance(val.recipe[key], str):
                 self.variables[key] = types.Kind.String
             elif isinstance(val.recipe[key], bool):
                 self.variables[key] = types.Kind.Bool
             elif isinstance(val.recipe[key], types.Call):
                 self.variables[key] = self.functions[
                     val.recipe[key].name].return_type
             else:
                 raise SchemaError('invalid variable type')
     return types.Step(val.name, fields, val.path)
Exemplo n.º 5
0
def resolve_step(step, ctx):
    recipe = resolve(step.recipe, ctx)
    return types.Step(step.name, recipe, step.path)
Exemplo n.º 6
0
 def test_repath(self):
     ctx = phase3.Context()
     ctx.step = types.Step('foo', None, '/base')
     self.assertEqual(ctx.repath('myPath'), '/base/myPath')
Exemplo n.º 7
0
 def test_step(self):
     # pylint: disable=no-self-use
     cls = attr.make_class('MockRecipe', ())
     recipe = cls()
     step = types.Step('foo', recipe, None)
     phase3.resolve_step(step, None)
Exemplo n.º 8
0
 def step(self, ast):
     return types.Step(ast.name, ast.recipe, None)
Exemplo n.º 9
0
 def test_create_temp_dir(self):
     loader = phase2.Phase2()
     loader.load_one(phase2.SCHEMA,
                     [types.Step('create-temp-dir', {'var': 'foo'}, None)],
                     [])
     self.assertEqual(loader.variables, {'foo': types.Kind.Path})
Exemplo n.º 10
0
 def test_step(self):
     schema = phase2.MODEL.parse('foo {}')
     result = phase2.Phase2.load(schema, [types.Step('foo', {}, None)])
     self.assertEqual(len(result), 1)
     self.assertEqual(result[0].__class__, types.Step)
     self.assertEqual(result[0].name, 'foo')
Exemplo n.º 11
0
 def test_set_bad_type(self):
     loader = phase2.Phase2()
     with self.assertRaises(phase2.SchemaError):
         loader.load_one(phase2.SCHEMA,
                         [types.Step('set', {'a': object()}, None)], [])