Else, the repeated calls to getUtility(IArchiveArchSet) clutter the code.
Maybe you should use a local or instance variable to store that?
Also, I think getRestrictedfamilies should be getRestrictedFamilies to be
proper camelCase. I know this is not your doing but could you please fix that
if it does not have too many call sites?
> + results = dict(
> + (row[0].name, row[1] is not None) for row in result_set)
> + self.assertEquals(
> + { 'arm' : False, 'cell-proc' : True, 'omap' : False},
I quite liked the approach from the first test where you converted the complex
result set to a dict. Maybe you can do something similar here to have only one
assert in the end? In case of a test failure the failure message will be much
clearer.
My suggestion:
result = [(row.archive, row.processorfamily) for row in result_set]
self.assertEqual([(self.ppa, self.cell_proc)], result)
Hi Jelmer,
thank you for this quick fix. I have a few comments about the tests and will
wait for your reply before I approve the branch.
Cheers,
Henning
Am 04.07.2010 01:40, schrieb Jelmer Vernooij: soyuz/model/ archivearch. py' soyuz/model/ archivearch. py 2010-02-25 15:25:30 +0000 soyuz/model/ archivearch. py 2010-07-03 23:40:54 +0000 launchpad. webapp. interfaces import ( processorfamily == ProcessorFamily .id)) .archive == archive.id, processorfamily == ProcessorFamily .id))) *origin) .find( y.restricted == True)) soyuz/tests/ test_archivearc h.py' soyuz/tests/ test_archivearc h.py 2010-02-25 15:25:30 +0000 soyuz/tests/ test_archivearc h.py 2010-07-03 23:40:54 +0000 interfaces. distribution import IDistributionSet
> === modified file 'lib/lp/
> --- lib/lp/
> +++ lib/lp/
> @@ -13,7 +13,7 @@
> from canonical.
> IStoreSelector, MAIN_STORE, DEFAULT_FLAVOR)
>
> -from storm.expr import Join, LeftJoin
> +from storm.expr import And, Join, LeftJoin
> from storm.locals import Int, Reference, Storm
>
>
> @@ -65,7 +65,8 @@
> ProcessorFamily,
> LeftJoin(
> ArchiveArch,
> - ArchiveArch.
> + And(ArchiveArch
> + ArchiveArch.
> result_set = store.using(
> (ProcessorFamily, ArchiveArch),
> (ProcessorFamil
>
> === modified file 'lib/lp/
> --- lib/lp/
> +++ lib/lp/
> @@ -11,6 +11,7 @@
>
> from lp.testing import TestCaseWithFactory
>
> +from lp.registry.
from canonical. launchpad. interfaces import ILaunchpadCeleb rities
See below.
> from lp.registry. interfaces. person import IPersonSet interfaces. archivearch import IArchiveArchSet interfaces. processor import IProcessorFamilySet veArch, self).setUp() IPersonSet) .getByName( 'cprov' ).archive IDistributionSe t)['ubuntu' ]
> from lp.soyuz.
> from lp.soyuz.
> @@ -24,6 +25,8 @@
> super(TestArchi
>
> self.ppa = getUtility(
> + ubuntu = getUtility(
> + self.ubuntu_archive = ubuntu.main_archive
We have a celebrity that you should use for this.
getUtility( ILaunchpadCeleb rities) .ubuntu
> pss = getUtility( IProcessorFamil ySet) associations( self): restricted_ uassociations( self): (all(aa is None for aa in archivearches)) association( self): restricted_ association( self): IArchiveArchSet ).new(self. ppa, self.cell_proc)
> self.cell_proc = pss.new(
> 'cell-proc', 'PS cell processor', 'Screamingly faaaaaaaaaaaast',
> @@ -32,7 +35,7 @@
> 'omap', 'Multimedia applications processor',
> 'Does all your sound & video', True)
>
> - def test_no_
> + def test_no_
> """Our archive is not associated with any restricted processor
> families yet."""
> result_set = list(
> @@ -40,7 +43,7 @@
> archivearches = [row[1] for row in result_set]
> self.assertTrue
>
> - def test_single_
> + def test_single_
> """Our archive is now associated with one of the restricted processor
> families."""
> getUtility(
> @@ -52,6 +55,29 @@
> { 'arm' : False, 'cell-proc' : True, 'omap' : False},
Leading space. ^ Copied&pasted further down ... ;)
> results) _association_ archive_ only(self) :
>
> + def test_restricted
Looks like this naming is used throughout this file but the correct name would ctedFamilies_ archive_ only" or similar.
probably be "test_getRestri
https:/ /dev.launchpad. net/TestsStyleG uide#Python Test Cases
> + """Test that only the associated archs for the archive itself are
> + returned."""
This doc string violates our docstring conventions but you don't need a doc
string for test methods anyway, just a comment.
# Test that only the associated archs for the archive itself are
# returned.
I see more instances of that, maybe you correct fix them as a drive-by fix?
Thank you very much!
> + getUtility( IArchiveArchSet ).new(self. ppa, self.cell_proc) IArchiveArchSet ).new(self. ubuntu_ archive, self.omap)
> + getUtility(
Hm, maybe you could add a factory method to the LaunchpadObject Factory for
ArchiveArch? Or are there reasons against that?
> + result_set = list( IArchiveArchSet ).getRestricted families( self.ppa) )
> + getUtility(
Else, the repeated calls to getUtility( IArchiveArchSet ) clutter the code.
Maybe you should use a local or instance variable to store that?
Also, I think getRestrictedfa milies should be getRestrictedFa milies to be
proper camelCase. I know this is not your doing but could you please fix that
if it does not have too many call sites?
> + results = dict(
> + (row[0].name, row[1] is not None) for row in result_set)
> + self.assertEquals(
> + { 'arm' : False, 'cell-proc' : True, 'omap' : False},
Leading space. ^
> + results) by_archive( self): getByArchive. """ IArchiveArchSet ).new(self. ppa, self.cell_proc) IArchiveArchSet ).new(self. ubuntu_ archive, self.omap) IArchiveArchSet ).getByArchive( self.ppa) )
> +
> + def test_get_
> + """Test ArchiveArchSet.
> + getUtility(
> + getUtility(
> + result_set = list(
> + getUtility(
Same comment about storing archive_arch_set
> + self.assertEqua ls(1, len(result_set)) ls(self. ppa, result_ set[0]. archive) ls(self. cell_proc, result_ set[0]. processorfamily )
> + self.assertEqua
> + self.assertEqua
I quite liked the approach from the first test where you converted the complex
result set to a dict. Maybe you can do something similar here to have only one
assert in the end? In case of a test failure the failure message will be much
clearer.
My suggestion:
result = [(row.archive, row.processorfa mily) for row in result_set] l([(self. ppa, self.cell_proc)], result)
self.assertEqua
> + TestLoader( ).loadTestsFrom Name(__ name__)
>
> def test_suite():
> return unittest.
>