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.

get_path()[source]

Returns the path to the temporary directory.

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

Creates a temporary file in the temporary directory.

Parameters:
  • 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.
Returns:

The name of the temporary file created.

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

Compute a hash value from a list of string.

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.

Parameters:
  • 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.
apache_beam.testing.test_utils.wait_for_subscriptions_created(subs, timeout=60)[source]

Wait for all PubSub subscriptions are created.

apache_beam.testing.test_utils.wait_for_topics_created(topics, timeout=60)[source]

Wait for all PubSub topics are created.

apache_beam.testing.test_utils.cleanup_subscriptions(subs)[source]

Cleanup PubSub subscriptions if exist.

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

Cleanup PubSub topics if exist.