コード例 #1
0
ファイル: test_options.py プロジェクト: vamega/paver
def test_default_namespace_searching():
    ns = options.Namespace()
    ns.val = 0
    ns.foo = options.Bunch(foo=1, bar=2, baz=3, blorg=6)
    ns.bar = options.Bunch(foo=4, baz=5, bop=7, val=8)
    assert ns.val == 0, "Top namespace has priority"
    assert ns.foo == options.Bunch(foo=1, bar=2, baz=3, blorg=6)
    assert ns.foo.foo == 1
    assert ns.bar.foo == 4
    assert ns.baz == 5
    assert ns.blorg == 6
    
    try:
        ns['does not exist']
        assert False, "expected key error for missing item"
    except KeyError:
        pass
    
    del ns['val']
    
    assert ns.val == 8, "Now getting val from inner dict"
    
    del ns.bar.val
    
    try:
        a = ns['val']
        assert False, "expected exception for deleted item %s" % (ns)
    except KeyError:
        pass
    
    del ns.foo
    assert ns._sections == ['bar']
コード例 #2
0
ファイル: test_options.py プロジェクト: vamega/paver
def test_search_order_is_adjustable():
    ns = options.Namespace(
        bar=options.Bunch(val=1, blorg=4)
    )
    ns.baz=options.Bunch(val=2, bop=5)
    ns.foo=options.Bunch(val=3, bam=6)

    assert ns.blorg == 4
    assert ns.val == 3
    
    ns.order('baz')
    assert ns.val == 2
    assert ns.bop == 5
    try:
        ns.bam
        assert False, "expected attribute error for item not in search"
    except AttributeError:
        pass
    
    ns.order('bar', 'baz')
    assert ns.val == 1
    assert ns.blorg == 4
    assert ns.bop == 5
    
    ns.order('baz', add_rest=True)
    assert ns.val == 2
    assert ns.bam == 6
コード例 #3
0
ファイル: test_setuputils.py プロジェクト: vamega/paver
def test_task_with_distutils_dep():
    _sdist.reset()

    @tasks.task
    @tasks.needs("paver.tests.test_setuputils.sdist")
    def sdist():
        assert _sdist.called

    env = _set_environment(sdist=sdist)
    env.options = options.Bunch(setup=options.Bunch())
    install_distutils_tasks()
    d = _get_distribution()
    d.cmdclass['sdist'] = _sdist

    task_obj = env.get_task('sdist')
    assert task_obj == sdist
    needs_obj = env.get_task(task_obj.needs[0])
    assert isinstance(needs_obj, DistutilsTask)
    assert needs_obj.command_class == _sdist

    tasks._process_commands(['sdist', "-f"])
    assert sdist.called
    assert _sdist.called
    cmd = d.get_command_obj('sdist')
    print_("Cmd is: %s" % cmd)
    assert cmd.foo
    assert _sdist.foo_set
コード例 #4
0
ファイル: test_options.py プロジェクト: vamega/paver
def test_add_dict_to_order():
    ns = options.Namespace()
    ns.foo = options.Bunch(val="yo")
    ns.bar = options.Bunch(val="there")
    assert ns.val == "there"
    ns.order('foo')
    assert ns.val == "yo"
    ns.order(dict(val="new"), add_rest=True)
    assert ns.val == "new", "Got %s" % (ns.val)
コード例 #5
0
ファイル: test_options.py プロジェクト: vamega/paver
def test_update():
    ns = options.Namespace()
    ns.update(foo=options.Bunch(val=2))
    assert ns._sections == ['foo'], str(ns._sections)
    ns.update([('bar', options.Bunch(val=2))])
    assert ns._sections == ['bar', 'foo'], str(ns._sections)
    ns.update(dict(baz=options.Bunch(val=3)))
    assert ns._sections == ['baz', 'bar', 'foo'], str(ns._sections)
    ns(hi='there')
    assert ns.hi == 'there'
コード例 #6
0
ファイル: test_setuputils.py プロジェクト: vamega/paver
def test_distutils_task_finder():
    env = _set_environment()
    env.options = options.Bunch(setup=options.Bunch())
    dist = _get_distribution()
    dutf = DistutilsTaskFinder()
    task = dutf.get_task('distutils.command.install')
    assert task
    task = dutf.get_task('install')
    assert task
    task = dutf.get_task('foo')
    assert task is None
コード例 #7
0
ファイル: test_setuputils.py プロジェクト: vamega/paver
def test_negative_opts_handled_for_distutils():
    _sdist.reset()
    env = _set_environment()
    env.options = options.Bunch(setup=options.Bunch())
    install_distutils_tasks()
    d = _get_distribution()
    d.cmdclass['sdist'] = _sdist_with_default_foo

    tasks._process_commands(['sdist', '--no-foo'])

    assert _sdist.called
    assert not _sdist.foo_set
