Merge lp:~james-w/launchpad/copy-archive-test-refactor into lp:launchpad
| Status: | Merged |
|---|---|
| Approved by: | Jelmer Vernooij on 2010-06-22 |
| Approved revision: | no longer in the source branch. |
| Merged at revision: | 11050 |
| Proposed branch: | lp:~james-w/launchpad/copy-archive-test-refactor |
| Merge into: | lp:launchpad |
| Diff against target: |
762 lines (+436/-150) 2 files modified
lib/lp/soyuz/scripts/populate_archive.py (+1/-1) lib/lp/soyuz/scripts/tests/test_populatearchive.py (+435/-149) |
| To merge this branch: | bzr merge lp:~james-w/launchpad/copy-archive-test-refactor |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Julian Edwards (community) | 2010-06-21 | Approve on 2010-06-22 | |
| Guilherme Salgado (community) | 2010-06-21 | Approve on 2010-06-21 | |
|
Review via email:
|
|||
Commit Message
Move some copy archive tests to use the factory, and add some more specific tests.
Description of the Change
Summary
The copy-archive tests are hard to understand as they use
the sampledata and test a lot of things in some methods.
There is even a method to check that the sampledata doesn't
change.
Proposed fix
Use the factory to create the data needed for a specific test,
and then break the tests down in to unit tests that test one
thing only.
Pre-implementation notes
None.
Implementation details
There is some duplication here, because I wasn't comfortable deleting
some of the existing tests as I wasn't sure what I hadn't tested with
new tests.
There are also two methods for running the script now, I left the original
one as it handled checking error messages, and that's what most of the
tests that use it now do.
I also created a small helper class to save passing around lots of values
between methods.
Tests
None as it is just test changes. You can run the tests in that file
with
./bin/test -cvv -s lp.soyuz.
Demo and Q/A
N/A
lint
None.
Thanks,
James
| James Westby (james-w) wrote : | # |
On Mon, 21 Jun 2010 18:01:25 -0000, Guilherme Salgado <email address hidden> wrote:
> Review: Approve
> Hi James,
>
> These changes look good to me; I only have a few comments.
>
> review approve
Great, thanks.
> Maybe you can mark the old tests with XXXs for someone who knows more
> about this check whether or not they can be removed?
Good idea, I'll look up the XXX policy and do this.
> > + def __init__(self, name, version,
> > + status=
>
> I think the style guide says that when you have a line break in the
> middle of a list of arguments you should indent all arguments at the
> same level, so
>
> def foo(self, bar, baz,
> etc...):
Will fix, thanks.
> I'd rather use self.assertIs(None, copy_archive) here because when that
> fails you'll get a helpful failure message instead of the "True is not
> False" one that assertTrue() gives.
Good idea, thanks.
> > + def createSourceDis
> > + """Create a distribution to be the source of a copy archive."""
> > + distroseries = self.createSour
> > + self.createSour
> > + self.layer.commit()
>
> Why do you need to commit here? If the commit is really necessary, I
> think it deserves a comment.
Because we are execing a script that will query the db from a different
transaction. I'll add the comment.
> When we remove the security proxy of something we should assign it to a
> different variable and name it appropriately (e.g. naked_build), to make
> sure it stands out wherever it's used. This is not a big deal in test
> code, but it's caused us some problems in production code.
Will fix, thanks.
> I wonder why a build.source_
> you know?
I don't know.
> Does this one deserve a comment as well?
Yes, will add it.
Thanks,
James
| James Westby (james-w) wrote : | # |
All comments addressed.
Julian, would you take a look to check you are happy with the proposed
changes?
Thanks,
James
| Julian Edwards (julian-edwards) wrote : | # |
James, thanks for making the code better!
>> Why do you need to commit here? If the commit is really necessary, I
>> think it deserves a comment.
>
>Because we are execing a script that will query the db from a different
>transaction. I'll add the comment.
Using commit() should be a last resort, as well as exec-ing scripts, as they are both very slow.
I don't have the time right now to delve very deeply into the code so I'll just raise some food for thought:
* Will store.flush() work instead of commit() ?
* Is the external script being invoked every test? Ideally it should be called once and only once with a simple case to make sure it's executable, then the bulk of the tests done via a script hook.
* It would be great if someone fixed the fucking hideous command line args to that script
Other than that, I expect as you guys use it more you'll see if it's buggy and needs more tests.
Cheers
J
| James Westby (james-w) wrote : | # |
On Tue, 22 Jun 2010 08:32:29 -0000, Julian Edwards <email address hidden> wrote:
> Review: Needs Information
> James, thanks for making the code better!
>
> >> Why do you need to commit here? If the commit is really necessary, I
> >> think it deserves a comment.
> >
> >Because we are execing a script that will query the db from a different
> >transaction. I'll add the comment.
>
> Using commit() should be a last resort, as well as exec-ing scripts, as they are both very slow.
>
> I don't have the time right now to delve very deeply into the code so I'll just raise some food for thought:
> * Will store.flush() work instead of commit() ?
No.
> * Is the external script being invoked every test? Ideally it should
> be called once and only once with a simple case to make sure it's
> executable, then the bulk of the tests done via a script hook.
Done.
> * It would be great if someone fixed the fucking hideous command line args to that script
Another time.
Please review the changes.
Thanks,
James

Hi James,
These changes look good to me; I only have a few comments.
review approve
On Mon, 2010-06-21 at 16:21 +0000, James Westby wrote:
[...]
>
> The copy-archive tests are hard to understand as they use
> the sampledata and test a lot of things in some methods.
> There is even a method to check that the sampledata doesn't
> change.
>
> Proposed fix
>
> Use the factory to create the data needed for a specific test,
> and then break the tests down in to unit tests that test one
> thing only.
>
> Pre-implementation notes
>
> None.
>
> Implementation details
>
> There is some duplication here, because I wasn't comfortable deleting
> some of the existing tests as I wasn't sure what I hadn't tested with
> new tests.
Maybe you can mark the old tests with XXXs for someone who knows more
about this check whether or not they can be removed?
> scripts. tests -m test_populatear chive soyuz/scripts/ populate_ archive. py' soyuz/scripts/ populate_ archive. py 2009-06-25 04:06:00 +0000 soyuz/scripts/ populate_ archive. py 2010-06-21 16:21:31 +0000 interfaces. publishing import active_ publishing_ status soyuz/scripts/ tests/test_ populatearchive .py' soyuz/scripts/ tests/test_ populatearchive .py 2010-05-20 15:27:12 +0000 soyuz/scripts/ tests/test_ populatearchive .py 2010-06-21 16:21:31 +0000 gerelease. sourcepackagena me PackagePublishi ngStatus. PUBLISHED, component="main"):
> There are also two methods for running the script now, I left the original
> one as it handled checking error messages, and that's what most of the
> tests that use it now do.
>
> I also created a small helper class to save passing around lots of values
> between methods.
>
> Tests
>
> None as it is just test changes. You can run the tests in that file
> with
>
> ./bin/test -cvv -s lp.soyuz.
>
> Demo and Q/A
>
> N/A
>
> lint
>
> None.
>
> Thanks,
>
> James
>
> differences between files attachment (review-diff.txt)
> === modified file 'lib/lp/
> --- lib/lp/
> +++ lib/lp/
> @@ -386,7 +386,7 @@
> :param distroseries: the distro series for which to create builds.
> :param archive: the archive for which to create builds.
> :param proc_families: the list of processor families for
> - which to create builds (optional).
> + which to create builds.
> """
> # Avoid circular imports.
> from lp.soyuz.
>
> === modified file 'lib/lp/
> --- lib/lp/
> +++ lib/lp/
> @@ -39,6 +40,16 @@
> return pub.sourcepacka
>
>
> +class PackageInfo:
> +
> + def __init__(self, name, version,
> + status=
I think the style guide says that when you have a line break in the
middle of a list of arguments you should indent all arguments at the
same level, so
def foo(self, bar, baz,
etc. ..):
> + self.name = name hiveScript( TestCaseWithFac tory): COPY, archive_name) (copy_archive is not None)
> + self.version = version
> + self.status = status
> + self.component = component
> +
> +
> class TestPopulateArc
> """Test the copy-package.py script."""
>
> @@ -118,6 +129,114 @@
> distro, ArchivePurpose.
> self.assertTrue
>
> + # Make sure the right source packa...