l.testing : package documentation

Part of lp

No package docstring
Module branding No module docstring; 1/1 functions documented
Module breadcrumbs Undocumented
Module browser A real, socket connecting browser.
Module dbuser Provides a context manager to run parts of a test as a different dbuser.
Module deprecated Infrastructure for testing LaunchpadFormView subclasses.
Module event Helper class for checking the event notifications.
Module factory Testing infrastructure for the Launchpad application.
Module fakemethod No module docstring; 1/1 classes documented
Module faketransaction Fake transaction manager.
Module fixture Launchpad test fixtures that have no better home.
Package gpgkeys OpenPGP keys used for testing.
Module karma Helper functions/classes to be used when testing the karma framework.
Package keyserver No package docstring; 2/3 modules, 0/1 packages documented
Module layers Layers used by Launchpad tests.
Module librarianhelpers Various helper functions for using the librarian in testing..
Module mail Useful helper functions used for testing.
Module mail_helpers Helper functions dealing with emails in tests.
Module matchers No module docstring; 15/20 classes, 1/1 functions documented
Module menu Helpers for testing menus.
Module pages Testing infrastructure for page tests.
Module pgsql Test harness for tests needing a PostgreSQL backend.
Module publication Helpers for testing out publication related code.
Module sampledata Constants that refer to values in sampledata.
Module script Helper functions for running external commands.
Module service_usage_helpers Helper functions dealing with IServiceUsage.
Module smtpd SMTP test helper.
Package swift No package docstring; 2/2 modules, 0/1 packages documented
Module systemdocs Infrastructure for setting up doctests.
Package tests Tests for the lp.testing module.
Package utilities No package docstring; 1/1 modules documented
Module views Functions to help with the testing of views.
Module xmlrpc Tools for testing XML-RPC services.
Module yuixhr Fixture code for YUITest + XHR integration testing.
Module _login No module docstring; 1/2 functions documented
Module _webservice No module docstring; 1/1 functions documented

From the __init__.py module:

Class AbstractYUITestCase No class docstring; 3/4 methods documented
Class BrowserTestCase A TestCase class for browser tests.
Class EventRecorder Intercept and record Zope events.
Class ExpectedException An ExpectedException that provides access to the caught exception.
Class FakeAdapterMixin A testcase mixin that helps register/unregister Zope adapters.
Class FakeLaunchpadRequest No class docstring; 1/1 methods documented
Class FakeTime Provides a controllable implementation of time.time().
Class RequestTimelineCollector Collect timeline events logged in web requests.
Class StormStatementRecorder A Storm tracer to record all database queries.
Class TestCase Provide Launchpad-specific test facilities.
Class TestCaseWithFactory No class docstring; 5/8 methods, 1/1 static methods documented
Class WebServiceTestCase Test case optimized for testing the web service using launchpadlib.
Class YUIUnitTestCase Undocumented
Class ZopeTestInSubProcess Run tests in a sub-process, respecting Zope idiosyncrasies.
Function admin_logged_in Undocumented
Function anonymous_logged_in Make a context manager for running with the anonymous log in.
Function api_url Find the web service URL of a data model object.
Function celebrity_logged_in Make a context manager for running logged in as a celebrity.
Function launchpadlib_credentials_for Create launchpadlib credentials for the given person.
Function launchpadlib_for Create a Launchpad object for the given person.
Function login Simulates a login, using the specified email.
Function login_admin Log in as an admin.
Function login_as Login as a person or a team.
Function login_celebrity Login as a celebrity.
Function login_person Login the person with their preferred email.
Function login_team Login as a member of 'team'.
Function logout Tear down after login(...), ending the current interaction.
Function oauth_access_token_for Find or create an OAuth access token for the given person.
Function person_logged_in Make a context manager for running logged in as 'person'.
Function run_with_login Run 'function' with 'person' logged in.
Function with_celebrity_logged_in Decorate a function so that it's run with a celebrity logged in.
Function with_person_logged_in Undocumented
Function build_yui_unittest_suite Undocumented
Function clean_up_reactor Undocumented
Function extract_lp_cache Undocumented
Function feature_flags Provide a context in which feature flags work.
Function map_branch_contents Return all files in branch at branch_url.
Function monkey_patch In the ContextManager scope, monkey-patch values.
Function nonblocking_readline Non-blocking readline.
Function normalize_whitespace Replace all sequences of whitespace with a single space.
Function record_statements Run the function and record the sql statements that are executed.
Function record_two_runs A helper that returns the two storm statement recorders
Function reset_logging Reset the logging system back to defaults
Function run_process Run the given command as a subprocess.
Function run_script Run the given command line as a subprocess.
Function run_with_storm_debug A helper function to run a function with storm debug tracing on.
Function set_feature_flag Set a feature flag to the specified value.
Function time_counter A generator for yielding datetime values.
Function unlink_source_packages Remove all links between the product and source packages.
Function validate_mock_class Validate method signatures in mock classes derived from real classes.
Function verifyObject A specialized verifyObject which removes the security proxy of the
Function ws_object Convert an object into its webservice version.
Function _harvest_yui_test_files Undocumented
@contextmanager
def admin_logged_in():
Undocumented
@contextmanager
def anonymous_logged_in():
Make a context manager for running with the anonymous log in.
@contextmanager
def celebrity_logged_in(celebrity_name):
Make a context manager for running logged in as a celebrity.
def login(email, participation=None):
Simulates a login, using the specified email.

