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})
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'})
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 })
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)
def resolve_step(step, ctx): recipe = resolve(step.recipe, ctx) return types.Step(step.name, recipe, step.path)
def test_repath(self): ctx = phase3.Context() ctx.step = types.Step('foo', None, '/base') self.assertEqual(ctx.repath('myPath'), '/base/myPath')
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)
def step(self, ast): return types.Step(ast.name, ast.recipe, None)
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})
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')
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)], [])