c.l.t.test_helpers : module documentation

Part of canonical.launchpad.tests

No module docstring
Function make_test_tarball_1 Generate a test tarball that looks something like a source tarball which
Function make_test_tarball_2 Generate a test tarball string that has some interesting files in a common
Function test_join_lines
>>> helpers.join_lines('foo', 'bar', 'baz')
Function test_shortest
>>> helpers.shortest(['xyzzy', 'foo', 'blah'])
Class DummyLanguage Undocumented
Class DummyLanguageSet Undocumented
Class DummyPerson Undocumented
Class DummyResponse Undocumented
Class DummyRequest Undocumented
Function adaptRequestToLanguages Undocumented
Class DummyRequestLanguages Undocumented
Class DummyLaunchBag Undocumented
Function test_preferred_or_request_languages
>>> from zope.app.testing.placelesssetup import setUp, tearDown
Function test_shortlist_returns_all_elements Override the warning function since by default all warnings raises an
Class TruncateTextTest No class docstring; 4/4 methods documented
Class TestEmailPeople Tests for emailPeople
Function test_suite Undocumented
def make_test_tarball_1():

Generate a test tarball that looks something like a source tarball which has exactly one directory called 'po' which is interesting (i.e. contains some files which look like POT/PO files).

>>> tarball = make_test_tarball_1()

Check it looks vaguely sensible.

>>> names = tarball.getnames()
>>> 'uberfrob-0.1/po/cy.po' in names
True
def make_test_tarball_2():

Generate a test tarball string that has some interesting files in a common prefix.

>>> tarball = make_test_tarball_2()

Check the expected files are in the archive.

# XXX: 2010-04-26, Salgado, bug=570244: This rstrip('/') is to make the # test pass on python2.5 and 2.6. >>> [name.rstrip('/') for name in tarball.getnames()] ['test', 'test/cy.po', 'test/es.po', 'test/test.pot']

Check the contents.

>>> f = tarball.extractfile('test/cy.po')
>>> f.readline()
'# Test PO file.\n'
def test_join_lines():
>>> helpers.join_lines('foo', 'bar', 'baz')
'foo\nbar\nbaz\n'
def test_shortest():
>>> helpers.shortest(['xyzzy', 'foo', 'blah'])
['foo']
>>> helpers.shortest(['xyzzy', 'foo', 'bar'])
['foo', 'bar']
def adaptRequestToLanguages(request):
Undocumented
def test_preferred_or_request_languages():
>>> from zope.app.testing.placelesssetup import setUp, tearDown
>>> from zope.app.testing import ztapi
>>> from zope.i18n.interfaces import IUserPreferredLanguages
>>> from lp.services.geoip.interfaces import IRequestPreferredLanguages
>>> from lp.services.geoip.interfaces import IRequestLocalLanguages
>>> from canonical.launchpad.helpers import preferred_or_request_languages

First, test with a person who has a single preferred language.

>>> setUp()
>>> ztapi.provideUtility(ILanguageSet, DummyLanguageSet())
>>> ztapi.provideUtility(ILaunchBag, DummyLaunchBag('foo.bar@canonical.com', dummyPerson))
>>> ztapi.provideAdapter(IBrowserRequest, IRequestPreferredLanguages, adaptRequestToLanguages)
>>> ztapi.provideAdapter(IBrowserRequest, IRequestLocalLanguages, adaptRequestToLanguages)
>>> languages = preferred_or_request_languages(DummyRequest())
>>> len(languages)
1
>>> languages[0].code
'es'
>>> tearDown()

Then test with a person who has no preferred language.

>>> setUp()
>>> ztapi.provideUtility(ILanguageSet, DummyLanguageSet())
>>> ztapi.provideUtility(ILaunchBag, DummyLaunchBag('foo.bar@canonical.com', dummyNoLanguagePerson))
>>> ztapi.provideAdapter(IBrowserRequest, IRequestPreferredLanguages, adaptRequestToLanguages)
>>> ztapi.provideAdapter(IBrowserRequest, IRequestLocalLanguages, adaptRequestToLanguages)
>>> languages = preferred_or_request_languages(DummyRequest())
>>> len(languages)
6
>>> languages[0].code
'ja'
>>> tearDown()
def test_shortlist_returns_all_elements():

Override the warning function since by default all warnings raises an exception and we can't test the return value of the function.

>>> import warnings
>>> def warn(message, category=None, stacklevel=2):
...     if category is None:
...         category = 'UserWarning'
...     else:
...         category = category.__class__.__name__
...     print "%s: %s" % (category, message)
>>> old_warn = warnings.warn
>>> warnings.warn = warn

Show that shortlist doesn't crop the results when a warning is printed.

>>> from canonical.launchpad.helpers import shortlist
>>> shortlist(list(range(10)), longest_expected=5) #doctest: +ELLIPSIS
UserWarning: shortlist() should not...
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> shortlist(xrange(10), longest_expected=5) #doctest: +ELLIPSIS
UserWarning: shortlist() should not...
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Reset our monkey patch.

>>> warnings.warn = old_warn
def test_suite():
Undocumented
API Documentation for Launchpad, generated by pydoctor at 2010-09-27 00:00:11.