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:
object
Context Manager to create and clean-up a temporary directory.
- 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.
- 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.delete_files(file_paths)[source]
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:
object
Data representing a pull request response.
Utility class for
create_pull_response
.
- apache_beam.testing.test_utils.create_pull_response(responses)[source]
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.
- apache_beam.testing.test_utils.create_file(path, contents)[source]
Create a file to use as input to test pipelines
- apache_beam.testing.test_utils.read_files_from_pattern(file_pattern)[source]
Reads the files that match a pattern
- class apache_beam.testing.test_utils.LCGenerator(a=25214903917, c=11, bits=48)[source]
Bases:
object
A pure Python implementation of linear congruential generator.
- seed_jdk(seed)[source]
Set the seed in the way equivalent to java.util.Random.seed.
This method provide a JDK equivalent random generator. Note that the JDK implementation has a known issue that is close seed generating close first pseudo-random number.
- next_int()[source]
Get the next integer value in the range of np.int32 ([0, 2^31-1]).
Equivalent to java.util.Random.nextInt.
- next_uint()[source]
Get the next unsigned integer value in the range of np.uint32.
Equivalent to java.util.Random.next(32).