apache_beam.testing.test_utils module

Utility methods for testing

For internal use only; no backwards-compatibility guarantees.

class apache_beam.testing.test_utils.TempDir[source]

Bases: future.types.newobject.newobject

Context Manager to create and clean-up a temporary directory.


Returns the path to the temporary directory.

create_temp_file(suffix='', lines=None)[source]

Creates a temporary file in the temporary directory.

  • suffix (str) – The filename suffix of the temporary file (e.g. ‘.txt’)
  • lines (List[str]) – A list of lines that will be written to the temporary file.

The name of the temporary file created.

apache_beam.testing.test_utils.compute_hash(content, hashing_alg='sha1')[source]

Compute a hash value of a list of objects by hashing their string representations.

apache_beam.testing.test_utils.patch_retry(testcase, module)[source]

A function to patch retry module to use mock clock and logger.

Clock and logger that defined in retry decorator will be replaced in test in order to skip sleep phase when retry happens.

  • testcase – An instance of unittest.TestCase that calls this function to patch retry module.
  • module – The module that uses retry and need to be replaced with mock clock and logger in test.

A function to clean up files or directories using FileSystems.

Glob is supported in file path and directories will be deleted recursively.

Parameters:file_paths – A list of strings contains file paths or directories.
apache_beam.testing.test_utils.cleanup_subscriptions(sub_client, subs)[source]

Cleanup PubSub subscriptions if exist.

apache_beam.testing.test_utils.cleanup_topics(pub_client, topics)[source]

Cleanup PubSub topics if exist.

class apache_beam.testing.test_utils.PullResponseMessage(data, attributes=None, publish_time_secs=None, publish_time_nanos=None, ack_id=None)[source]

Bases: future.types.newobject.newobject

Data representing a pull request response.

Utility class for create_pull_response.


Create an instance of google.cloud.pubsub.types.ReceivedMessage.

Used to simulate the response from pubsub.SubscriberClient().pull().

Parameters:responses – list of PullResponseMessage
Returns:An instance of google.cloud.pubsub.types.PullResponse populated with responses.