If the lp.testing.ANONYMOUS constant is supplied as the email, you'll be logged in as the anonymous user.

You can optionally pass in a participation to be used. If no participation is given, a LaunchpadTestRequest is used.

If the participation provides IPublicationRequest, it must implement setPrincipal(), otherwise it must allow setting its principal attribute.

def login_admin(participation=None):
Log in as an admin.
def login_as(person_or_team, participation=None):
Login as a person or a team.
Parametersperson_or_teamA person, a team, ANONYMOUS or None. None and ANONYMOUS are equivalent, and will log the person in as the anonymous user.
def login_celebrity(celebrity_name, participation=None):
Login as a celebrity.
def login_person(person, participation=None):
Login the person with their preferred email.
def login_team(team, participation=None):
Login as a member of 'team'.
def logout():
Tear down after login(...), ending the current interaction.

Note that this is done automatically in LaunchpadFunctionalTestCase's tearDown method so you generally won't need to call this.

@contextmanager
def person_logged_in(person):
Make a context manager for running logged in as 'person'.
ParameterspersonA person, an account, a team or ANONYMOUS. If a team, will log in as an arbitrary member of that team.
def run_with_login(person, function, *args, **kwargs):
Run 'function' with 'person' logged in.
def with_celebrity_logged_in(celebrity_name):
Decorate a function so that it's run with a celebrity logged in.
def with_person_logged_in(person):
Undocumented
def api_url(obj):
Find the web service URL of a data model object.

This makes it easy to load up the factory object you just created in launchpadlib.

ParametersWhich web service version to use.
ReturnsA relative URL suitable for passing into Launchpad.load().
def launchpadlib_credentials_for(consumer_name, person, permission=OAuthPermission.WRITE_PRIVATE, context=None):
Create launchpadlib credentials for the given person.
Parametersconsumer_nameAn OAuth consumer name.
personA person (or the name of a person) for whom to create or find credentials.
permissionAn OAuthPermission (or its token) designating the level of permission the credentials should have.
contextThe OAuth context for the credentials.
ReturnsA launchpadlib Credentials object.
def launchpadlib_for(consumer_name, person=None, permission=OAuthPermission.WRITE_PRIVATE, context=None, version='devel', service_root='http://api.launchpad.dev/'):
Create a Launchpad object for the given person.
Parametersconsumer_nameAn OAuth consumer name.
personA person (or the name of a person) for whom to create or find credentials.
permissionAn OAuthPermission (or its token) designating the level of permission the credentials should have.
contextThe OAuth context for the credentials.
versionThe version of the web service to access.
service_rootThe root URL of the web service to access.
ReturnsA launchpadlib Launchpad object.
def oauth_access_token_for(consumer_name, person, permission, context=None):
Find or create an OAuth access token for the given person.
:param consumer_name: An OAuth consumer name.
:param person: A person (or the name of a person) for whom to create
    or find credentials.
:param permission: An OAuthPermission (or its token) designating
    the level of permission the credentials should have.
:param context: The OAuth context for the credentials (or a string
    designating same).

:return: A tuple of an OAuthAccessToken object and its secret.
def reset_logging():
Reset the logging system back to defaults

Currently, defaults means 'the way the Z3 testrunner sets it up' plus customizations made in lp_sitecustomize

def record_statements(function, *args, **kwargs):
Run the function and record the sql statements that are executed.
Returnsa tuple containing the return value of the function, and a list of sql statements.
def record_two_runs(tested_method, item_creator, first_round_number, second_round_number=None, login_method=None, record_request=False):
A helper that returns the two storm statement recorders obtained when running tested_method after having run the method {item_creator} {first_round_number} times and then again after having run the same method {second_round_number} times.

