Esempio n. 1
0
  def test_config_list(self):
    cl = config.ConfigList(lambda: config.ConfigGroup(
      a = config.Single(bool),
      b = config.Single(dict),
    ))

    self.assertEqual(
      cl.schema_proto(),
      d.Schema(sequence=d.Schema.Sequence(
        inner_type=d.Schema(struct=d.Schema.Struct(type_map={
          'a': d.Schema(single=d.Schema.Single(
            inner_type=[d.Schema.BOOLEAN],
            required=True,
            default_json='null',
          )),
          'b': d.Schema(single=d.Schema.Single(
            inner_type=[d.Schema.OBJECT],
            required=True,
            default_json='null',
          ))
        }))
      ))
    )
Esempio n. 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',
        )),
      })))
Esempio n. 3
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))
Esempio n. 4
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)
Esempio n. 5
0
  def testNewReturnsConfigGroup(self):
    schema = config.ConfigGroupSchema(test=config.Single(int))

    self.assertIsInstance(schema.new(test=3), config.ConfigGroup)
Esempio n. 6
0
# Copyright 2013 The LUCI Authors. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.

from recipe_engine import recipe_api, config

DEPS = [
    'context',
    'path',
    'properties',
    'step',
]

RETURN_SCHEMA = config.ReturnSchema(test_me=config.Single(int))

PROPERTIES = {
    'bad_return': recipe_api.Property(default=False),
    'access_invalid_data': recipe_api.Property(default=False),
    'timeout': recipe_api.Property(default=0, kind=int),
}


def RunSteps(api, bad_return, access_invalid_data, timeout):
    if bad_return:
        return RETURN_SCHEMA.new(test_me='this should fail')
    elif timeout:
        # Timeout causes the recipe engine to raise an exception if your step takes
        # longer to run than you allow. Units are seconds.
        if timeout == 1:
            api.step('timeout', ['sleep', '20'], timeout=1)
        elif timeout == 2:
# Copyright 2015 The LUCI Authors. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.

from recipe_engine.recipe_api import Property
from recipe_engine import config

DEPS = [
    'properties',
]

# Missing PROPERTIES on purpose

RETURN_SCHEMA = config.ReturnSchema(result=config.Single(int), )


def RunSteps(api):
    return RETURN_SCHEMA(result=0)


def GenTests(api):
    yield (api.test('basic'))
Esempio n. 8
0
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.

from recipe_engine.recipe_api import Property, RequireClient
from recipe_engine import config

DEPS = [
    'properties',
]

PROPERTIES = {
    'to_pass': Property(),
}

RETURN_SCHEMA = config.ReturnSchema(
    result=config.Single(int),
)

dependency_manager = RequireClient('dependency_manager')

def RunSteps(api, to_pass):
  res = dependency_manager.depend_on(
      'engine_tests/depend_on/bottom', {'number': to_pass})
  return RETURN_SCHEMA(result=res['number_times_two'])

def GenTests(api):
  yield (
      api.test('basic') +
      api.properties(to_pass=3) +
      api.depend_on('engine_tests/depend_on/bottom',
                    {'number': 3}, {'number_times_two': 6})
Esempio n. 9
0
# that can be found in the LICENSE file.

from recipe_engine.recipe_api import Property
from recipe_engine import config

DEPS = [
    'raw_io',
    'properties',
    'step',
]

PROPERTIES = {
    'number': Property(kind=int),
}

RETURN_SCHEMA = config.ReturnSchema(number_times_two=config.Single(int), )


def RunSteps(api, number):
    # Newline cause bc complains if it doesn't have it
    num_s = '%s*%s\n' % (number, 2)
    result = api.step('calc it', ['bc'],
                      stdin=api.raw_io.input(data=num_s),
                      stdout=api.raw_io.output('out'))
    return RETURN_SCHEMA(number_times_two=int(result.stdout))


def GenTests(api):
    yield (api.test('basic') + api.properties(number=3) +
           api.step_data('calc it', stdout=api.raw_io.output('6')))