|
9 | 9 | """Tests for the :class:`aiida.orm.nodes.data.data:Data` class.""" |
10 | 10 |
|
11 | 11 | import os |
| 12 | +import tempfile |
| 13 | +from contextlib import contextmanager |
12 | 14 |
|
13 | 15 | import numpy |
14 | 16 | import pytest |
@@ -176,19 +178,29 @@ def test_constructor(): |
176 | 178 | assert node.source == source |
177 | 179 |
|
178 | 180 |
|
179 | | -def test_data_exporters(data_plugin, generate_class_instance): |
180 | | - """Verify that the return value of the export methods of all `Data` sub classes have the correct type. |
| 181 | +@contextmanager |
| 182 | +def temporary_directory(): |
| 183 | + """Context manager that changes to a temporary directory.""" |
| 184 | + original_cwd = os.getcwd() |
| 185 | + with tempfile.TemporaryDirectory() as temp_dir: |
| 186 | + try: |
| 187 | + os.chdir(temp_dir) |
| 188 | + yield temp_dir |
| 189 | + finally: |
| 190 | + os.chdir(original_cwd) |
181 | 191 |
|
182 | | - It should be a tuple where the first should be a byte string and the second a dictionary. |
183 | | - """ |
| 192 | + |
| 193 | +def test_data_exporters(data_plugin, generate_class_instance): |
| 194 | + """Verify that the return value of the export methods of all `Data` sub classes have the correct type.""" |
184 | 195 | export_formats = data_plugin.get_export_formats() |
185 | 196 |
|
186 | 197 | if not export_formats: |
187 | 198 | return |
188 | 199 |
|
189 | 200 | instance = generate_class_instance(data_plugin) |
190 | 201 |
|
191 | | - for fileformat in export_formats: |
192 | | - content, dictionary = instance._exportcontent(fileformat) |
193 | | - assert isinstance(content, bytes) |
194 | | - assert isinstance(dictionary, dict) |
| 202 | + with temporary_directory(): |
| 203 | + for fileformat in export_formats: |
| 204 | + content, dictionary = instance._exportcontent(fileformat) |
| 205 | + assert isinstance(content, bytes) |
| 206 | + assert isinstance(dictionary, dict) |
0 commit comments