def test_getconfig01(self): ''' Clear the singleton configuration manager. Get a configuration namespace (triggering instantiation of a new configuration manager). Use the add_properties() interface. Test the correct properties were added. ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None configuration.getConfig(__name__, False, properties={ 'foo': { 'value': 5 }, 'bar': 7 }) cfg = configuration.getConfig(__name__, False, properties={ 'baz': { 'value': 1 }, 'aaa': 2 }) self.assertEqual(cfg.baz.value, 1) self.assertEqual(cfg.aaa.value, 2)
def test_getconfig03(self): ''' Trigger the creation of a non-parent namespace. Test that the default namespace is returned. ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None configuration.getConfig('foobar') cfg = configuration.getConfig() log.debug("cfg.name=%r", cfg.name) self.assertEqual(cfg.name, configuration.DEFAULT_NS)
def test_getconfig02(self): ''' Trigger the creation of a parent namespace. Test that the parent namespace is retrieved by default. ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None configuration.getConfig('dlapp') cfg = configuration.getConfig() log.debug("cfg.name=%r", cfg.name) self.assertEqual(cfg.name, 'dlapp')
def test_getconfig05(self): ''' Trigger the creation of a non-parent namespace. Test that ornearest=False causes an exception rather than the default namespace to be returned. ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None configuration.getConfig('foobar') eok = False try: configuration.getConfig(ornearest=False) except ConfigManagerMissingNamespace: eok = True self.assertTrue(eok)
def test_getConfigRecord05(self): ''' Call getConfigRecord without a namespace element to the name ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None configuration.getConfig(__name__, False, properties={ 'foo': { 'value': 5 }, 'bar': 7 }) p = configuration.getConfigRecord("foo") self.assertEqual(p.name, "foo") self.assertEqual(p.value, 5)
def test_getConfigRecord06(self): ''' Call getConfigRecord where the property exists in the default rather than current namespace and ornearest is True ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None configuration.getConfig(DEFAULT_NS, False, properties={ 'foo': { 'value': 5 }, 'bar': 7 }) p = configuration.getConfigRecord("foo", True) self.assertEqual(p.name, "foo") self.assertEqual(p.value, 5)
def test_getConfigRecord01(self): ''' Create a property record then retrieve it using the getConfigRecord function. ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None configuration.getConfig(__name__, False, properties={ 'foo': { 'value': 5 }, 'bar': 7 }) p = configuration.getConfigRecord(__name__ + ".foo") self.assertEqual(p.name, "foo") self.assertEqual(p.value, 5)
def test_getConfigRecord08(self): ''' Call getConfigRecord with an empty name. ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None configuration.getConfig(DEFAULT_NS, False, properties={ 'foo': { 'value': 5 }, 'bar': 7 }) eok = False try: configuration.getConfigRecord("", False) except ConfigPropertyBadName: eok = True self.assertTrue(eok)
def test_getConfigRecord04(self): ''' call getConfigRecord with a bad property name ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None configuration.getConfig(__name__, False, properties={ 'foo': { 'value': 5 }, 'bar': 7 }) eok = False try: configuration.getConfigRecord("good.!badname") except ConfigPropertyBadName: eok = True self.assertTrue(eok)
def test_getConfigRecord02(self): ''' call getConfigRecord with nonexistent property name ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None configuration.getConfig(__name__, False, properties={ 'foo': { 'value': 5 }, 'bar': 7 }) eok = False try: configuration.getConfigRecord(__name__ + ".baz") except ConfigPropertyNotFound: eok = True self.assertTrue(eok)
def test_getConfigRecord07(self): ''' Call getConfigRecord where the property exists in the default rather than current namespace and ornearest is False ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None configuration.getConfig(DEFAULT_NS, False, properties={ 'foo': { 'value': 5 }, 'bar': 7 }) eok = False try: configuration.getConfigRecord("foo", False) except ConfigPropertyNotFound: eok = True self.assertTrue(eok)
def test_appconfig03(self): ''' Create property record, verify the name and value. ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None cns = configuration.getConfig(__name__) name = 'foo' app_prop = __name__ + "." + name p = cns.add_property(name, value=5, validate=tstvalidate) appcfg = AppConfig(app_prop) appcfg.value = 6 x = appcfg.value self.assertEqual(x, p.value)
def test_appconfig04(self): ''' Create property record, verify the name and value. ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None cns = configuration.getConfig(DEFAULT_NS) name = 'foo' app_prop = __name__ + "." + name p = cns.add_property(name, value=5, validate=tstvalidate) dcfg = {'first': {'second': {name: 3}}} appcfg = AppConfig(app_prop) appcfg.set_dictalias(dictconfig=dcfg, dictalias=[['first', 'second', 'foo']], dictformat=reformat) appcfg.resolve() dns = configuration.getConfig(DEFAULT_NS) nns = configuration.getConfig(__name__) log.debug("DEFAULT_NS=%r", dns) log.debug("__name__=%r", nns) self.assertEqual(3, p.value)
def test_appconfig05(self): ''' Create property record, verify the name and value. ''' log = logging.getLogger(__name__) log.debug("BEGIN: unittest.TestCase.id=%r", unittest.TestCase.id(self)) configuration.configuration_manager = None cns = configuration.getConfig(DEFAULT_NS) name = 'foo' app_prop = __name__ + "." + name p = cns.add_property(name, value=5, validate=tstvalidate) dcfg = {'first': {'second': {name: 1}}} envvar = 'TEST_QRGSRYBPFJES' log.debug("Environemt Variable: %r", envvar) value = 3 os.environ[envvar] = "%s" % (value, ) appcfg = AppConfig(app_prop, envalias=[envvar], envformat=reformatstr) appcfg.set_dictalias(dictconfig=dcfg, dictalias=[['first', 'second', 'foo']], dictformat=reformat) appcfg.resolve() self.assertEqual(value, p.value)