Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3c1cb13
test correct #include statements for repypp.py
XuefengHuang Feb 9, 2015
6c4d9d3
Test #include statements(have multiple arguments).
XuefengHuang Feb 9, 2015
786df6a
Test #include statements(have no arguments).
XuefengHuang Feb 9, 2015
023e15a
Test #include statements(non-existing files).
XuefengHuang Feb 9, 2015
5ae6d69
discard tempfile module and give more explanations
XuefengHuang Feb 16, 2015
ea005d9
Discard tempfile module and give more explanations
XuefengHuang Feb 16, 2015
e5bf5da
Fixed comment error
XuefengHuang Feb 16, 2015
d2c698a
Discard tempfile module and give more explanations
XuefengHuang Feb 16, 2015
44d7785
Update ut_seattlelibv2_repypp_noargument.py
XuefengHuang Feb 16, 2015
b31e10d
Added an unit test for repypp.py
XuefengHuang Feb 16, 2015
7c3da40
Added an unit test for repypp.py
XuefengHuang Feb 16, 2015
9a48ae8
Update ut_seattlelibv2_repypp_include_non-existingfiles.py
XuefengHuang Feb 16, 2015
d0ef53f
Added an unit test for repypp.py
XuefengHuang Feb 16, 2015
fd6fc2c
Added error message if repypp.py doesn't work.
XuefengHuang Feb 17, 2015
0872104
Added a library file for unit tests of repypp.py
XuefengHuang Feb 19, 2015
04c89e9
added test_repypp_library
XuefengHuang Feb 19, 2015
6fc3f2b
added test_repypp_library
XuefengHuang Feb 19, 2015
021deb7
added test_repypp_library
XuefengHuang Feb 19, 2015
e0b97ee
added test_repypp_library
XuefengHuang Feb 19, 2015
2f6b9b5
Update ut_seattlelibv2_repypp_multiplearguments.py
XuefengHuang Feb 19, 2015
696edcb
added try-except statement for execute repypp.py
XuefengHuang Feb 19, 2015
8e26f8d
added test_repypp_library
XuefengHuang Feb 19, 2015
0321fc3
Added an unit test for repypp.py
XuefengHuang Feb 19, 2015
0851475
Split this unit test into two unit tests
XuefengHuang Feb 19, 2015
e0c7f5e
Added an unit test for repypp.py
XuefengHuang Feb 19, 2015
140e732
Added an unit test for repypp.py
XuefengHuang Feb 19, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/test_repypp_library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'''
This script is a library for unit tests of repypp.py. It includes
three functions: create a temporary file, execute repypp.py and
check preprocessed file.
'''
import os
import sys
import subprocess

def createtempfile(filename, content):
if os.path.isfile(filename):
os.remove(filename)
temporary_file = open(filename, 'w')
temporary_file.write(content)
temporary_file.close()


def preprocess(filename):
try:
subprocess.call([sys.executable, 'repypp.py', filename, os.path.splitext(filename)[0] + '_preprocessed.repy'])
except:
print 'Can not execute repypp.py'

def checkcontent(filename):
correctresult1 ='''def foo():
pass
'''
correctresult2 ='''def bar():
pass
'''
f = open(filename,'r')

if not correctresult1 in f.read() and not correctresult2 in f.read():
print "the result of repypp.py produces is not correct!"
43 changes: 43 additions & 0 deletions tests/ut_seattlelibv2_repypp_include_filecontent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
repypp.py is a preprocessor for repy. It includes dependent files as
needed.This is used to help the programmer avoid the need to use
import. They can instead use "include X" which works somewhat like
"from X import *".

This script tests correct include statements(whether repypp.py
incorrectly touched file contents).
"""

import os
import test_repypp_library

def main():
filecontent1 = '''def foo():
pass
'''
filecontent2 = '''include testfile_repypp_example1.repy
def bar():
pass
'''
#create a temporary_file1 contains:
#def foo():
# pass
test_repypp_library.createtempfile('testfile_repypp_example1.repy', filecontent1)

#create a temporary_file2 contains:
#include testfile_repypp_example1.repy
#def bar():
# pass
test_repypp_library.createtempfile('testfile_repypp_example2.repy', filecontent2)

test_repypp_library.preprocess('testfile_repypp_example2.repy')

# check whether the file contents match what we expect.
test_repypp_library.checkcontent('testfile_repypp_example2_preprocessed.repy')

os.remove('testfile_repypp_example2_preprocessed.repy')
os.remove('testfile_repypp_example1.repy')
os.remove('testfile_repypp_example2.repy')

if __name__ == "__main__":
main()
53 changes: 53 additions & 0 deletions tests/ut_seattlelibv2_repypp_include_multiplearguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma out Error opening source file 'testfile_repypp_example1.repy testfile_repypp_example2.repy'

"""
repypp.py is a preprocessor for repy. It includes dependent files as
needed.This is used to help the programmer avoid the need to use
import. They can instead use "include X" which works somewhat like
"from X import *".

