コード例 #1
0
ファイル: test_arg_check.py プロジェクト: ooici-dm/pyon
    def test_validates_success(self):
        import pyon.util.arg_check as ac
        fl = self._FakeLog()
        ac.log = fl
        try:
            ac.validateTrue(False,'blah')
        except BadRequest as e:
            self.assertTrue(e.message == 'blah')

        self.assertEquals(fl.name,"pyon.util.test.test_arg_check")
コード例 #2
0
ファイル: test_arg_check.py プロジェクト: ooici-dm/pyon
    def test_validates_success(self):
        import pyon.util.arg_check as ac
        fl = self._FakeLog()
        ac.log = fl
        try:
            ac.validateTrue(False, 'blah')
        except BadRequest as e:
            self.assertTrue(e.message == 'blah')

        self.assertEquals(fl.name, "pyon.util.test.test_arg_check")
コード例 #3
0
ファイル: datastore.py プロジェクト: ooici-dm/pyon
    def get_datastore(self, ds_name, profile=DataStore.DS_PROFILE.BASIC, config=None):
        """
        Factory method to get a datastore instance from given name, profile and config.
        This is the central point to cache these instances, to decide persistent or mock
        and to force clean the store on first use.
        @param ds_name  Logical name of datastore (will be scoped with sysname)
        @param profile  One of known constants determining the use of the store
        @param config  Override config to use
        """
        validateTrue(ds_name,'ds_name must be provided')
        if ds_name in self._datastores:
            log.debug("get_datastore(): Found instance of store '%s'" % ds_name)
            return self._datastores[ds_name]

        scoped_name = DatastoreManager.get_scoped_name(ds_name)

        # Imports here to prevent cyclic module dependency
        from pyon.core.bootstrap import CFG
        config = config or CFG

        if self.persistent is None:
            self.persistent = not bool(get_safe(config, "system.mockdb"))
        if self.force_clean is None:
            self.force_clean = bool(get_safe(config, "system.force_clean"))

        # Create a datastore instance
        log.info("get_datastore(): Create instance of store '%s' {persistent=%s, scoped_name=%s}" % (
            ds_name, self.persistent, scoped_name))
        new_ds = DatastoreManager.get_datastore_instance(ds_name, self.persistent, profile)

        # Clean the store instance
        # TBD: Do we really want to do it here? or make it more manual?
        if self.force_clean:
            log.info("get_datastore(): Force clean store '%s'" % ds_name)
            try:
                new_ds.delete_datastore(scoped_name)
            except NotFound:
                pass

        # Create store if not existing
        if not new_ds.datastore_exists(scoped_name):
            new_ds.create_datastore(scoped_name)
        else:
            if self.persistent:
                # NOTE: This may be expensive if called more than once per container
                # If views exist and are dropped and recreated
                new_ds._define_views(profile=profile, keepviews=True)

        # Set a few standard datastore instance fields
        new_ds.local_name = ds_name
        new_ds.ds_profile = profile

        self._datastores[ds_name] = new_ds

        return new_ds
コード例 #4
0
ファイル: test_arg_check.py プロジェクト: ooici-dm/pyon
    def test_validations(self):
        import pyon.util.arg_check as arg_check

        with self.assertRaises(BadRequest):
            arg_check.validateTrue(False,'test')

        with self.assertRaises(BadRequest):
            arg_check.validateEqual(3,4,'test')

        with self.assertRaises(BadRequest):
            arg_check.validateNotEqual(4,4,'test')

        with self.assertRaises(BadRequest):
            arg_check.validateFalse(True,'test')

        with self.assertRaises(BadRequest):
            one = list()
            two = list()
            arg_check.validateIs(one,two,'test')

        with self.assertRaises(BadRequest):
            one = list()
            two = one
            arg_check.validateIsNot(one,two,'test')

        with self.assertRaises(BadRequest):
            c = None
            arg_check.validateIsNotNone(c,'test')

        with self.assertRaises(BadRequest):
            one = list([1,3])
            two = 2
            arg_check.validateIn(two,one,'test')

        with self.assertRaises(BadRequest):
            one = list([1,2,3])
            two = 2
            arg_check.validateNotIn(two,one,'test')

        with self.assertRaises(BadRequest):
            one = list()
            arg_check.validateIsInstance(one,dict,'test')

        with self.assertRaises(BadRequest):
            one = list()
            arg_check.validateNotIsInstance(one,list,'test')