コード例 #8
0
ファイル: test_setuputils.py プロジェクト: vamega/paver
def test_distutils_tasks_should_not_get_extra_options():
    _sdist.reset()
    env = _set_environment()
    env.options = options.Bunch(setup=options.Bunch())
    install_distutils_tasks()
    d = _get_distribution()
    d.cmdclass['sdist'] = _sdist

    tasks._process_commands(['sdist'])
    assert _sdist.called
    assert not _sdist.foo_set
    opts = d.get_option_dict('sdist')
    assert 'foo' not in opts
コード例 #9
0
ファイル: test_options.py プロジェクト: vamega/paver
def test_clear():
    ns = options.Namespace(foo=options.Bunch(bar=1))
    ns.order('foo')
    ns.clear()
    assert len(ns) == 0
    assert len(ns._sections) == 0
    assert ns._ordering == None
コード例 #10
0
ファイル: test_setuputils.py プロジェクト: vamega/paver
def test_needs_sdist_without_options():
    """Test that a custom sdist can be used in needs() w/o options.setup"""
    _sdist.reset()

    @tasks.task
    @tasks.needs("paver.tests.test_setuputils.sdist")
    def sdist():
        assert _sdist.called

    @tasks.task
    @tasks.needs("sdist")
    def t1():
        pass

    env = _set_environment(sdist=sdist, t1=t1)
    env.options = options.Bunch()
    install_distutils_tasks()
    d = _get_distribution()
    d.cmdclass['sdist'] = _sdist

    tasks._process_commands(['t1'])
    assert sdist.called
    assert _sdist.called
    assert t1.called
    cmd = d.get_command_obj('sdist')
    assert not cmd.foo
    assert not _sdist.foo_set
コード例 #11
0
ファイル: test_setuputils.py プロジェクト: vamega/paver
def test_override_distutils_command():
    @tasks.task
    def sdist():
        pass

    env = _set_environment(sdist=sdist)
    env.options = options.Bunch(setup=options.Bunch())

    install_distutils_tasks()
    d = _get_distribution()

    d.cmdclass['sdist'] = _sdist
    tasks._process_commands(
        ['sdist', 'paver.tests.test_setuputils.sdist', '-f'])
    assert sdist.called
    assert _sdist.called
    assert _sdist.foo_set
    assert isinstance(_sdist.fin, _sdist)
コード例 #12
0
ファイル: test_options.py プロジェクト: vamega/paver
def test_setdotted_values():
    ns = options.Namespace()
    ns.foo = options.Bunch()
    ns.setdotted("foo.bar", "baz")
    assert ns.foo.bar == "baz"
    ns.setdotted("bligger.bar", "flilling")
    assert ns.bligger.bar == "flilling"
    ns.val = 10
    try:
        ns.setdotted("val.yo", 42)
        assert False, "Expected exception when a value is found instead of bunch"
    except options.OptionsError:
        pass
コード例 #13
0
ファイル: test_doctools.py プロジェクト: kvbik/paver
def test_cogging():
    env = tasks.Environment(doctools)
    tasks.environment = env
    opt = env.options
    opt.cog = options.Bunch()
    basedir = path(__file__).dirname()
    opt.cog.basedir = basedir
    opt.cog.pattern = "*.rst"
    opt.cog.includedir = basedir / "data"
    env.options = opt
    doctools.cog()
    textfile = basedir / "data/textfile.rst"
    data = open(textfile).read()
    print data
    assert "print sys.path" in data
    doctools.uncog()
    data = open(textfile).read()
    assert "print sys.path" not in data
コード例 #14
0
def test_cogging():
    if not paver.doctools.has_cog:
        raise SkipTest("Cog must be installed for this test")
    env = tasks.Environment(doctools)
    tasks.environment = env
    opt = env.options
    opt.cog = options.Bunch()
    basedir = path(__file__).dirname()
    opt.cog.basedir = basedir
    opt.cog.pattern = "*.rst"
    opt.cog.includedir = basedir / "data"
    env.options = opt
    doctools.cog()
    textfile = basedir / "data/textfile.rst"
    with open(textfile) as f:
        data = f.read()
    print_(data)
    assert "print sys.path" in data
    doctools.uncog()
    with open(textfile) as f:
        data = f.read()
    assert "print sys.path" not in data
コード例 #15
0
ファイル: test_options.py プロジェクト: vamega/paver
def test_callables_in_bunch():
    b = options.Bunch(foo = lambda: "hi")
    assert b.foo == "hi", "foo was: %s" % b.foo
コード例 #16
0
ファイル: test_options.py プロジェクト: vamega/paver
def test_setdefault():
    ns = options.Namespace()
    ns.setdefault('foo', options.Bunch())
    assert ns._sections == ['foo'], ns._sections