From 2dd5cf430edaae01594d566c9f27d780c3ffb4ef Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 26 Apr 2015 21:43:42 -0300 Subject: Initial commit --- tests/read_diferentes_offsets.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/read_diferentes_offsets.py (limited to 'tests/read_diferentes_offsets.py') 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!" -- cgit v1.2.3-70-g09d2