当前位置: 首页>>代码示例>>Python>>正文


Python tools.assert_in方法代码示例

本文整理汇总了Python中nose.tools.assert_in方法的典型用法代码示例。如果您正苦于以下问题:Python tools.assert_in方法的具体用法?Python tools.assert_in怎么用?Python tools.assert_in使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nose.tools的用法示例。


在下文中一共展示了tools.assert_in方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_harvest_job_create_as_sysadmin

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def test_harvest_job_create_as_sysadmin(self):
        source = factories.HarvestSource(**SOURCE_DICT.copy())

        site_user = toolkit.get_action('get_site_user')(
            {'model': model, 'ignore_auth': True}, {})['name']
        data_dict = {
            'source_id': source['id'],
            'run': True
            }
        job = toolkit.get_action('harvest_job_create')(
            {'user': site_user}, data_dict)

        assert_equal(job['source_id'], source['id'])
        assert_equal(job['status'], 'Running')
        assert_equal(job['gather_started'], None)
        assert_in('stats', job.keys()) 
开发者ID:italia,项目名称:daf-recipes,代码行数:18,代码来源:test_action.py

示例2: test_await_data

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def test_await_data(self):
        """asking for ar.data flushes outputs"""
        self.minimum_engines(1)
        
        v = self.client[-1]
        ar = v.execute('\n'.join([
            "import time",
            "from IPython.kernel.zmq.datapub import publish_data",
            "for i in range(5):",
            "    publish_data(dict(i=i))",
            "    time.sleep(0.1)",
        ]), block=False)
        found = set()
        tic = time.time()
        # timeout after 10s
        while time.time() <= tic + 10:
            if ar.data:
                found.add(ar.data['i'])
                if ar.data['i'] == 4:
                    break
            time.sleep(0.05)
        
        ar.get(5)
        nt.assert_in(4, found)
        self.assertTrue(len(found) > 1, "should have seen data multiple times, but got: %s" % found) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:27,代码来源:test_asyncresult.py

示例3: test_push_dataframe

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def test_push_dataframe():
    from pandas import DataFrame
    rm = rmagic.RMagics(ip)
    df = DataFrame([{'a': 1, 'b': 'bar'}, {'a': 5, 'b': 'foo', 'c': 20}])
    ip.push({'df':df})
    ip.run_line_magic('Rpush', 'df')
    
    # This is converted to factors, which are currently converted back to Python
    # as integers, so for now we test its representation in R.
    sio = StringIO()
    rinterface.set_writeconsole(sio.write)
    try:
        rm.r('print(df$b[1])')
        nt.assert_in('[1] bar', sio.getvalue())
    finally:
        rinterface.set_writeconsole(None)
    
    # Values come packaged in arrays, so we unbox them to test.
    nt.assert_equal(rm.r('df$a[2]')[0], 5)
    missing = rm.r('df$c[1]')[0]
    assert np.isnan(missing), missing 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:23,代码来源:test_rmagic.py

示例4: test_store_restore

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def test_store_restore():
    ip.user_ns['foo'] = 78
    ip.magic('alias bar echo "hello"')
    tmpd = tempfile.mkdtemp()
    ip.magic('cd ' + tmpd)
    ip.magic('store foo')
    ip.magic('store bar')
    
    # Check storing
    nt.assert_equal(ip.db['autorestore/foo'], 78)
    nt.assert_in('bar', ip.db['stored_aliases'])
    
    # Remove those items
    ip.user_ns.pop('foo', None)
    ip.alias_manager.undefine_alias('bar')
    ip.magic('cd -')
    ip.user_ns['_dh'][:] = []
    
    # Check restoring
    ip.magic('store -r')
    nt.assert_equal(ip.user_ns['foo'], 78)
    nt.assert_in('bar', ip.alias_manager.alias_table)
    nt.assert_in(os.path.realpath(tmpd), ip.user_ns['_dh'])
    
    os.rmdir(tmpd) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:27,代码来源:test_storemagic.py

