<commit_before># coding=utf-8
from __future__ import unicode_literals

import posixpath
import time
from contextlib import contextmanager
from datetime import timedelta
from io import StringIO
from urllib.parse import urlsplit, urlunsplit

import requests
from django.contrib.staticfiles.storage import staticfiles_storage
from django.core.exceptions import ImproperlyConfigured
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
from django.core.management import CommandError, call_command
from django.test import SimpleTestCase
from django.utils import timezone
from django.utils.timezone import is_naive, make_naive, utc

from django_s3_storage.storage import S3Storage, StaticS3Storage


class TestS3Storage(SimpleTestCase):

    # Helpers.

    @contextmanager
    def save_file(self, name="foo.txt", content=b"foo", storage=default_storage):
        name = storage.save(name, ContentFile(content, name))
        try:
            time.sleep(1)  # Let S3 process the save.
            yield name
        finally:
            storage.delete(name)

    # Configuration tets.

    def testSettingsImported(self):
        self.assertEqual(S3Storage().settings.AWS_S3_CONTENT_LANGUAGE, "")
        with self.settings(AWS_S3_CONTENT_LANGUAGE="foo"):
            self.assertEqual(S3Storage().settings.AWS_S3_CONTENT_LANGUAGE, "foo")

    def testSettingsOverwritenBySuffixedSettings(self):
        self.assertEqual(StaticS3Storage().settings.AWS_S3_CONTENT_LANGUAGE, "")
        with self.settings(AWS_S3_CONTENT_LANGUAGE="foo", AWS_S3_CONTENT_LANGUAGE_STATIC="bar"):
            self.assertEqual(StaticS3Storage().settings.AWS_S3_CONTENT_LANGUAGE, "bar")

    def testSettingsOverwrittenByKwargs(self):
        self.assertEqual(S3Storage().settings.AWS_S3_CONTENT_LANGUAGE, "")
        self.assertEqual(S3Storage(aws_s3_content_language="foo").settings.AWS_S3_CONTENT_LANGUAGE, "foo")

    def testSettingsCannotUsePublicUrlAndBucketAuth(self):
        self.assertRaises(ImproperlyConfigured, lambda: S3Storage(
            aws_s3_bucket_auth=True,
            aws_s3_public_url="/foo/",
        ))

    def testSettingsUnknown(self):
        self.assertRaises(ImproperlyConfigured, lambda: S3Storage(
            foo=True,
        ))

    # Storage tests.

    def testOpenMissing(self):<commit_msg>Fixing tests<commit_after># coding=utf-8
from __future__ import unicode_literals

import posixpath
import time
from contextlib import contextmanager
from datetime import timedelta
from io import StringIO
from urllib.parse import urlsplit, urlunsplit

import requests
from django.contrib.staticfiles.storage import staticfiles_storage
from django.core.exceptions import ImproperlyConfigured
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
from django.core.management import CommandError, call_command
from django.test import SimpleTestCase
from django.utils import timezone
from django.utils.timezone import is_naive, make_naive, utc

from django_s3_storage.storage import S3Storage, StaticS3Storage


class TestS3Storage(SimpleTestCase):

    # Helpers.

    @contextmanager
    def save_file(self, name="foo.txt", content=b"foo", storage=default_storage):
        name = storage.save(name, ContentFile(content, name))
        try:
            time.sleep(1)  # Let S3 process the save.
            yield name
        finally:
            storage.delete(name)

    # Configuration tets.

    def testSettingsImported(self):
        self.assertEqual(S3Storage().settings.AWS_S3_CONTENT_LANGUAGE, "")
        with self.settings(AWS_S3_CONTENT_LANGUAGE="foo"):
            self.assertEqual(S3Storage().settings.AWS_S3_CONTENT_LANGUAGE, "foo")

    def testSettingsOverwritenBySuffixedSettings(self):
        self.assertEqual(StaticS3Storage().settings.AWS_S3_CONTENT_LANGUAGE, "")
        with self.settings(AWS_S3_CONTENT_LANGUAGE="foo", AWS_S3_CONTENT_LANGUAGE_STATIC="bar"):
            self.assertEqual(StaticS3Storage().settings.AWS_S3_CONTENT_LANGUAGE, "bar")

    def testSettingsOverwrittenByKwargs(self):
        self.assertEqual(S3Storage().settings.AWS_S3_CONTENT_LANGUAGE, "")
        self.assertEqual(S3Storage(aws_s3_content_language="foo").settings.AWS_S3_CONTENT_LANGUAGE, "foo")

    def testSettingsUnknown(self):
        self.assertRaises(ImproperlyConfigured, lambda: S3Storage(
            foo=True,
        ))

    # Storage tests.

    def testOpenMissing(self):
{'fraction_non_alphanumeric': 0.08298014722284185, 'fraction_numerical': 0.01137631050635735, 'mean_word_length': 4.262910798122066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5201110', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1341, 'n_words': 257}