blob: 412fe06c3028912a05d23dae9b0e2e1582d9b1a1 [file] [log] [blame]
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>apache_beam.testing.test_utils module &mdash; Apache Beam documentation</title>
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="apache_beam.testing.util module" href="apache_beam.testing.util.html" />
<link rel="prev" title="apache_beam.testing.test_stream_service module" href="apache_beam.testing.test_stream_service.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home"> Apache Beam
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="apache_beam.coders.html">apache_beam.coders package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.dataframe.html">apache_beam.dataframe package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.internal.html">apache_beam.internal package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.io.html">apache_beam.io package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.metrics.html">apache_beam.metrics package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.ml.html">apache_beam.ml package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.options.html">apache_beam.options package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.portability.html">apache_beam.portability package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.runners.html">apache_beam.runners package</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="apache_beam.testing.html">apache_beam.testing package</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="apache_beam.testing.html#subpackages">Subpackages</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="apache_beam.testing.html#submodules">Submodules</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="apache_beam.testing.datatype_inference.html">apache_beam.testing.datatype_inference module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.testing.extra_assertions.html">apache_beam.testing.extra_assertions module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.testing.metric_result_matchers.html">apache_beam.testing.metric_result_matchers module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.testing.pipeline_verifiers.html">apache_beam.testing.pipeline_verifiers module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.testing.synthetic_pipeline.html">apache_beam.testing.synthetic_pipeline module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.testing.test_pipeline.html">apache_beam.testing.test_pipeline module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.testing.test_stream.html">apache_beam.testing.test_stream module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.testing.test_stream_service.html">apache_beam.testing.test_stream_service module</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">apache_beam.testing.test_utils module</a></li>
<li class="toctree-l3"><a class="reference internal" href="apache_beam.testing.util.html">apache_beam.testing.util module</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.tools.html">apache_beam.tools package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.transforms.html">apache_beam.transforms package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.typehints.html">apache_beam.typehints package</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.utils.html">apache_beam.utils package</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.error.html">apache_beam.error module</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.pipeline.html">apache_beam.pipeline module</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.pvalue.html">apache_beam.pvalue module</a></li>
<li class="toctree-l1"><a class="reference internal" href="apache_beam.version.html">apache_beam.version module</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Apache Beam</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> &raquo;</li>
<li><a href="apache_beam.testing.html">apache_beam.testing package</a> &raquo;</li>
<li>apache_beam.testing.test_utils module</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/apache_beam.testing.test_utils.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="module-apache_beam.testing.test_utils">
<span id="apache-beam-testing-test-utils-module"></span><h1>apache_beam.testing.test_utils module<a class="headerlink" href="#module-apache_beam.testing.test_utils" title="Permalink to this headline"></a></h1>
<p>Utility methods for testing</p>
<p>For internal use only; no backwards-compatibility guarantees.</p>
<dl class="class">
<dt id="apache_beam.testing.test_utils.TempDir">
<em class="property">class </em><code class="descclassname">apache_beam.testing.test_utils.</code><code class="descname">TempDir</code><a class="reference internal" href="_modules/apache_beam/testing/test_utils.html#TempDir"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.testing.test_utils.TempDir" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>Context Manager to create and clean-up a temporary directory.</p>
<dl class="method">
<dt id="apache_beam.testing.test_utils.TempDir.get_path">
<code class="descname">get_path</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/testing/test_utils.html#TempDir.get_path"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.testing.test_utils.TempDir.get_path" title="Permalink to this definition"></a></dt>
<dd><p>Returns the path to the temporary directory.</p>
</dd></dl>
<dl class="method">
<dt id="apache_beam.testing.test_utils.TempDir.create_temp_file">
<code class="descname">create_temp_file</code><span class="sig-paren">(</span><em>suffix=''</em>, <em>lines=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/testing/test_utils.html#TempDir.create_temp_file"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.testing.test_utils.TempDir.create_temp_file" title="Permalink to this definition"></a></dt>
<dd><p>Creates a temporary file in the temporary directory.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>suffix</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.8)"><em>str</em></a>) – The filename suffix of the temporary file (e.g. ‘.txt’)</li>
<li><strong>lines</strong> (<em>List</em><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.8)"><em>str</em></a><em>]</em>) – A list of lines that will be written to the temporary
file.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The name of the temporary file created.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="function">
<dt id="apache_beam.testing.test_utils.compute_hash">
<code class="descclassname">apache_beam.testing.test_utils.</code><code class="descname">compute_hash</code><span class="sig-paren">(</span><em>content</em>, <em>hashing_alg='sha1'</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/testing/test_utils.html#compute_hash"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.testing.test_utils.compute_hash" title="Permalink to this definition"></a></dt>
<dd><p>Compute a hash value of a list of objects by hashing their string
representations.</p>
</dd></dl>
<dl class="function">
<dt id="apache_beam.testing.test_utils.patch_retry">
<code class="descclassname">apache_beam.testing.test_utils.</code><code class="descname">patch_retry</code><span class="sig-paren">(</span><em>testcase</em>, <em>module</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/testing/test_utils.html#patch_retry"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.testing.test_utils.patch_retry" title="Permalink to this definition"></a></dt>
<dd><p>A function to patch retry module to use mock clock and logger.</p>
<p>Clock and logger that defined in retry decorator will be replaced in test
in order to skip sleep phase when retry happens.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>testcase</strong> – An instance of unittest.TestCase that calls this function to
patch retry module.</li>
<li><strong>module</strong> – The module that uses retry and need to be replaced with mock
clock and logger in test.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="apache_beam.testing.test_utils.delete_files">
<code class="descclassname">apache_beam.testing.test_utils.</code><code class="descname">delete_files</code><span class="sig-paren">(</span><em>file_paths</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/testing/test_utils.html#delete_files"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.testing.test_utils.delete_files" title="Permalink to this definition"></a></dt>
<dd><p>A function to clean up files or directories using <code class="docutils literal notranslate"><span class="pre">FileSystems</span></code>.</p>
<p>Glob is supported in file path and directories will be deleted recursively.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>file_paths</strong> – A list of strings contains file paths or directories.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="apache_beam.testing.test_utils.cleanup_subscriptions">
<code class="descclassname">apache_beam.testing.test_utils.</code><code class="descname">cleanup_subscriptions</code><span class="sig-paren">(</span><em>sub_client</em>, <em>subs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/testing/test_utils.html#cleanup_subscriptions"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.testing.test_utils.cleanup_subscriptions" title="Permalink to this definition"></a></dt>
<dd><p>Cleanup PubSub subscriptions if exist.</p>
</dd></dl>
<dl class="function">
<dt id="apache_beam.testing.test_utils.cleanup_topics">
<code class="descclassname">apache_beam.testing.test_utils.</code><code class="descname">cleanup_topics</code><span class="sig-paren">(</span><em>pub_client</em>, <em>topics</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/testing/test_utils.html#cleanup_topics"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.testing.test_utils.cleanup_topics" title="Permalink to this definition"></a></dt>
<dd><p>Cleanup PubSub topics if exist.</p>
</dd></dl>
<dl class="class">
<dt id="apache_beam.testing.test_utils.PullResponseMessage">
<em class="property">class </em><code class="descclassname">apache_beam.testing.test_utils.</code><code class="descname">PullResponseMessage</code><span class="sig-paren">(</span><em>data</em>, <em>attributes=None</em>, <em>publish_time_secs=None</em>, <em>publish_time_nanos=None</em>, <em>ack_id=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/testing/test_utils.html#PullResponseMessage"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.testing.test_utils.PullResponseMessage" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>Data representing a pull request response.</p>
<p>Utility class for <code class="docutils literal notranslate"><span class="pre">create_pull_response</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="apache_beam.testing.test_utils.create_pull_response">
<code class="descclassname">apache_beam.testing.test_utils.</code><code class="descname">create_pull_response</code><span class="sig-paren">(</span><em>responses</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/apache_beam/testing/test_utils.html#create_pull_response"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#apache_beam.testing.test_utils.create_pull_response" title="Permalink to this definition"></a></dt>
<dd><p>Create an instance of <code class="docutils literal notranslate"><span class="pre">google.cloud.pubsub.types.ReceivedMessage</span></code>.</p>
<p>Used to simulate the response from pubsub.SubscriberClient().pull().</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>responses</strong> – list of <code class="docutils literal notranslate"><span class="pre">PullResponseMessage</span></code></td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">An instance of <code class="docutils literal notranslate"><span class="pre">google.cloud.pubsub.types.PullResponse</span></code> populated with
responses.</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="apache_beam.testing.util.html" class="btn btn-neutral float-right" title="apache_beam.testing.util module" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="apache_beam.testing.test_stream_service.html" class="btn btn-neutral float-left" title="apache_beam.testing.test_stream_service module" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>