Skip to content

Commit fe98dae

Browse files
committed
Hack: Run test_data_exporters in tmp_dir
Fixing it properly, e.g., by adding a `target_dir` parameter, would require adding it throughout the call stack (`_export_yaml`, `Data.export`, `Data._exportcontent`, `data_export`). Maybe do later on.
1 parent 9082020 commit fe98dae

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

tests/orm/nodes/data/test_data.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"""Tests for the :class:`aiida.orm.nodes.data.data:Data` class."""
1010

1111
import os
12+
import tempfile
13+
from contextlib import contextmanager
1214

1315
import numpy
1416
import pytest
@@ -176,19 +178,29 @@ def test_constructor():
176178
assert node.source == source
177179

178180

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)
181191

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."""
184195
export_formats = data_plugin.get_export_formats()
185196

186197
if not export_formats:
187198
return
188199

189200
instance = generate_class_instance(data_plugin)
190201

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

Comments
 (0)