def test_build_options(self): """Test usage of BuildOptions.""" # delete instance of BuildOptions BuildOptions.__metaclass__._instances.pop(BuildOptions, None) # make sure BuildOptions is a singleton class bo1 = BuildOptions() bo2 = BuildOptions() bo3 = BuildOptions({'foo': 'bar'}) # note: argument is ignored, an instance is already available self.assertTrue(bo1 is bo2) self.assertTrue(bo1 is bo3) # test basic functionality BuildOptions.__metaclass__._instances.pop(BuildOptions, None) bo = BuildOptions({ 'debug': False, 'force': True }) self.assertTrue(not bo['debug']) self.assertTrue(bo['force']) # updating is impossible (methods are not even available) self.assertErrorRegex(TypeError, '.*item assignment.*', lambda x: bo.update(x), {'debug': True}) self.assertErrorRegex(AttributeError, '.*no attribute.*', lambda x: bo.__setitem__(*x), ('debug', True)) # only valid keys can be set BuildOptions.__metaclass__._instances.pop(BuildOptions, None) msg = "Encountered unknown keys .* \(known keys: .*" self.assertErrorRegex(KeyError, msg, BuildOptions, {'thisisclearlynotavalidbuildoption': 'FAIL'}) # test init_build_options and build_option functions self.assertErrorRegex(KeyError, msg, init_build_options, {'thisisclearlynotavalidbuildoption': 'FAIL'}) bo = init_build_options({ 'robot_path': '/some/robot/path', 'stop': 'configure', }) # specific build options should be set self.assertEqual(bo['robot_path'], '/some/robot/path') self.assertEqual(bo['stop'], 'configure') # all possible build options should be set (defaults are used where needed) self.assertEqual(sorted(bo.keys()), sorted(BuildOptions.KNOWN_KEYS)) # there should be only one BuildOptions instance bo2 = BuildOptions() self.assertTrue(bo is bo2)
def test_build_options(self): """Test usage of BuildOptions.""" # delete instance of BuildOptions BuildOptions.__metaclass__._instances.pop(BuildOptions, None) # make sure BuildOptions is a singleton class bo1 = BuildOptions() bo2 = BuildOptions() bo3 = BuildOptions({ 'foo': 'bar' }) # note: argument is ignored, an instance is already available self.assertTrue(bo1 is bo2) self.assertTrue(bo1 is bo3) # test basic functionality BuildOptions.__metaclass__._instances.pop(BuildOptions, None) bo = BuildOptions({'debug': False, 'force': True}) self.assertTrue(not bo['debug']) self.assertTrue(bo['force']) # updating is impossible (methods are not even available) self.assertErrorRegex(TypeError, '.*item assignment.*', lambda x: bo.update(x), {'debug': True}) self.assertErrorRegex(AttributeError, '.*no attribute.*', lambda x: bo.__setitem__(*x), ('debug', True)) # only valid keys can be set BuildOptions.__metaclass__._instances.pop(BuildOptions, None) msg = "Encountered unknown keys .* \(known keys: .*" self.assertErrorRegex(KeyError, msg, BuildOptions, {'thisisclearlynotavalidbuildoption': 'FAIL'}) # test init_build_options and build_option functions self.assertErrorRegex(KeyError, msg, init_build_options, {'thisisclearlynotavalidbuildoption': 'FAIL'}) bo = init_build_options({ 'robot_path': '/some/robot/path', 'stop': 'configure', }) # specific build options should be set self.assertEqual(bo['robot_path'], '/some/robot/path') self.assertEqual(bo['stop'], 'configure') # all possible build options should be set (defaults are used where needed) self.assertEqual(sorted(bo.keys()), sorted(BuildOptions.KNOWN_KEYS)) # there should be only one BuildOptions instance bo2 = BuildOptions() self.assertTrue(bo is bo2)