blob: f950de41621a7ad038819501b6c1b2aae49460d0 [file] [log] [blame]
# -*- coding: utf-8 -*-
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unittests for main builder logic ("""
from __future__ import print_function
import importlib
import mock
from chromite.cbuildbot import builders
from import simple_builders
from chromite.lib import cros_test_lib
class ModuleTest(cros_test_lib.MockTempDirTestCase):
"""Module loading related tests"""
def testGetBuilderClass(self):
"""Check behavior when requesting a valid builder."""
result = builders.GetBuilderClass('simple_builders.SimpleBuilder')
self.assertEqual(result, simple_builders.SimpleBuilder)
def testGetBuilderClassError(self):
"""Check behavior when requesting missing builders."""
self.assertRaises(ValueError, builders.GetBuilderClass, 'Foalksdjo')
self.assertRaises(ImportError, builders.GetBuilderClass, 'foo.Foalksdjo')
self.assertRaises(AttributeError, builders.GetBuilderClass,
def testGetBuilderClassConfig(self):
"""Check behavior when requesting config builders.
This can't be done with live classes since the site config may or may not
be there.
# Setup
mock_module = mock.Mock()
mock_module.MyBuilder = 'fake_class'
mock_import = self.PatchObject(importlib, 'import_module',
# Test
result = builders.GetBuilderClass('config.my_builders.MyBuilder')
# Verify
self.assertEqual(result, 'fake_class')
# Test again with a nested builder class name.
# Test
result = builders.GetBuilderClass('config.nested.my_builders.MyBuilder')
# Verify
self.assertEqual(result, 'fake_class')