Exemple #1
0
  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))
Exemple #2
0
  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',
        )),
      })))
Exemple #3
0
 def testMustBeOneOf(self):
   schema = config.ConfigGroupSchema(test=config.Enum('foo', 'bar'))
   with self.assertRaises(ValueError):
     schema.new(test='baz')
Exemple #4
0
 def testEnum(self):
   schema = config.ConfigGroupSchema(test=config.Enum('foo', 'bar'))
   self.assertIsInstance(schema.new(test='foo'), config.ConfigGroup)
Exemple #5
0
 def testMustHaveTypeMap(self):
   with self.assertRaises(ValueError):
     config.ConfigGroupSchema()
Exemple #6
0
  def testCallCallsNew(self):
    schema = config.ConfigGroupSchema(test=config.Single(int))
    sentinel = object()
    schema.new = lambda *args, **kwargs: sentinel

    self.assertEqual(schema(test=3), sentinel)
Exemple #7
0
  def testNewReturnsConfigGroup(self):
    schema = config.ConfigGroupSchema(test=config.Single(int))

    self.assertIsInstance(schema.new(test=3), config.ConfigGroup)