def testRunChecksReturnType(self): sentinel = object() mocked_return = object() class FakeReturn(object): def as_jsonish(_self, hidden=sentinel): self.assertEqual(True, hidden) return mocked_return script = loader.RecipeScript( 'fake_recipe', { 'RETURN_SCHEMA': config.ConfigGroupSchema(a=config.Single(int)), 'RunSteps': lambda api: None, 'GenTests': lambda api: None, }, 'fake_package', 'some/path') loader.invoke_with_properties = lambda *args, **kwargs: FakeReturn() self.assertEqual(mocked_return, script.run(None, None, None))
def test_config_group_schema(self): cg = config.ConfigGroupSchema( combo=config.Single((int, float), empty_val=20), other=config.List(str), field=config.Single((str, type(None))), ) self.assertEqual( cg.schema_proto(), d.Schema(struct=d.Schema.Struct(type_map={ 'combo': d.Schema(single=d.Schema.Single( inner_type=[d.Schema.NUMBER], required=True, default_json='20', )), 'other': d.Schema(list=d.Schema.List( inner_type=[d.Schema.STRING], )), 'field': d.Schema(single=d.Schema.Single( inner_type=[d.Schema.STRING, d.Schema.NULL], required=True, default_json='null', )), })))
def testMustBeOneOf(self): schema = config.ConfigGroupSchema(test=config.Enum('foo', 'bar')) with self.assertRaises(ValueError): schema.new(test='baz')
def testEnum(self): schema = config.ConfigGroupSchema(test=config.Enum('foo', 'bar')) self.assertIsInstance(schema.new(test='foo'), config.ConfigGroup)
def testMustHaveTypeMap(self): with self.assertRaises(ValueError): config.ConfigGroupSchema()
def testCallCallsNew(self): schema = config.ConfigGroupSchema(test=config.Single(int)) sentinel = object() schema.new = lambda *args, **kwargs: sentinel self.assertEqual(schema(test=3), sentinel)
def testNewReturnsConfigGroup(self): schema = config.ConfigGroupSchema(test=config.Single(int)) self.assertIsInstance(schema.new(test=3), config.ConfigGroup)