File: remote_data_manager.rst

package info (click to toggle)
sunpy 7.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,592 kB
  • sloc: python: 41,765; ansic: 1,710; makefile: 39
file content (33 lines) | stat: -rw-r--r-- 1,183 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
.. _dev_guide_remote_data_manager_tests:

Tests using the Remote Data Manager
===================================

A pytest fixture (``sunpy_cache``) is provided for ease of mocking network requests when using cache.
The following example demonstrates the usage of the fixture:

.. code-block:: python

    @manager.require('test_file',
                     ['http://data.sunpy.org/sample-data/predicted-sunspot-radio-flux.txt'],
                     '4c85b04a5528aa97eb84a087450eda0421c71833820576330bba148564089b11')
    def test_function():
        return manager.get('test_file')

    @pytest.fixture()
    def local_cache(sunpy_cache):
        sunpy_cache = sunpy_cache('sunpy.test_module.cache')
        sunpy_cache.add('http://example.com/test_file',
                        'test_data_path')

The above snippet creates a pytest fixture called ``local_cache``.
This fixture can be used in wherever the files have to be mocked.
An example is given below:

.. code-block:: python

    def test_test_function(local_cache):
        # inside this function the mocked cache is used

        # test_function uses 'http://example.com/test_file'
        assert test_function() == True