Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
create unique files and clean the static directory since tests run in…
Browse files Browse the repository at this point in the history
… parallell
  • Loading branch information
antonagestam committed Jan 4, 2017
1 parent dff07b6 commit a81db11
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
11 changes: 7 additions & 4 deletions collectfast/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils.six import StringIO

from collectfast import settings
from .utils import test, create_static_file
from .utils import test, create_static_file, clean_static_dir


def override_setting(name, value):
Expand All @@ -30,7 +30,8 @@ def call_collectstatic(*args, **kwargs):

@test
def test_basics(case):
create_static_file('static/testfile.txt')
clean_static_dir()
create_static_file()
result = call_collectstatic()
case.assertIn("1 static file copied.", result)
# file state should now be cached
Expand All @@ -41,7 +42,8 @@ def test_basics(case):
@test
@override_setting("threads", 5)
def test_threads(case):
create_static_file('static/testfile.txt')
clean_static_dir()
create_static_file()
result = call_collectstatic()
case.assertIn("1 static file copied.", result)
# file state should now be cached
Expand All @@ -66,7 +68,8 @@ def test_collectfast_disabled(case):

@test
def test_disable_collectfast(case):
create_static_file('static/testfile.txt')
clean_static_dir()
create_static_file()
result = call_collectstatic(disable_collectfast=True)
case.assertIn("1 static file copied.", result)

Expand Down
13 changes: 12 additions & 1 deletion collectfast/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import random
import unittest
import uuid
import os


def test(func):
Expand All @@ -15,9 +17,18 @@ def test(func):
return type(func.__name__, (unittest.TestCase, ), {func.__name__: func})


def create_static_file(filename):
def create_static_file():
filename = 'static/%s.txt' % uuid.uuid4()
for i in range(3):
with open(filename, 'w+') as f:
for i in range(500):
f.write(chr(int(random.random() * 64)))
f.close()


def clean_static_dir():
d = 'static/'
for f in os.listdir(d):
path = os.path.join(d, f)
if os.path.isfile(path):
os.unlink(path)

0 comments on commit a81db11

Please sign in to comment.