diff options
| author | Claudiu Popa <pcmanticore@gmail.com> | 2016-02-13 15:01:03 +0000 |
|---|---|---|
| committer | Claudiu Popa <pcmanticore@gmail.com> | 2016-02-13 16:51:02 +0000 |
| commit | ffa1ba873ca879ae2d259903b8add63f6e6eb2ac (patch) | |
| tree | e9b81be8638ed01eae5f2e9ecff4327c406619bf /astroid/tests/resources.py | |
| parent | a4a12428946b533dfebd5ecc38bcbef39288b499 (diff) | |
| download | astroid-git-ffa1ba873ca879ae2d259903b8add63f6e6eb2ac.tar.gz | |
Move testdata back into tests.
Diffstat (limited to 'astroid/tests/resources.py')
| -rw-r--r-- | astroid/tests/resources.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/astroid/tests/resources.py b/astroid/tests/resources.py index 175b9d17..1390088c 100644 --- a/astroid/tests/resources.py +++ b/astroid/tests/resources.py @@ -15,8 +15,12 @@ # # You should have received a copy of the GNU Lesser General Public License along # with astroid. If not, see <http://www.gnu.org/licenses/>. +import binascii +import contextlib import os import sys +import shutil +import tempfile import pkg_resources import six @@ -25,12 +29,30 @@ from astroid import builder from astroid import MANAGER -DATA_DIR = 'testdata/python{}/'.format(sys.version_info[0]) +DATA_DIR = 'testdata' BUILTINS = six.moves.builtins.__name__ + +@contextlib.contextmanager +def _temporary_file(): + name = binascii.hexlify(os.urandom(5)).decode() + path = find(name) + try: + yield path + finally: + os.remove(path) + +@contextlib.contextmanager +def tempfile_with_content(content): + with _temporary_file() as tmp: + with open(tmp, 'wb') as stream: + stream.write(content) + yield tmp + + def find(name): return pkg_resources.resource_filename( - pkg_resources.Requirement.parse('astroid'), + 'astroid.tests', os.path.normpath(os.path.join(DATA_DIR, name))) |