示例5: test_ipython_start_kernel_userns

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def test_ipython_start_kernel_userns():
    cmd = ('from IPython import start_kernel\n'
           'ns = {"tre": 123}\n'
           'start_kernel(user_ns=ns)')

    with setup_kernel(cmd) as client:
        msg_id = client.object_info('tre')
        msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
        content = msg['content']
        assert content['found']
        nt.assert_equal(content['string_form'], u'123')

        # user_module should be an instance of DummyMod
        msg_id = client.execute("usermod = get_ipython().user_module")
        msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
        content = msg['content']
        nt.assert_equal(content['status'], u'ok')
        msg_id = client.object_info('usermod')
        msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
        content = msg['content']
        assert content['found']
        nt.assert_in('DummyMod', content['string_form']) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:test_start_kernel.py

示例6: test_var_expand_local

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def test_var_expand_local(self):
        """Test local variable expansion in !system and %magic calls"""
        # !system
        ip.run_cell('def test():\n'
                    '    lvar = "ttt"\n'
                    '    ret = !echo {lvar}\n'
                    '    return ret[0]\n')
        res = ip.user_ns['test']()
        nt.assert_in('ttt', res)
        
        # %magic
        ip.run_cell('def makemacro():\n'
                    '    macroname = "macro_var_expand_locals"\n'
                    '    %macro {macroname} codestr\n')
        ip.user_ns['codestr'] = "str(12)"
        ip.run_cell('makemacro()')
        nt.assert_in('macro_var_expand_locals', ip.user_ns) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:test_interactiveshell.py

示例7: test_line_cell_magics

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def test_line_cell_magics():
    from IPython.core.magic import register_line_cell_magic

    @register_line_cell_magic
    def _bar_cellm(line, cell):
        pass
    
    ip = get_ipython()
    c = ip.Completer

    # The policy here is trickier, see comments in completion code.  The
    # returned values depend on whether the user passes %% or not explicitly,
    # and this will show a difference if the same name is both a line and cell
    # magic.
    s, matches = c.complete(None, '_bar_ce')
    nt.assert_in('%_bar_cellm', matches)
    nt.assert_in('%%_bar_cellm', matches)
    s, matches = c.complete(None, '%_bar_ce')
    nt.assert_in('%_bar_cellm', matches)
    nt.assert_in('%%_bar_cellm', matches)
    s, matches = c.complete(None, '%%_bar_ce')
    nt.assert_not_in('%_bar_cellm', matches)
    nt.assert_in('%%_bar_cellm', matches) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:25,代码来源:test_completer.py

示例8: test_file_amend

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def test_file_amend():
    """%%file -a amends files"""
    ip = get_ipython()
    with TemporaryDirectory() as td:
        fname = os.path.join(td, 'file2')
        ip.run_cell_magic("file", fname, u'\n'.join([
            'line1',
            'line2',
        ]))
        ip.run_cell_magic("file", "-a %s" % fname, u'\n'.join([
            'line3',
            'line4',
        ]))
        with open(fname) as f:
            s = f.read()
        nt.assert_in('line1\n', s)
        nt.assert_in('line3\n', s) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:test_magic.py

示例9: test_alias_magic

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def test_alias_magic():
    """Test %alias_magic."""
    ip = get_ipython()
    mm = ip.magics_manager

    # Basic operation: both cell and line magics are created, if possible.
    ip.run_line_magic('alias_magic', 'timeit_alias timeit')
    nt.assert_in('timeit_alias', mm.magics['line'])
    nt.assert_in('timeit_alias', mm.magics['cell'])

    # --cell is specified, line magic not created.
    ip.run_line_magic('alias_magic', '--cell timeit_cell_alias timeit')
    nt.assert_not_in('timeit_cell_alias', mm.magics['line'])
    nt.assert_in('timeit_cell_alias', mm.magics['cell'])

    # Test that line alias is created successfully.
    ip.run_line_magic('alias_magic', '--line env_alias env')
    nt.assert_equal(ip.run_line_magic('env', ''),
                    ip.run_line_magic('env_alias', '')) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:21,代码来源:test_magic.py

