<commit_before>"""
For simplicity and to avoid requiring a paid-for account on some cloud
storage system testing is conducted against two local storage backends. Since
the QueuedStorage backend is truly agnostic about the local and remote
storage systems, this should work as transparently as using one (or even two!)
remote storage systems.
"""
import os
import shutil
import tempfile
from os import path
from datetime import datetime

from django.core.files.base import File
from django.core.files.storage import FileSystemStorage, Storage
from django.conf import settings as django_settings
from django.test import TestCase

from queued_storage.backends import QueuedStorage
from queued_storage.conf import settings

from . import models


class StorageTests(TestCase):

    def setUp(self):
        self.old_celery_always_eager = getattr(
            settings, 'CELERY_ALWAYS_EAGER', False)
        settings.CELERY_ALWAYS_EAGER = True
        tmp_dir = tempfile.mkdtemp()
        self.test_file_name = 'queued_storage.txt'
        self.test_file_path = path.join(tmp_dir, self.test_file_name)
        with open(self.test_file_path, 'a') as test_file:
            test_file.write('test')
        self.test_file = open(self.test_file_path, 'r')

        # Overriding MEDIA_ROOT for tests (probbaly undefined at that stage anyway)
        # Starting with Django>=1.10, Storages APIs don't allow to write outside MEDIA_ROOT
        django_settings.MEDIA_ROOT = tempfile.mkdtemp()
        self.local_dir = os.path.join(django_settings.MEDIA_ROOT, 'storage_tests_local')
        self.remote_dir = os.path.join(django_settings.MEDIA_ROOT, 'storage_tests_remote')

        self.addCleanup(shutil.rmtree, self.local_dir)
        self.addCleanup(shutil.rmtree, self.remote_dir)
        self.addCleanup(shutil.rmtree, tmp_dir)

    def tearDown(self):
        settings.CELERY_ALWAYS_EAGER = self.old_celery_always_eager

    def test_storage_init(self):
        """
        Make sure that creating a QueuedStorage object works<commit_msg>One needs to create dirs?<commit_after>"""
For simplicity and to avoid requiring a paid-for account on some cloud
storage system testing is conducted against two local storage backends. Since
the QueuedStorage backend is truly agnostic about the local and remote
storage systems, this should work as transparently as using one (or even two!)
remote storage systems.
"""
import os
import shutil
import tempfile
from os import path
from datetime import datetime

from django.core.files.base import File
from django.core.files.storage import FileSystemStorage, Storage
from django.conf import settings as django_settings
from django.test import TestCase

from queued_storage.backends import QueuedStorage
from queued_storage.conf import settings

from . import models


class StorageTests(TestCase):

    def setUp(self):
        self.old_celery_always_eager = getattr(
            settings, 'CELERY_ALWAYS_EAGER', False)
        settings.CELERY_ALWAYS_EAGER = True
        tmp_dir = tempfile.mkdtemp()
        self.test_file_name = 'queued_storage.txt'
        self.test_file_path = path.join(tmp_dir, self.test_file_name)
        with open(self.test_file_path, 'a') as test_file:
            test_file.write('test')
        self.test_file = open(self.test_file_path, 'r')

        # Overriding MEDIA_ROOT for tests (probbaly undefined at that stage anyway)
        # Starting with Django>=1.10, Storages APIs don't allow to write outside MEDIA_ROOT
        django_settings.MEDIA_ROOT = tempfile.mkdtemp()
        self.local_dir = os.path.join(django_settings.MEDIA_ROOT, 'storage_tests_local')
        self.remote_dir = os.path.join(django_settings.MEDIA_ROOT, 'storage_tests_remote')
        os.mkdir(self.local_dir)
        os.mkdir(self.remote_dir)

        self.addCleanup(shutil.rmtree, self.local_dir)
        self.addCleanup(shutil.rmtree, self.remote_dir)
        self.addCleanup(shutil.rmtree, tmp_dir)

    def tearDown(self):
        settings.CELERY_ALWAYS_EAGER = self.old_celery_always_eager

    def test_storage_init(self):
        """
        Make sure that creating a QueuedStorage object works
{'fraction_non_alphanumeric': 0.07123883120019318, 'fraction_numerical': 0.0014489253803429123, 'mean_word_length': 3.7554535017221586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5412191', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1220, 'n_words': 347}