コード例 #5
0
ファイル: test_arg_check.py プロジェクト: ooici-dm/pyon
    def test_validations(self):
        import pyon.util.arg_check as arg_check

        with self.assertRaises(BadRequest):
            arg_check.validateTrue(False, 'test')

        with self.assertRaises(BadRequest):
            arg_check.validateEqual(3, 4, 'test')

        with self.assertRaises(BadRequest):
            arg_check.validateNotEqual(4, 4, 'test')

        with self.assertRaises(BadRequest):
            arg_check.validateFalse(True, 'test')

        with self.assertRaises(BadRequest):
            one = list()
            two = list()
            arg_check.validateIs(one, two, 'test')

        with self.assertRaises(BadRequest):
            one = list()
            two = one
            arg_check.validateIsNot(one, two, 'test')

        with self.assertRaises(BadRequest):
            c = None
            arg_check.validateIsNotNone(c, 'test')

        with self.assertRaises(BadRequest):
            one = list([1, 3])
            two = 2
            arg_check.validateIn(two, one, 'test')

        with self.assertRaises(BadRequest):
            one = list([1, 2, 3])
            two = 2
            arg_check.validateNotIn(two, one, 'test')

        with self.assertRaises(BadRequest):
            one = list()
            arg_check.validateIsInstance(one, dict, 'test')

        with self.assertRaises(BadRequest):
            one = list()
            arg_check.validateNotIsInstance(one, list, 'test')
コード例 #6
0
ファイル: datastore.py プロジェクト: ooici-dm/pyon
    def get_datastore(self,
                      ds_name,
                      profile=DataStore.DS_PROFILE.BASIC,
                      config=None):
        """
        Factory method to get a datastore instance from given name, profile and config.
        This is the central point to cache these instances, to decide persistent or mock
        and to force clean the store on first use.
        @param ds_name  Logical name of datastore (will be scoped with sysname)
        @param profile  One of known constants determining the use of the store
        @param config  Override config to use
        """
        validateTrue(ds_name, 'ds_name must be provided')
        if ds_name in self._datastores:
            log.debug("get_datastore(): Found instance of store '%s'" %
                      ds_name)
            return self._datastores[ds_name]

        scoped_name = DatastoreManager.get_scoped_name(ds_name)

        # Imports here to prevent cyclic module dependency
        from pyon.core.bootstrap import CFG
        config = config or CFG

        if self.persistent is None:
            self.persistent = not bool(get_safe(config, "system.mockdb"))
        if self.force_clean is None:
            self.force_clean = bool(get_safe(config, "system.force_clean"))

        # Create a datastore instance
        log.info(
            "get_datastore(): Create instance of store '%s' {persistent=%s, scoped_name=%s}"
            % (ds_name, self.persistent, scoped_name))
        new_ds = DatastoreManager.get_datastore_instance(
            ds_name, self.persistent, profile)

        # Clean the store instance
        # TBD: Do we really want to do it here? or make it more manual?
        if self.force_clean:
            log.info("get_datastore(): Force clean store '%s'" % ds_name)
            try:
                new_ds.delete_datastore(scoped_name)
            except NotFound:
                pass

        # Create store if not existing
        if not new_ds.datastore_exists(scoped_name):
            new_ds.create_datastore(scoped_name)
        else:
            if self.persistent:
                # NOTE: This may be expensive if called more than once per container
                # If views exist and are dropped and recreated
                new_ds._define_views(profile=profile, keepviews=True)

        # Set a few standard datastore instance fields
        new_ds.local_name = ds_name
        new_ds.ds_profile = profile

        self._datastores[ds_name] = new_ds

        return new_ds
コード例 #7
0
 def list_len(self, l):
     '''
     You needed to be certain that a list had len >0
     '''
     validateTrue(len(l) > 0, 'list=%s was empty.' % str(l))
コード例 #8
0
ファイル: arg_check_example.py プロジェクト: ooici-dm/pyon
 def list_len(self, l):
     """
     You needed to be certain that a list had len >0
     """
     validateTrue(len(l) > 0, "list=%s was empty." % str(l))