mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-05 08:27:22 +03:00
Moved temp_directory
to testing_utils
to allow reuse in other test files.
This commit is contained in:
parent
2be5945864
commit
e66bb00d08
@ -18,8 +18,6 @@ import sys
|
||||
import math
|
||||
import contextlib
|
||||
import threading
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
import lxml.html
|
||||
import lxml.etree
|
||||
@ -27,7 +25,7 @@ import cairocffi as cairo
|
||||
import pytest
|
||||
|
||||
from .testing_utils import (
|
||||
resource_filename, assert_no_logs, capture_logs, TestHTML)
|
||||
resource_filename, assert_no_logs, capture_logs, TestHTML, temp_directory)
|
||||
from .test_draw import image_to_pixels
|
||||
from ..compat import urljoin, urlencode, urlparse_uses_relative, iteritems
|
||||
from ..urls import path2url
|
||||
@ -52,20 +50,6 @@ def chdir(path):
|
||||
os.chdir(old_dir)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def temp_directory():
|
||||
"""Context manager that gives the path to a new temporary directory.
|
||||
|
||||
Remove everything on exiting the context.
|
||||
|
||||
"""
|
||||
directory = tempfile.mkdtemp()
|
||||
try:
|
||||
yield directory
|
||||
finally:
|
||||
shutil.rmtree(directory)
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
"""Shortcut for reading a file."""
|
||||
with open(filename, 'rb') as fd:
|
||||
|
@ -17,6 +17,8 @@ import os.path
|
||||
import logging
|
||||
import contextlib
|
||||
import functools
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from .. import HTML, CSS
|
||||
from ..logger import LOGGER
|
||||
@ -97,3 +99,17 @@ def almost_equal(a, b):
|
||||
if isinstance(a, float) or isinstance(b, float):
|
||||
return round(abs(a - b), 6) == 0
|
||||
return a == b
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def temp_directory():
|
||||
"""Context manager that gives the path to a new temporary directory.
|
||||
|
||||
Remove everything on exiting the context.
|
||||
|
||||
"""
|
||||
directory = tempfile.mkdtemp()
|
||||
try:
|
||||
yield directory
|
||||
finally:
|
||||
shutil.rmtree(directory)
|
||||
|
Loading…
Reference in New Issue
Block a user