If {login_method} is not None, it is called before each batch of {item_creator} calls.

If {record_request} is True, RequestTimelineCollector is used to get the query counts, so {tested_method} should make a web request. Otherwise, StormStatementRecorder is used to get the query count.

Returnsa tuple containing the two recorders obtained by the successive runs.
def run_with_storm_debug(function, *args, **kwargs):
A helper function to run a function with storm debug tracing on.
def build_yui_unittest_suite(app_testing_path, yui_test_class):
Undocumented
def _harvest_yui_test_files(file_path):
Undocumented
@contextmanager
def feature_flags():
Provide a context in which feature flags work.
def time_counter(origin=None, delta=timedelta(5)):

A generator for yielding datetime values.

Each time the generator yields a value, the origin is incremented by the delta.

>>> now = time_counter(datetime(2007, 12, 1), timedelta(days=1))
>>> now.next()
datetime.datetime(2007, 12, 1, 0, 0)
>>> now.next()
datetime.datetime(2007, 12, 2, 0, 0)
>>> now.next()
datetime.datetime(2007, 12, 3, 0, 0)
def run_script(cmd_line, env=None, cwd=None):
Run the given command line as a subprocess.
Parameterscmd_lineA command line suitable for passing to subprocess.Popen.
envAn optional environment dict. If none is given, the script will get a copy of your present environment. Either way, PYTHONPATH will be removed from it because it will break the script.
ReturnsA 3-tuple of stdout, stderr, and the process' return code.
def run_process(cmd, env=None):
Run the given command as a subprocess.

This differs from run_script in that it does not execute via a shell and it explicitly connects stdin to /dev/null so that processes will not be able to hang, waiting for user input.

Parameterscmd_lineA command suitable for passing to subprocess.Popen.
envAn optional environment dict. If none is given, the script will get a copy of your present environment. Either way, PYTHONPATH will be removed from it because it will break the script.
ReturnsA 3-tuple of stdout, stderr, and the process' return code.
def normalize_whitespace(string):
Replace all sequences of whitespace with a single space.
def map_branch_contents(branch):
Return all files in branch at branch_url.
Parametersbranch_urlthe URL for an accessible branch.
Returnsa dict mapping file paths to file contents. Only regular files are included.
def set_feature_flag(name, value, scope=u'default', priority=1):
Set a feature flag to the specified value.

In order to access the flag, use the feature_flags context manager or set the feature controller in some other way. :param name: The name of the flag. :param value: The value of the flag. :param scope: The scope in which the specified value applies.

def validate_mock_class(mock_class):

Validate method signatures in mock classes derived from real classes.

We often use mock classes in tests which are derived from real classes.

This function ensures that methods redefined in the mock class have the same signature as the corresponding methods of the base class.

>>> class A:
...
...     def method_one(self, a):
...         pass
>>>
>>> class B(A):
...     def method_one(self, a):
...        pass
>>> validate_mock_class(B)

If a class derived from A defines method_one with a different signature, we get an AssertionError.

>>> class C(A):
...     def method_one(self, a, b):
...        pass
>>> validate_mock_class(C)
Traceback (most recent call last):
...
AssertionError: Different method signature for method_one:...

Even a parameter name must not be modified.

>>> class D(A):
...     def method_one(self, b):
...        pass
>>> validate_mock_class(D)
Traceback (most recent call last):
...
AssertionError: Different method signature for method_one:...

If validate_mock_class() for anything but a class, we get an AssertionError.

>>> validate_mock_class('a string')
Traceback (most recent call last):
...
AssertionError: validate_mock_class() must be called for a class
def ws_object(launchpad, obj):
Convert an object into its webservice version.
ParameterslaunchpadThe Launchpad instance to convert from.
objThe object to convert.
ReturnsA launchpadlib Entry object.
@contextmanager
def monkey_patch(context, **kwargs):
In the ContextManager scope, monkey-patch values.

The context may be anything that supports setattr. Packages, modules, objects, etc. The kwargs are the name/value pairs for the values to set.

def unlink_source_packages(product):
Remove all links between the product and source packages.

A product cannot be deactivated if it is linked to source packages.

def extract_lp_cache(text):
Undocumented
def nonblocking_readline(instream, timeout):
Non-blocking readline.

Files must provide a valid fileno() method. This is a test helper as it is inefficient and unlikely useful for production code.

def clean_up_reactor():
Undocumented
def verifyObject(iface, candidate, tentative=0):
A specialized verifyObject which removes the security proxy of the object before verifying it.
API Documentation for Launchpad, generated by pydoctor at 2018-10-17 00:00:11.