File: test_setuputils.py

package info (click to toggle)
python-paver 1.2.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,220 kB
  • ctags: 979
  • sloc: python: 4,678; makefile: 20
file content (152 lines) | stat: -rw-r--r-- 4,212 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from distutils.core import Command
from paver.deps.six import print_

from paver.setuputils import install_distutils_tasks, \
                            DistutilsTaskFinder, _get_distribution, \
                            DistutilsTask
from paver import tasks, options
from paver.tests.utils import _set_environment

class _sdist(Command):
    called = False
    foo_set = False
    fin = None
    user_options = [("foo", "f", "Foo"), ("no-foo", None, "No Foo")]
    boolean_options = ['foo']
    negative_opt = {'no-foo' : 'foo'}
    
    def initialize_options(self):
        self.foo = False
        
    def finalize_options(self):
        pass
    
    def run(self):
        _sdist.called = True
        _sdist.foo_set = self.foo
        _sdist.fin = self.get_finalized_command("sdist")
    
    @classmethod
    def reset(cls):
        cls.called = False
        cls.foo_set = False
        cls.fin = None


class _sdist_with_default_foo(_sdist):
    def initialize_options(self):
        self.foo = True

#----------------------------------------------------------------------
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)

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

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
    
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

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

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