diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/read_diferentes_offsets.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/read_diferentes_offsets.py b/tests/read_diferentes_offsets.py new file mode 100644 index 0000000..008ef05 --- /dev/null +++ b/tests/read_diferentes_offsets.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +import sys +import random +random.seed("Yeah babe") + +text = open(sys.argv[1]).read() + +fin = open(sys.argv[1]) +for _ in xrange(1000): + offset = random.randint(0, len(text)) + size = random.randint(0, min(len(text) - offset - 1, 10 * 1024)) + fin.seek(offset) + chunk = fin.read(size) + assert len(chunk) <= size + assert len(chunk) != 0 + if text[offset:offset + len(chunk)] != chunk: + s = "Read fails for file {} with offset {} and size {}" + raise IOError(s.format(sys.argv[1], offset, size)) +print "Success!" |