Skip to content

Commit

Permalink
add test scenarios for reading file as lines
Browse files Browse the repository at this point in the history
  • Loading branch information
rvelea committed Apr 22, 2014
1 parent 4a53111 commit 5c0ec09
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
58 changes: 58 additions & 0 deletions tests/io_tests/test_lines_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/python -OOBtt
"""This test reads the current file using "lines" function, and compares against standard API
If any errors occur the test displays a "FAILED" message"""
import sys

import pysec
import pysec.io
import pysec.io.fcheck
import pysec.io.fd
import pysec.io.fs
import pysec.io.temp

def standard_read_self():
test_data = []
fd = open(__file__, "r")
for line in fd:
test_data.append(line)
fd.close()
return test_data

def main():
sys.stdout.write("BASIC LINES TEST: ")
# saving whole file in memory for future comparison
test_data = standard_read_self()
# Read lines with EOL
with pysec.io.fd.File.open(__file__, pysec.io.fd.FO_READ) as ftest:
test_cnt = ftest.lines(keep_eol=True)
if ''.join(test_cnt) != ''.join(test_data):
sys.stdout.write("FAILED with KEEP_EOL=TRUE\n")
return
# Read lines without EOL
with pysec.io.fd.File.open(__file__, pysec.io.fd.FO_READ) as ftest:
test_cnt = ftest.lines(keep_eol=False)
if ''.join(test_cnt) != ''.join(test_data).replace('\n', ''):
sys.stdout.write("FAILED with KEEP_EOL=FALSE\n")
return
# Read lines using EOL=')'
with pysec.io.fd.File.open(__file__, pysec.io.fd.FO_READ) as ftest:
test_cnt = ftest.lines(eol=')', keep_eol=True)
if ''.join(test_cnt) != ''.join(test_data):
sys.stdout.write("FAILED with EOL=')' and KEEP_EOL=TRUE\n")
return
# Read lines using EOL=')' and KEEP_EOL=FALSE
with pysec.io.fd.File.open(__file__, pysec.io.fd.FO_READ) as ftest:
test_cnt = ftest.lines(eol=')', keep_eol=False)
if ''.join(test_cnt) != ''.join(test_data).replace(')', ''):
sys.stdout.write("FAILED with EOL=')' and KEEP_EOL=FALSE\n")
return
# Read first line starting at offset 32 and ending at 256
with pysec.io.fd.File.open(__file__, pysec.io.fd.FO_READ) as ftest:
test_cnt = ftest.lines(start=32, stop=256, eol='\n', keep_eol=True)
if ''.join(test_cnt) != ''.join(test_data)[32:256]:
sys.stdout.write("FAILED with different start and stop\n")
return
sys.stdout.write("PASSED\n")

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion tests/io_tests/test_write_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import pysec.io.temp

FILE_SIZE = 4096
FILE_NAME = '/tmp/pysec_write_test'
FILE_NAME = '/tmp/__pysec_write_test.tmp'


def main():
Expand Down

0 comments on commit 5c0ec09

Please sign in to comment.