new tests for the new pseudo-random content files

Signed-off-by: Alfredo Deza <alfredo@deza.pe>
This commit is contained in:
Alfredo Deza 2014-12-12 11:09:27 -05:00
parent fc92b4925d
commit 8ee55a32f5

View file

@ -1,4 +1,4 @@
import realistic from s3tests import realistic
import shutil import shutil
import tempfile import tempfile
@ -17,19 +17,20 @@ class TestFiles(object):
# the size and seed is what we can get when generating a bunch of files # the size and seed is what we can get when generating a bunch of files
# with pseudo random numbers based on sttdev, seed, and mean. # with pseudo random numbers based on sttdev, seed, and mean.
# this fails, demonstrating the problem # this fails, demonstrating the (current) problem
def test_random_file_invalid(self): #def test_random_file_invalid(self):
size = 2506764 # size = 2506764
seed = 3391518755 # seed = 3391518755
source = realistic.RandomContentFile(size=size, seed=seed) # source = realistic.RandomContentFile(size=size, seed=seed)
t = tempfile.SpooledTemporaryFile() # t = tempfile.SpooledTemporaryFile()
shutil.copyfileobj(source, t) # shutil.copyfileobj(source, t)
precomputed = realistic.PrecomputedContentFile(t) # precomputed = realistic.PrecomputedContentFile(t)
# assert precomputed.valid()
verifier = realistic.FileVerifier() # verifier = realistic.FileVerifier()
shutil.copyfileobj(precomputed, verifier) # shutil.copyfileobj(precomputed, verifier)
assert verifier.valid() # assert verifier.valid()
# this passes # this passes
def test_random_file_valid(self): def test_random_file_valid(self):
@ -39,9 +40,42 @@ class TestFiles(object):
t = tempfile.SpooledTemporaryFile() t = tempfile.SpooledTemporaryFile()
shutil.copyfileobj(source, t) shutil.copyfileobj(source, t)
precomputed = realistic.PrecomputedContentFile(t) precomputed = realistic.PrecomputedContentFile(t)
assert precomputed.valid()
verifier = realistic.FileVerifier() #verifier = realistic.FileVerifier()
shutil.copyfileobj(precomputed, verifier) #shutil.copyfileobj(precomputed, verifier)
assert verifier.valid() #assert verifier.valid()
#assert 0
# new implementation
class TestFileValidator(object):
def test_new_file_is_valid(self):
size = 2506001
contents = realistic.generate_file_contents(size)
t = tempfile.SpooledTemporaryFile()
t.write(contents)
t.seek(0)
fp = realistic.FileValidator(t)
assert fp.valid()
def test_new_file_is_valid_when_size_is_1(self):
size = 1
contents = realistic.generate_file_contents(size)
t = tempfile.SpooledTemporaryFile()
t.write(contents)
t.seek(0)
fp = realistic.FileValidator(t)
assert fp.valid()
def test_new_file_is_valid_on_several_calls(self):
size = 2506001
contents = realistic.generate_file_contents(size)
t = tempfile.SpooledTemporaryFile()
t.write(contents)
t.seek(0)
fp = realistic.FileValidator(t)
assert fp.valid()
assert fp.valid()