示例10: test_save

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def test_save():
    """Test %save."""
    ip = get_ipython()
    ip.history_manager.reset()   # Clear any existing history.
    cmds = [u"a=1", u"def b():\n  return a**2", u"print(a, b())"]
    for i, cmd in enumerate(cmds, start=1):
        ip.history_manager.store_inputs(i, cmd)
    with TemporaryDirectory() as tmpdir:
        file = os.path.join(tmpdir, "testsave.py")
        ip.run_line_magic("save", "%s 1-10" % file)
        with open(file) as f:
            content = f.read()
            nt.assert_equal(content.count(cmds[0]), 1)
            nt.assert_in('coding: utf-8', content)
        ip.run_line_magic("save", "-a %s 1-10" % file)
        with open(file) as f:
            content = f.read()
            nt.assert_equal(content.count(cmds[0]), 2)
            nt.assert_in('coding: utf-8', content) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:21,代码来源:test_magic.py

示例11: test_key_value_field

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def test_key_value_field():

    team = Team(name="Team1")
    test.assert_equal(team.options, {})
    team.options = "name = Ramast"
    test.assert_equal(team.options, {"name": "Ramast"})
    test.assert_equal(str(team.options), "name = Ramast\n")
    team.options = {"Age": 30}
    test.assert_equal(str(team.options), "Age = 30\n")
    # Notice int has been converted to string since we don't store value data type
    test.assert_equal(team.options, {"Age": "30"})
    team.options.update({"Name": "Ramast"})
    # Output should be
    #     Name = Ramast
    #     Age = 30
    # but since dictionary doesn't maintain order, I can't predict which one of the two lines will show first
    test.assert_in("Age = 30", str(team.options))
    test.assert_in("Name = Ramast", str(team.options))
    # Test invalid string
    try:
        team.options = "Name ?? Ramast"
        assert False, "Assigning invalid string should raise ValidationError"
    except ValidationError:
        pass 
开发者ID:rewardz,项目名称:django_model_helpers,代码行数:26,代码来源:test_key_value_field.py

示例12: assert_in

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def assert_in(result, expected_set):
        nums = xrange(1, len(expected_set)+1)
        for i, expected in zip(nums, expected_set):
            print("Expected %d:\n%s\n" % (i, expected))
        print("Got:\n%s\n" % result)
        assert result in expected_set 
开发者ID:gregbanks,项目名称:python-tabulate,代码行数:8,代码来源:common.py

示例13: test_debugging

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def test_debugging(self):
        console_msg = (
            "This should log\nSo should this\nAnd this too\nThis should log "
            "also\nSo should this\nAnd this too\nBut this one should\nAnd this"
            " one too"
        )

        logger = gogo.Gogo("debug.none").logger
        logger.debug("This should log")
        logger.info("So should this")
        logger.warning("And this too")

        logger = gogo.Gogo("debug.on", verbose=True).logger
        logger.debug("This should log also")
        logger.info("So should this")
        logger.warning("And this too")

        logger = gogo.Gogo("debug.off", verbose=False).logger
        logger.debug("This shouldn't log")
        logger.info("But this one should")
        logger.warning("And this one too")

        results = sys.stdout.getvalue().strip()
        nt.assert_in("This should log", results)
        nt.assert_not_in("This shouldn't log", results)
        nt.assert_equal(console_msg, results) 
开发者ID:reubano,项目名称:pygogo,代码行数:28,代码来源:test_main.py

示例14: assert_in

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def assert_in(a, b, msg=None):
            assert a in b, msg or '%r was not in %r' % (a, b) 
开发者ID:italia,项目名称:daf-recipes,代码行数:4,代码来源:test_controller.py

示例15: test_new_form_is_rendered

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_in [as 别名]
def test_new_form_is_rendered(self):

        url = url_for('harvest_new')

        app = self._get_test_app()

        response = app.get(url, extra_environ=self.extra_environ)

        assert_in('<form id="source-new"', response.body) 
开发者ID:italia,项目名称:daf-recipes,代码行数:11,代码来源:test_controller.py


注:本文中的nose.tools.assert_in方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。