This script tests if repypp.py check erroneous include statements
(have multiple arguments).

"""

import os
import test_repypp_library

def main():
filecontent1 = '''def foo1():
pass
'''
filecontent2 = '''def foo2():
pass
'''
filecontent3 = '''include testfile_repypp_example1.repy testfile_repypp_example2.repy
def bar():
pass
'''
#create a temporary_file1 contains:
#def foo1():
# pass
test_repypp_library.createtempfile('testfile_repypp_example1.repy', filecontent1)

#create a temporary_file2 contains:
#def foo2():
# pass
test_repypp_library.createtempfile('testfile_repypp_example2.repy', filecontent2)

#create a temporary_file3 contains:
#include testfile_repypp_example1.repy testfile_repypp_example2.repy
#def bar():
# pass
test_repypp_library.createtempfile('testfile_repypp_example3.repy', filecontent3)

test_repypp_library.preprocess('testfile_repypp_example3.repy')

if os.path.isfile('testfile_repypp_example3_preprocessed.repy'):
os.remove('testfile_repypp_example3_preprocessed.repy')

os.remove('testfile_repypp_example1.repy')
os.remove('testfile_repypp_example2.repy')

if __name__ == "__main__":
main()
37 changes: 37 additions & 0 deletions tests/ut_seattlelibv2_repypp_include_noargument.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma out Error opening source file ''

"""
repypp.py is a preprocessor for repy. It includes dependent files as
needed.This is used to help the programmer avoid the need to use
import. They can instead use "include X" which works somewhat like
"from X import *".

This script tests if repypp.py check erroneous include statements
(have no arguments at all).
"""

import os
import test_repypp_library

def main():
filecontent = '''include
def bar():
pass
'''
if os.path.isfile('testfile_repypp_example.repy'):
os.remove('testfile_repypp_example.repy')
#create a temporary_file contains:
#include
#def bar():
# pass
test_repypp_library.createtempfile('testfile_repypp_example.repy', filecontent)

test_repypp_library.preprocess('testfile_repypp_example.repy')

if os.path.isfile('testfile_repypp_example_preprocessed.repy'):
os.remove('testfile_repypp_example_preprocessed.repy')

os.remove('testfile_repypp_example.repy')

if __name__ == "__main__":
main()
39 changes: 39 additions & 0 deletions tests/ut_seattlelibv2_repypp_include_non-existingfiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma out Error opening source file 'non_exist.repy'

"""
repypp.py is a preprocessor for repy. It includes dependent files as
needed.This is used to help the programmer avoid the need to use
import. They can instead use "include X" which works somewhat like
"from X import *".

This script tests if repypp.py check erroneous include statements
(include non-existing files).
"""

import os
import test_repypp_library

def main():
filecontent = '''include non_exist.repy
def bar():
pass
'''
#create a temporary_file contains:
#include non_exist.repy
#def bar():
# pass
test_repypp_library.createtempfile('testfile_repypp_example.repy', filecontent)

if os.path.isfile('non_exist.repy'):
os.remove('non_exist.repy')

test_repypp_library.preprocess('testfile_repypp_example.repy')

if os.path.isfile('testfile_repypp_example_preprocessed.repy'):
os.remove('testfile_repypp_example_preprocessed.repy')

if os.path.isfile('testfile_repypp_example.repy'):
os.remove('testfile_repypp_example.repy')

if __name__ == "__main__":
main()
40 changes: 40 additions & 0 deletions tests/ut_seattlelibv2_repypp_include_specifiedfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
repypp.py is a preprocessor for repy. It includes dependent files as
needed.This is used to help the programmer avoid the need to use
import. They can instead use "include X" which works somewhat like
"from X import *".

This script tests correct include statements(whether repypp.py failed
to include the specified file).
"""

