issue10946 - ask for some advices on testing

4 views
Skip to first unread message

Wojciech Wojtyniak

unread,
Jun 13, 2011, 2:26:51 PM6/13/11
to Fellowship of packaging, Éric Araujo, Senthil Kumaran
Hello!

I'm fixing issue10946[1]. --skip-build option doesn't get to bdist_* commands called by bdist itself. Actually fix seemed easy to me by adding:

sub_cmd.skip_build = self.skip_build

before calling subcommand in run() method of bdist. It follows the way in which other options are set (eg. sub_cmd.owner or sub_cmd.group). Actually Eric suggested (in initial comment of issue) using a set_undefined_options() in every subcommand which should get skip_build from parent command. I assume that he is right and don't argue (his solutions is much more elegant, I think) but I need some comments on testing this.

Actually existing test looks like (I'll show only half of every test, second one is analogous):

pkg_pth, dist = self.create_dist()
cmd = bdist(dist)
cmd.skip_build = False
cmd.formats = ['ztar']
cmd.ensure_finalized()
self.assertFalse(self._get_platform_called)

It tests only if ensure_finalized() has called platform or not, and code in bdist.py looks like:

if self.plat_name is None:
if self.skip_build:
self.plat_name = util.get_platform()
else:
self.plat_name = self.get_finalized_command('build').plat_name

So test itself should have some improvements too. I've proposed them as follow: create a dummy command which can be called and test if skip_build will be propagated to it.

class CommandToSkip(Command):
def initialize_options(self):
self.skip_build = None

def finalize_options(self):
pass

def run(self):
pass

pkg_pth, dist = self.create_dist()
dist.command_obj['bdist_dumb'] = CommandToSkip(dist)
cmd = bdist(dist)
cmd.skip_build = False
cmd.formats = ['ztar']
cmd.ensure_finalized()
cmd.run()
self.assertFalse(dist.command_obj['bdist_dumb'].skip_build)

And this test actually test if the option has been passed to subcommands.

I have also confess that I've made a mistake and recognized Yannick's patch posted in issue thread by Eric as the same version of test as in repo, but it actually differs:

pkg_pth, dist = self.create_dist()
# With the skip_build option, command.build is not called.
cmd = bdist(dist)
cmd.skip_build = True
cmd.ensure_finalized()
cmd.run()
self.assertFalse(dist.have_run['build'])

Which doesn't fail after my fi

I'm thinking that the best way for fixing both bug and test is setting 'skip_built' option via set_undefined_options() (like Eric said) and developing a propper test, there I need advice: should I stick to my solution or switch Yannick's? Preserve tests write by Tarek? What are general advices for designing and writing test in project?

Thanks for all comments!

[1] http://bugs.python.org/issue10946
--
Wojciech Wojtyniak

Reply all
Reply to author
Forward
0 new messages