diff --git a/tests/test_repypp_library.py b/tests/test_repypp_library.py new file mode 100644 index 0000000..aaa0ea9 --- /dev/null +++ b/tests/test_repypp_library.py @@ -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!" diff --git a/tests/ut_seattlelibv2_repypp_include_filecontent.py b/tests/ut_seattlelibv2_repypp_include_filecontent.py new file mode 100644 index 0000000..1c4f1a6 --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_include_filecontent.py @@ -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() diff --git a/tests/ut_seattlelibv2_repypp_include_multiplearguments.py b/tests/ut_seattlelibv2_repypp_include_multiplearguments.py new file mode 100644 index 0000000..8152a48 --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_include_multiplearguments.py @@ -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() diff --git a/tests/ut_seattlelibv2_repypp_include_noargument.py b/tests/ut_seattlelibv2_repypp_include_noargument.py new file mode 100644 index 0000000..1ad4e28 --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_include_noargument.py @@ -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() diff --git a/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py b/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py new file mode 100644 index 0000000..474e794 --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py @@ -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() diff --git a/tests/ut_seattlelibv2_repypp_include_specifiedfile.py b/tests/ut_seattlelibv2_repypp_include_specifiedfile.py new file mode 100644 index 0000000..b2c4a1e --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_include_specifiedfile.py @@ -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() diff --git a/tests/ut_seattlelibv2_repypp_multiplearguments.py b/tests/ut_seattlelibv2_repypp_multiplearguments.py new file mode 100644 index 0000000..a902c59 --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_multiplearguments.py @@ -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). + +""" + +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() diff --git a/tests/ut_seattlelibv2_repypp_noargument.py b/tests/ut_seattlelibv2_repypp_noargument.py new file mode 100644 index 0000000..67ed21c --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_noargument.py @@ -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() diff --git a/tests/ut_seattlelibv2_repypp_samearguments.py b/tests/ut_seattlelibv2_repypp_samearguments.py new file mode 100644 index 0000000..8a3f6a9 --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_samearguments.py @@ -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() diff --git a/tests/ut_seattlelibv2_repypp_specialcomments.py b/tests/ut_seattlelibv2_repypp_specialcomments.py new file mode 100644 index 0000000..e5c195e --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_specialcomments.py @@ -0,0 +1,45 @@ +""" +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 some comments(include some_lib.repy # Ensure that +comments are ignored, even if preceded by whitespace) are ignored. +""" + +import os +import test_repypp_library + +def main(): + filecontent1 = '''def foo(): + pass +''' + filecontent2 = '''include testfile_repypp_example1.repy # Ensure that comments are ignored, even if preceded by whitespace +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 # Ensure that comments are ignored, even if preceded by whitespace + #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() +