# Created by Leo from: C:\Development\Python22\Lib\site-packages\vb2py\vb2py.leo
from unittest import *
from testframework import *
import vb2py.utils
PATH = vb2py.utils.rootPath()
# << File tests >> (1 of 5)
# It is hard to test opening and closing files without reading so we do
# things all at once
# Open with Input
tests.append((r"""
Open "%s" For Input As #3
Input #3, a
Input #3, b
Input #3, c, d, e
Input #3, f, g
Close #3
""" % vb2py.utils.relativePath("test\\testread.txt"), {'a' : 'Can you hear me now?',
'b' : 'Can you still hear me now?',
'c' : 10, 'd' : 20, 'e' : 30,
'f' : 5, 'g' : "hello",
}))
# Open with Line Input
tests.append((r"""
Open "%s\\test\\testread.txt" For Input As #3
Line Input #3, a
Line Input #3, b
Line Input #3, c
Line Input #3, d
Close #3
""" % PATH, {'a' : 'Can you hear me now?',
'b' : 'Can you still hear me now?',
'c' : '10, 20, 30',
'd' : '5, "hello"',
}))
# Open and using Input() to get numbers of characters
tests.append((r"""
Open "%s\\test\\testread.txt" For Input As #3
a = Input(3, #3)
b = Input(1, #3)
c = Input(3, #3)
Close #3
""" % PATH, {'a' : 'Can',
'b' : ' ',
'c' : 'you',
}))
# << File tests >> (2 of 5)
# It is hard to test opening and closing files without reading so we do
# things all at once
# Open with print
tests.append((r"""
Open "%s/test/testwrite.txt" For Output As #3
Print #3, 10
Print #3, 20, 30
Print #3, 40, 50
Print #3, "hello"
Close #3
Open "%s/test/testwrite.txt" For Input As #3
Input #3, a, b, c, d, f
Line Input #3, e
""" % (PATH, PATH), {'a' : 10, 'b' : 20,
'c' : 30, 'd' : 40, 'e' : 'hello',
'f' : 50,
}))
# Open with print but no cr
tests.append((r"""
Open "%s/test/testwrite.txt" For Output As #3
Print #3, 10;
Print #3, 20, 30;
Print #3, 40, "hello", 50;
Close #3
Open "%s/test/testwrite.txt" For Input As #3
Line Input #3, a
""" % (PATH, PATH), {'a' : "1020\t3040\thello\t50"}
))
# << File tests >> (3 of 5)
# Open a couple of files and then use a bare close to close them and check we
# close ok
# Open with Input
tests.append((r"""
Open "%s" For Input As #3
Open "%s" For Output As #4
Close
Input #3, a
""" % (vb2py.utils.relativePath("test\\testread.txt"),
vb2py.utils.relativePath("test\\testwrite.txt")),
{'FAIL' : 'yes',
}))
# << File tests >> (4 of 5)
# Seek in a file
# Seek as a way of moving around in a file
tests.append((r"""
Open "%s" For Input As #3
Input #3, a
Seek #3, 1
Input #3, b
Seek #3, 5
Input #3, c
""" % vb2py.utils.relativePath("test\\testread.txt"),
{
'a' : 'Can you hear me now?',
'b' : 'Can you hear me now?',
'c' : 'you hear me now?',
}))
# Seek as a property of the file
tests.append((r"""
Open "%s" For Input As #3
a = Seek(3)
Input #3, _a
b = Seek(3)
Seek #3, 5
c = Seek(3)
""" % vb2py.utils.relativePath("test\\testread.txt"),
{
'a' : 1,
'b' : 23,
'c' : 5,
}))
# << File tests >> (5 of 5)
# Return the directory of file matches - this is a weird function
# Dir
tests.append((r"""
a = Dir("test\\test*.txt")
b = Dir()
c = Dir()
""",
{
'a' : 'testread.txt',
'b' : 'testwrite.txt',
'c' : '',
}))
# Dir$
tests.append((r"""
a = Dir$("test\\test*.txt")
b = Dir$()
c = Dir$()
""",
{
'a' : 'testread.txt',
'b' : 'testwrite.txt',
'c' : '',
}))
# Dir no parenthesis
tests.append((r"""
a = Dir("test\\test*.txt")
b = Dir
c = Dir
""",
{
'a' : 'testread.txt',
'b' : 'testwrite.txt',
'c' : '',
}))
# Dir$ no parenthesis
tests.append((r"""
a = Dir$("test\\test*.txt")
b = Dir$
c = Dir$
""",
{
'a' : 'testread.txt',
'b' : 'testwrite.txt',
'c' : '',
}))
# -- end -- << File tests >>
import vb2py.vbparser
vb2py.vbparser.log.setLevel(0) # Don't print all logging stuff
TestClass = addTestsTo(BasicTest, tests)
if __name__ == "__main__":
main()
|