How to use common - 10 common examples

To help you get started, we’ve selected a few common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mdaniel / virtualbox-org-svn-vbox-trunk / src / VBox / ValidationKit / testdriver / base.py View on Github external
def processCheckPidAndName(uPid, sName):
    """
    Checks if a process PID and NAME matches.
    """
    if sys.platform == 'win32':
        fRc = winbase.processCheckPidAndName(uPid, sName);
    else:
        sOs = utils.getHostOs();
        if sOs == 'linux':
            asPsCmd = ['/bin/ps',     '-p', '%u' % (uPid,), '-o', 'fname='];
        elif sOs == 'solaris':
            asPsCmd = ['/usr/bin/ps', '-p', '%u' % (uPid,), '-o', 'fname='];
        elif sOs == 'darwin':
            asPsCmd = ['/bin/ps',     '-p', '%u' % (uPid,), '-o', 'ucomm='];
        else:
            asPsCmd = None;

        if asPsCmd is not None:
            try:
                oPs = subprocess.Popen(asPsCmd, stdout=subprocess.PIPE);
                sCurName = oPs.communicate()[0];
                iExitCode = oPs.wait();
            except:
                reporter.logXcpt();
github hpi-xnor / BMXNet-v2 / tests / python / unittest / test_loss.py View on Github external
@with_seed(1234)
def test_saveload():
    nclass = 10
    N = 20
    data = mx.random.uniform(-1, 1, shape=(N, nclass))
    label = mx.nd.array(np.random.randint(0, nclass, size=(N,)), dtype='int32')
    data_iter = mx.io.NDArrayIter(data, label, batch_size=10, label_name='label')
    output = get_net(nclass)
    l = mx.symbol.Variable('label')
    Loss = gluon.loss.SoftmaxCrossEntropyLoss()
    loss = Loss(output, l)
    loss = mx.sym.make_loss(loss)
    mod = mx.mod.Module(loss, data_names=('data',), label_names=('label',))
    mod.fit(data_iter, num_epoch=100, optimizer_params={'learning_rate': 1.},
            eval_metric=mx.metric.Loss())
    mod.save_checkpoint('test', 100, save_optimizer_states=True)
    mod = mx.mod.Module.load('test', 100, load_optimizer_states=True,
github thalium / icebox / third_party / virtualbox / src / VBox / ValidationKit / testdriver / base.py View on Github external
# Options.
        self.fNoWipeClean       = False;

        # Tasks - only accessed by one thread atm, so no need for locking.
        self.aoTasks            = [];

        # Host info.
        self.sHost              = utils.getHostOs();
        self.sHostArch          = utils.getHostArch();

        #
        # Get our bearings and adjust the environment.
        #
        if not utils.isRunningFromCheckout():
            self.sBinPath = os.path.join(g_ksValidationKitDir, utils.getHostOs(), utils.getHostArch());
        else:
            self.sBinPath = os.path.join(g_ksValidationKitDir, os.pardir, os.pardir, os.pardir, 'out', utils.getHostOsDotArch(),
                                         os.environ.get('KBUILD_TYPE', os.environ.get('BUILD_TYPE', 'debug')),
                                         'validationkit', utils.getHostOs(), utils.getHostArch());
        self.sOrgShell = os.environ.get('SHELL');
        self.sOurShell = os.path.join(self.sBinPath, 'vts_shell' + exeSuff()); # No shell yet.
        os.environ['SHELL'] = self.sOurShell;

        self.sScriptPath = getDirEnv('TESTBOX_PATH_SCRIPTS');
        if self.sScriptPath is None:
            self.sScriptPath = os.path.abspath(os.path.join(os.getcwd(), '..'));
        os.environ['TESTBOX_PATH_SCRIPTS'] = self.sScriptPath;

        self.sScratchPath = getDirEnv('TESTBOX_PATH_SCRATCH', fTryCreate = True);
        if self.sScratchPath is None:
            sTmpDir = tempfile.gettempdir();
github thalium / icebox / third_party / virtualbox / src / VBox / ValidationKit / testdriver / base.py View on Github external
self.fInterrupted       = False;

        # Actions.
        self.asSpecialActions   = ['extract', 'abort'];
        self.asNormalActions    = ['cleanup-before', 'verify', 'config', 'execute', 'cleanup-after' ];
        self.asActions          = [];
        self.sExtractDstPath    = None;

        # Options.
        self.fNoWipeClean       = False;

        # Tasks - only accessed by one thread atm, so no need for locking.
        self.aoTasks            = [];

        # Host info.
        self.sHost              = utils.getHostOs();
        self.sHostArch          = utils.getHostArch();

        #
        # Get our bearings and adjust the environment.
        #
        if not utils.isRunningFromCheckout():
            self.sBinPath = os.path.join(g_ksValidationKitDir, utils.getHostOs(), utils.getHostArch());
        else:
            self.sBinPath = os.path.join(g_ksValidationKitDir, os.pardir, os.pardir, os.pardir, 'out', utils.getHostOsDotArch(),
                                         os.environ.get('KBUILD_TYPE', os.environ.get('BUILD_TYPE', 'debug')),
                                         'validationkit', utils.getHostOs(), utils.getHostArch());
        self.sOrgShell = os.environ.get('SHELL');
        self.sOurShell = os.path.join(self.sBinPath, 'vts_shell' + exeSuff()); # No shell yet.
        os.environ['SHELL'] = self.sOurShell;

        self.sScriptPath = getDirEnv('TESTBOX_PATH_SCRIPTS');
github svn2github / virtualbox / trunk / src / VBox / ValidationKit / testdriver / base.py View on Github external
def __init__(self, sName, asArgs, uPid, hWin = None, uTid = None):
        TdTaskBase.__init__(self, utils.getCallerName());
        self.sName      = sName;
        self.asArgs     = asArgs;
        self.uExitCode  = -127;
        self.uPid       = uPid;
        self.hWin       = hWin;
        self.uTid       = uTid;
        self.sKindCrashReport = None;
        self.sKindCrashDump   = None;
github google / coursebuilder-core / coursebuilder / modules / data_pump / data_pump_tests.py View on Github external
'name', 'Name', 'string', description='user name'))
        sub_registry.add_property(schema_fields.SchemaField(
            'city', 'City', 'string', description='city name'))
        reg.add_sub_registry('sub_registry', title='Sub Registry',
                             description='a sub-registry',
                             registry=sub_registry)

        reg.add_property(schema_fields.FieldArray(
            'simple_array', 'Simple Array', description='a simple array',
            item_type=schema_fields.SchemaField(
                'array_int', 'Array Int', 'integer', description='array int')))

        complex_array_type = schema_fields.FieldRegistry('complex_array_type')
        complex_array_type.add_property(schema_fields.SchemaField(
            'this', 'This', 'string', description='the this'))
        complex_array_type.add_property(schema_fields.SchemaField(
            'that', 'That', 'number', description='the that'))
        complex_array_type.add_property(schema_fields.SchemaField(
            'these', 'These', 'datetime', description='the these'))
        reg.add_property(schema_fields.FieldArray(
            'complex_array', 'Complex Array', description='complex array',
            item_type=complex_array_type))
        actual_schema = self.job._json_schema_to_bigquery_schema(
            reg.get_json_schema_dict()['properties'])

        expected_schema = [
            {'mode': 'NULLABLE',
             'type': 'INTEGER',
             'name': 'an_integer',
             'description': 'an integer'},
            {'mode': 'REQUIRED',
             'type': 'STRING',
github google / coursebuilder-core / coursebuilder / modules / data_pump / data_pump_tests.py View on Github external
optional=True, description='an integer'))
        reg.add_property(schema_fields.SchemaField(
            'a_string', 'A String', 'string', description='a string'))
        reg.add_property(schema_fields.SchemaField(
            'some text', 'Some Text', 'text', description='some text'))
        reg.add_property(schema_fields.SchemaField(
            'some html', 'Some HTML', 'html', description='some html'))
        reg.add_property(schema_fields.SchemaField(
            'a url', 'A URL', 'url', description='a url'))
        reg.add_property(schema_fields.SchemaField(
            'a file', 'A File', 'file', description='a file'))
        reg.add_property(schema_fields.SchemaField(
            'a number', 'A Number', 'number', description='a number'))
        reg.add_property(schema_fields.SchemaField(
            'a boolean', 'A Boolean', 'boolean', description='a boolean'))
        reg.add_property(schema_fields.SchemaField(
            'a date', 'A Date', 'date', description='a date'))
        reg.add_property(schema_fields.SchemaField(
            'a datetime', 'A DateTime', 'datetime', description='a datetime'))

        sub_registry = schema_fields.FieldRegistry('subregistry')
        sub_registry.add_property(schema_fields.SchemaField(
            'name', 'Name', 'string', description='user name'))
        sub_registry.add_property(schema_fields.SchemaField(
            'city', 'City', 'string', description='city name'))
        reg.add_sub_registry('sub_registry', title='Sub Registry',
                             description='a sub-registry',
                             registry=sub_registry)

        reg.add_property(schema_fields.FieldArray(
            'simple_array', 'Simple Array', description='a simple array',
            item_type=schema_fields.SchemaField(
github hpi-xnor / BMXNet-v2 / tests / python / unittest / test_gluon_contrib.py View on Github external
@with_seed()
def test_convgru():
    cell = contrib.rnn.Conv1DGRUCell((10, 50), 100, 3, 3, prefix='rnn_')
    check_rnn_cell(cell, prefix='rnn_', in_shape=(1, 10, 50), out_shape=(1, 100, 48))

    cell = contrib.rnn.Conv2DGRUCell((10, 20, 50), 100, 3, 3, prefix='rnn_')
    check_rnn_cell(cell, prefix='rnn_', in_shape=(1, 10, 20, 50), out_shape=(1, 100, 18, 48))

    cell = contrib.rnn.Conv3DGRUCell((10, 20, 30, 50), 100, 3, 3, prefix='rnn_')
    check_rnn_cell(cell, prefix='rnn_', in_shape=(1, 10, 20, 30, 50), out_shape=(1, 100, 18, 28, 48))
github hpi-xnor / BMXNet-v2 / tests / python / unittest / test_sparse_ndarray.py View on Github external
@with_seed()
def test_create_sparse_nd_infer_shape():
    def check_create_csr_infer_shape(shape, density, dtype):
        try:
            matrix = rand_ndarray(shape, 'csr', density=density)
            data = matrix.data
            indptr = matrix.indptr
            indices = matrix.indices
            nd = mx.nd.sparse.csr_matrix((data, indices, indptr), dtype=dtype)
            num_rows, num_cols = nd.shape
            assert(num_rows == len(indptr) - 1)
            assert(indices.shape[0] > 0), indices
            assert(np.sum((num_cols <= indices).asnumpy()) == 0)
            assert(nd.dtype == dtype), (nd.dtype, dtype)
        # cannot infer on invalid shape
        except ValueError:
            pass
github hpi-xnor / BMXNet-v2 / tests / python / unittest / test_gluon.py View on Github external
@with_seed()
def test_sequential():
    check_sequential(gluon.nn.Sequential())
    check_sequential(gluon.nn.HybridSequential())