<commit_before>from django.test import TestCase
from django.core.files.base import ContentFile
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from uuid import uuid4
import os
from storages.backends.s3boto import S3BotoStorage


class S3BotoStorageTests(TestCase):
    def setUp(self):
        self.storage = S3BotoStorage()
        
        # use a unique folder namespace for tests
        path_prefix = "test-subfolder/"
        dirs, files = self.storage.listdir(path_prefix)
        while dirs or files:
            path_prefix = "test-subfolder-%s/" % uuid4()
            dirs, files = self.storage.listdir(path_prefix)
        self.path_prefix = path_prefix
        
    def prefix_path(self, path):
        return "%s%s" % (self.path_prefix, path)
    
    def test_storage_save(self):
        name = self.prefix_path('test_storage_save.txt')
        content = 'new content'
        self.storage.save(name, ContentFile(content))
        self.assertEqual(self.storage.open(name).read(), content)
    
    def test_storage_open_for_writing(self):
        name = self.prefix_path('test_open_for_writing.txt')
        content = 'new content'
        file = self.storage.open(name, 'w')
        file.write(content)
        file.close()
        self.assertEqual(self.storage.open(name).read(), content)
        <commit_msg>delete all files created during each test<commit_after>from django.test import TestCase
from django.core.files.base import ContentFile
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from uuid import uuid4
import os
from storages.backends.s3boto import S3BotoStorage

class S3BotoStorageTests(TestCase):
    def setUp(self):
        self.storage = S3BotoStorage()
        
        # use a unique folder namespace for tests
        path_prefix = "test-subfolder/"
        dirs, files = self.storage.listdir(path_prefix)
        while dirs or files:
            path_prefix = "test-subfolder-%s/" % uuid4()
            dirs, files = self.storage.listdir(path_prefix)
        self.path_prefix = path_prefix
    
    def tearDown(self):
        # delete all files created during each test
        name = self.storage._normalize_name(self.storage._clean_name(self.path_prefix))
        dirlist = self.storage.bucket.list(self.storage._encode_name(name))
        names = [x.name for x in dirlist]
        for name in names:
            self.storage.delete(name)
        
    def prefix_path(self, path):
        return "%s%s" % (self.path_prefix, path)
    
    def test_storage_save(self):
        name = self.prefix_path('test_storage_save.txt')
        content = 'new content'
        self.storage.save(name, ContentFile(content))
        self.assertEqual(self.storage.open(name).read(), content)
    
    def test_storage_open_for_writing(self):
        name = self.prefix_path('test_open_for_writing.txt')
        content = 'new content'
        file = self.storage.open(name, 'w')
        file.write(content)
        file.close()
        self.assertEqual(self.storage.open(name).read(), content)
        
{'fraction_non_alphanumeric': 0.09803921568627451, 'fraction_numerical': 0.003857280617164899, 'mean_word_length': 2.795121951219512, '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': '206336', 'n_tokens_mistral': 909, 'n_tokens_neox': 915, 'n_words': 206}