import os
import test_repypp_library

def main():
filecontent1 = '''def foo():
pass
'''
filecontent2 = '''include testfile_repypp_example1.repy
def bar():
pass
'''
#create a temporary_file1 contains:
#def foo():
# pass
test_repypp_library.createtempfile('testfile_repypp_example1.repy', filecontent1)

#create a temporary_file2 contains:
#include testfile_repypp_example1.repy
#def bar():
# pass
test_repypp_library.createtempfile('testfile_repypp_example2.repy', filecontent2)

test_repypp_library.preprocess('testfile_repypp_example2.repy')

os.remove('testfile_repypp_example2_preprocessed.repy')
os.remove('testfile_repypp_example1.repy')
os.remove('testfile_repypp_example2.repy')

if __name__ == "__main__":
main()
55 changes: 55 additions & 0 deletions tests/ut_seattlelibv2_repypp_multiplearguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#pragma out Invalid number of arguments
#pragma out repypp.py infile outfile

#pragma out preprocesses infile and includes content from the current directory. Output is
#pragma out written to outfile. Outfile and infile must be distinct.

"""
repypp.py is a preprocessor for repy. It includes dependent files as
needed.This is used to help the programmer avoid the need to use
import. They can instead use "include X" which works somewhat like
"from X import *".

This script tests if repypp.py check command line erroneous arguments
(have multiple arguments).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"If repypp works correctly, it will not accept any number of command-line arguments other than two, and will print an error message and usage string, see https://github.com/SeattleTestbed/seattlelib_v2/blob/master/repypp.py#L197-L200and https://github.com/SeattleTestbed/seattlelib_v2/blob/master/repypp.py#L41-L45"

"""

import os
import subprocess
import sys
import test_repypp_library


def main():
filecontent1 = '''def foo():
pass
'''
filecontent2 = '''include testfile_repypp_example1.repy
def bar():
pass
'''
#create a temporary_file1 contains:
#def foo():
# pass
test_repypp_library.createtempfile('testfile_repypp_example1.repy', filecontent1)

#create a temporary_file2 contains:
#include testfile_repypp_example1.repy
#def bar():
# pass
test_repypp_library.createtempfile('testfile_repypp_example2.repy', filecontent2)

try:
subprocess.call([sys.executable, 'repypp.py', 'testfile_repypp_example1.repy', 'testfile_repypp_example1_preprocessed.repy' , 'testfile_repypp_example2.repy'])
except:
print 'Can not execute repypp.py'

if os.path.isfile('testfile_repypp_example1_preprocessed.repy'):
os.remove('testfile_repypp_example1_preprocessed.repy')

os.remove('testfile_repypp_example1.repy')
os.remove('testfile_repypp_example2.repy')

if __name__ == "__main__":
main()
28 changes: 28 additions & 0 deletions tests/ut_seattlelibv2_repypp_noargument.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma out Invalid number of arguments
#pragma out repypp.py infile outfile

#pragma out preprocesses infile and includes content from the current directory. Output is
#pragma out written to outfile. Outfile and infile must be distinct.

"""
repypp.py is a preprocessor for repy. It includes dependent files as
needed.This is used to help the programmer avoid the need to use
import. They can instead use "include X" which works somewhat like
"from X import *".

This script tests if repypp.py check command line erroneous arguments
(have no arguments at all).

"""

import subprocess
import sys

def main():
try:
subprocess.call([sys.executable, 'repypp.py'])
except:
print 'Can not execute repypp.py'

if __name__ == "__main__":
main()
33 changes: 33 additions & 0 deletions tests/ut_seattlelibv2_repypp_samearguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma out The infile and outfile must be different files

"""
repypp.py is a preprocessor for repy. It includes dependent files as
needed.This is used to help the programmer avoid the need to use
import. They can instead use "include X" which works somewhat like
"from X import *".

This script tests if repypp.py check command line erroneous arguments
(have same arguments).

"""

import os
import subprocess
import sys
import test_repypp_library

def main():
filecontent = '''def foo():
pass
'''
#create a temporary_file contains:
#def foo():
# pass
test_repypp_library.createtempfile('testfile_repypp_example.repy', filecontent)

subprocess.call([sys.executable, 'repypp.py', 'testfile_repypp_example.repy', 'testfile_repypp_example.repy'])

os.remove('testfile_repypp_example.repy')

if __name__ == "__main__":
main()
Loading