From 3c1cb13f689e03b3c86dc02a8ab5baba62ceb109 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Mon, 9 Feb 2015 08:54:49 -0500 Subject: [PATCH 01/26] test correct #include statements for repypp.py --- tests/ut_seattlelibv2_repypp_include.py | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/ut_seattlelibv2_repypp_include.py diff --git a/tests/ut_seattlelibv2_repypp_include.py b/tests/ut_seattlelibv2_repypp_include.py new file mode 100644 index 0000000..50b1b18 --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_include.py @@ -0,0 +1,28 @@ +""" +ut_seattlelibv2_repypp_include.py -- -- This script tests correct #include statements + +""" + +import os +import tempfile +import subprocess + +def main(): + #create a temporary_file1 contains: + #def foo(): + # pass + temporary_file1 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) + temporary_file1.writelines(['def foo():\n',' pass']) + + #create a temporary_file2 contains: + #include temporary_file1.py + #def bar(): + # pass + temporary_file2 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) + temporary_file2.writelines(['include ' + temporary_file1.name + '\n','def bar():\n',' pass']) + + subprocess.call(['python', 'repypp.py',temporary_file2.name, 'unittest.py']) + os.remove('unittest.py') + +if __name__ == "__main__": + main() From 6c4d9d3079bb2c638c61e78c75a338b526fdda9d Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Mon, 9 Feb 2015 08:57:02 -0500 Subject: [PATCH 02/26] Test #include statements(have multiple arguments). This script tests if repypp.py check erroneous #include statements(have multiple arguments). --- ...t_seattlelibv2_repypp_multiplearguments.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/ut_seattlelibv2_repypp_multiplearguments.py diff --git a/tests/ut_seattlelibv2_repypp_multiplearguments.py b/tests/ut_seattlelibv2_repypp_multiplearguments.py new file mode 100644 index 0000000..7835bd1 --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_multiplearguments.py @@ -0,0 +1,38 @@ +#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. + +""" +ut_seattlelibv2_repypp_multiplearguments.py -- This script tests if repypp.py check erroneous +#include statements(have multiple arguments). + +""" + +import os +import sys +import tempfile +import subprocess + +def main(): + #create a temporary_file1 contains: + #def foo(): + # pass + temporary_file1 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) + temporary_file1.writelines(['def foo():\n',' pass']) + + #create a temporary_file2 contains: + #include temporary_file1.py + #def bar(): + # pass + temporary_file2 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) + temporary_file2.writelines(['include ' + temporary_file1.name + '\n','def bar():\n',' pass']) + + subprocess.call(['python', 'repypp.py', temporary_file2.name, 'unittest.py' , temporary_file1.name]) + + if os.path.isfile('unittest.py'): + os.remove('unittest.py') + +if __name__ == "__main__": + main() From 786df6a399358c9f94639319aff003836d772152 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Mon, 9 Feb 2015 08:58:38 -0500 Subject: [PATCH 03/26] Test #include statements(have no arguments). --- tests/ut_seattlelibv2_repypp_noargument.py | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/ut_seattlelibv2_repypp_noargument.py diff --git a/tests/ut_seattlelibv2_repypp_noargument.py b/tests/ut_seattlelibv2_repypp_noargument.py new file mode 100644 index 0000000..22c5cf0 --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_noargument.py @@ -0,0 +1,38 @@ +#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. + +""" +ut_seattlelibv2_repypp_noargument.py -- This script tests if repypp.py check erroneous +#include statements(have no arguments at all). + +""" + +import os +import sys +import tempfile +import subprocess + +def main(): + #create a temporary_file1 contains: + #def foo(): + # pass + temporary_file1 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) + temporary_file1.writelines(['def foo():\n',' pass']) + + #create a temporary_file2 contains: + #include temporary_file1.py + #def bar(): + # pass + temporary_file2 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) + temporary_file2.writelines(['include ' + temporary_file1.name + '\n','def bar():\n',' pass']) + + subprocess.call(['python', 'repypp.py']) + + if os.path.isfile('unittest.py'): + os.remove('unittest.py') + +if __name__ == "__main__": + main() From 023e15af54b1511f751d1b7fa238e15407455a85 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Mon, 9 Feb 2015 09:00:29 -0500 Subject: [PATCH 04/26] Test #include statements(non-existing files). This script tests if repypp.py check erroneous #include statements(include non-existing files --- ...elibv2_repypp_include_non-existingfiles.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/ut_seattlelibv2_repypp_include_non-existingfiles.py 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..fba5111 --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py @@ -0,0 +1,34 @@ +#pragma out Error opening source file 'nonexit.py' + +""" +ut_seattlelibv2_repypp_include_non-existingfiles.py -- This script tests if repypp.py check erroneous +#include statements(include non-existing files). + +""" + +import os +import sys +import tempfile +import subprocess + +def main(): + #create a temporary_file1 contains: + #def foo(): + # pass + temporary_file1 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) + temporary_file1.writelines(['def foo():\n',' pass']) + + #create a temporary_file2 contains: + #include nonexit.py + #def bar(): + # pass + temporary_file2 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) + temporary_file2.writelines(['include nonexit.py\n','def bar():\n',' pass']) + + subprocess.call(['python', 'repypp.py', temporary_file2.name, 'unittest.py']) + + if os.path.isfile('unittest.py'): + os.remove('unittest.py') + +if __name__ == "__main__": + main() From 5ae6d6954bb04e2562875e6f9a084b2c0cd7f023 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Sun, 15 Feb 2015 23:42:37 -0500 Subject: [PATCH 05/26] discard tempfile module and give more explanations Since the name using tempfile module which is not satisfied the requirement of Repy, so I discard it. And I give more explanations, modify file names. Also checking whether the file contents match what we expect. --- tests/ut_seattlelibv2_repypp_include.py | 37 +++++++++++++++++-------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/tests/ut_seattlelibv2_repypp_include.py b/tests/ut_seattlelibv2_repypp_include.py index 50b1b18..bd7384d 100644 --- a/tests/ut_seattlelibv2_repypp_include.py +++ b/tests/ut_seattlelibv2_repypp_include.py @@ -1,28 +1,43 @@ """ -ut_seattlelibv2_repypp_include.py -- -- This script tests correct #include statements +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 """ import os -import tempfile import subprocess def main(): #create a temporary_file1 contains: #def foo(): - # pass - temporary_file1 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) - temporary_file1.writelines(['def foo():\n',' pass']) + # pass + temporary_file1 = open('testfile_repypp_example1.repy', 'w') + temporary_file1.write('def foo():\n pass\n') + temporary_file1.close() #create a temporary_file2 contains: - #include temporary_file1.py + #include testfile_repypp_example1.repy #def bar(): - # pass - temporary_file2 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) - temporary_file2.writelines(['include ' + temporary_file1.name + '\n','def bar():\n',' pass']) + # pass + temporary_file2 = open('testfile_repypp_example2.repy', 'w') + temporary_file2.write('include testfile_repypp_example1.repy\ndef bar():\n pass\n') + temporary_file2.close() - subprocess.call(['python', 'repypp.py',temporary_file2.name, 'unittest.py']) - os.remove('unittest.py') + subprocess.call(['python', 'repypp.py', 'testfile_repypp_example2.repy', 'testfile_repypp_example2_preprocessed.repy',]) + + # check whether the file contents match what we expect. + correctresult1 = 'def foo():\n pass\n' + correctresult2 = 'def bar():\n pass\n' + + f = open('testfile_repypp_example2_preprocessed.repy','r') + + if not correctresult1 in f.read() and not correctresult2 in f.read(): + print "the result of repypp.py produces is not correct!" + + os.remove('testfile_repypp_example2_preprocessed.repy') + os.remove('testfile_repypp_example1.repy') + os.remove('testfile_repypp_example2.repy') if __name__ == "__main__": main() From ea005d986782fe3c941c29e6f1fa5bbb08b86e5e Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Sun, 15 Feb 2015 23:45:10 -0500 Subject: [PATCH 06/26] Discard tempfile module and give more explanations Since the name using tempfile module which is not satisfied with the requirement of Repy, so I discard it. And I give more explanations, modify file names. --- ...elibv2_repypp_include_non-existingfiles.py | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py b/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py index fba5111..86185a2 100644 --- a/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py +++ b/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py @@ -1,34 +1,31 @@ -#pragma out Error opening source file 'nonexit.py' +pragma out Error opening source file 'non_exist.repy' """ -ut_seattlelibv2_repypp_include_non-existingfiles.py -- This script tests if repypp.py check erroneous -#include statements(include non-existing 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 erroneous #include statements(include non-existing files). """ import os import sys -import tempfile import subprocess def main(): - #create a temporary_file1 contains: + #create a temporary_file contains: #def foo(): - # pass - temporary_file1 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) - temporary_file1.writelines(['def foo():\n',' pass']) + # pass + temporary_file = open('testfile_repypp_example.repy', 'w') + temporary_file.write('include non_exist.repy\ndef bar():\n pass') + temporary_file.close() - #create a temporary_file2 contains: - #include nonexit.py - #def bar(): - # pass - temporary_file2 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) - temporary_file2.writelines(['include nonexit.py\n','def bar():\n',' pass']) - - subprocess.call(['python', 'repypp.py', temporary_file2.name, 'unittest.py']) - - if os.path.isfile('unittest.py'): - os.remove('unittest.py') + subprocess.call(['python', 'repypp.py', 'testfile_repypp_example.repy', 'testfile_repypp_example_preprocessed.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() From e5bf5da7b2f33f19b25d5da5a4720fbeb3033af4 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Sun, 15 Feb 2015 23:46:35 -0500 Subject: [PATCH 07/26] Fixed comment error --- tests/ut_seattlelibv2_repypp_include_non-existingfiles.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py b/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py index 86185a2..6e50d95 100644 --- a/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py +++ b/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py @@ -13,7 +13,8 @@ def main(): #create a temporary_file contains: - #def foo(): + #include non_exist.repy + #def bar(): # pass temporary_file = open('testfile_repypp_example.repy', 'w') temporary_file.write('include non_exist.repy\ndef bar():\n pass') From d2c698a1e27bf29e268910405711b52356659c11 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Sun, 15 Feb 2015 23:49:28 -0500 Subject: [PATCH 08/26] Discard tempfile module and give more explanations Since the name using tempfile module which is not satisfied the requirement of Repy, so I discard it. And I give more explanations, modify file names. --- ...t_seattlelibv2_repypp_multiplearguments.py | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/tests/ut_seattlelibv2_repypp_multiplearguments.py b/tests/ut_seattlelibv2_repypp_multiplearguments.py index 7835bd1..e7328e3 100644 --- a/tests/ut_seattlelibv2_repypp_multiplearguments.py +++ b/tests/ut_seattlelibv2_repypp_multiplearguments.py @@ -5,8 +5,10 @@ #pragma out written to outfile. Outfile and infile must be distinct. """ -ut_seattlelibv2_repypp_multiplearguments.py -- This script tests if repypp.py check erroneous -#include statements(have multiple arguments). +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 arguments(have multiple arguments). """ @@ -18,21 +20,26 @@ def main(): #create a temporary_file1 contains: #def foo(): - # pass - temporary_file1 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) - temporary_file1.writelines(['def foo():\n',' pass']) + # pass + temporary_file1 = open('testfile_repypp_example1.repy', 'w') + temporary_file1.write('def foo():\n pass\n') + temporary_file1.close() #create a temporary_file2 contains: - #include temporary_file1.py + #include testfile_repypp_example1.repy #def bar(): - # pass - temporary_file2 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) - temporary_file2.writelines(['include ' + temporary_file1.name + '\n','def bar():\n',' pass']) + # pass + temporary_file2 = open('testfile_repypp_example2.repy', 'w') + temporary_file2.write('include testfile_repypp_example1.repy\ndef bar():\n pass\n') + temporary_file2.close() - subprocess.call(['python', 'repypp.py', temporary_file2.name, 'unittest.py' , temporary_file1.name]) + subprocess.call(['python', 'repypp.py', 'testfile_repypp_example2.repy', 'testfile_repypp_example2_preprocessed.repy' , 'testfile_repypp_example2.repy']) - if os.path.isfile('unittest.py'): - os.remove('unittest.py') + if os.path.isfile('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() From 44d7785258c1f6de65966b983b2a7cf0c5099775 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Sun, 15 Feb 2015 23:50:39 -0500 Subject: [PATCH 09/26] Update ut_seattlelibv2_repypp_noargument.py --- tests/ut_seattlelibv2_repypp_noargument.py | 23 ++++------------------ 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/tests/ut_seattlelibv2_repypp_noargument.py b/tests/ut_seattlelibv2_repypp_noargument.py index 22c5cf0..95b0b22 100644 --- a/tests/ut_seattlelibv2_repypp_noargument.py +++ b/tests/ut_seattlelibv2_repypp_noargument.py @@ -5,34 +5,19 @@ #pragma out written to outfile. Outfile and infile must be distinct. """ -ut_seattlelibv2_repypp_noargument.py -- This script tests if repypp.py check erroneous -#include statements(have no arguments at all). +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 arguments(have no arguments at all). """ -import os import sys -import tempfile import subprocess def main(): - #create a temporary_file1 contains: - #def foo(): - # pass - temporary_file1 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) - temporary_file1.writelines(['def foo():\n',' pass']) - - #create a temporary_file2 contains: - #include temporary_file1.py - #def bar(): - # pass - temporary_file2 = tempfile.NamedTemporaryFile(prefix='testfile_', suffix='.py', dir= os.path.dirname(os.path.realpath(__file__)), delete=True) - temporary_file2.writelines(['include ' + temporary_file1.name + '\n','def bar():\n',' pass']) - subprocess.call(['python', 'repypp.py']) - if os.path.isfile('unittest.py'): - os.remove('unittest.py') if __name__ == "__main__": main() From b31e10dbd25866a8b021ae898e342003a8f34369 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Sun, 15 Feb 2015 23:51:50 -0500 Subject: [PATCH 10/26] Added an unit test for repypp.py This script tests if repypp.py check erroneous #include statements(have multiple arguments). --- ...elibv2_repypp_include_multiplearguments.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/ut_seattlelibv2_repypp_include_multiplearguments.py diff --git a/tests/ut_seattlelibv2_repypp_include_multiplearguments.py b/tests/ut_seattlelibv2_repypp_include_multiplearguments.py new file mode 100644 index 0000000..405c10c --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_include_multiplearguments.py @@ -0,0 +1,46 @@ +#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 sys +import subprocess + +def main(): + #create a temporary_file1 contains: + #def foo1(): + # pass + temporary_file1 = open('testfile_repypp_example1.repy', 'w') + temporary_file1.write('def foo1():\n pass\n') + temporary_file1.close() + + #create a temporary_file2 contains: + #def foo2(): + # pass + temporary_file2 = open('testfile_repypp_example2.repy', 'w') + temporary_file2.write('def foo2():\n pass\n') + temporary_file2.close() + + #create a temporary_file2 contains: + #include testfile_repypp_example1.repy testfile_repypp_example2.repy + #def bar(): + # pass + temporary_file3 = open('testfile_repypp_example3.repy', 'w') + temporary_file3.write('include testfile_repypp_example1.repy testfile_repypp_example2.repy\ndef bar():\n pass\n') + temporary_file3.close() + + subprocess.call(['python', 'repypp.py', 'testfile_repypp_example3.repy', 'testfile_repypp_example3_preprocessed.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() From 7c3da4080034c408468f2a7614251c85e42e2c11 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Sun, 15 Feb 2015 23:52:58 -0500 Subject: [PATCH 11/26] Added an unit test for repypp.py This script tests if repypp.py check erroneous #include statements(have no arguments at all). --- ..._seattlelibv2_repypp_include_noargument.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/ut_seattlelibv2_repypp_include_noargument.py diff --git a/tests/ut_seattlelibv2_repypp_include_noargument.py b/tests/ut_seattlelibv2_repypp_include_noargument.py new file mode 100644 index 0000000..7600af0 --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_include_noargument.py @@ -0,0 +1,30 @@ +#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 sys +import subprocess + +def main(): + #create a temporary_file2 contains: + #include + #def bar(): + # pass + temporary_file = open('testfile_repypp_example.repy', 'w') + temporary_file.write('include \ndef bar():\n pass\n') + temporary_file.close() + + subprocess.call(['python', 'repypp.py', 'testfile_repypp_example.repy', 'testfile_repypp_example_preprocessed.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() From 9a48ae86ca0086c91c00093b1372496d76065fa3 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Sun, 15 Feb 2015 23:56:56 -0500 Subject: [PATCH 12/26] Update ut_seattlelibv2_repypp_include_non-existingfiles.py --- tests/ut_seattlelibv2_repypp_include_non-existingfiles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py b/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py index 6e50d95..7f49219 100644 --- a/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py +++ b/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py @@ -1,4 +1,4 @@ -pragma out Error opening source file 'non_exist.repy' +#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 From d0ef53fdafc8e138ae0c562bc7f15de3f639f133 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Mon, 16 Feb 2015 13:50:05 -0500 Subject: [PATCH 13/26] Added an unit test for repypp.py This script tests if some comments(include some_lib.repy # Ensure that comments are ignored, even if preceded by whitespace) are ignored. --- .../ut_seattlelibv2_repypp_specialcomments.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/ut_seattlelibv2_repypp_specialcomments.py diff --git a/tests/ut_seattlelibv2_repypp_specialcomments.py b/tests/ut_seattlelibv2_repypp_specialcomments.py new file mode 100644 index 0000000..4f1e466 --- /dev/null +++ b/tests/ut_seattlelibv2_repypp_specialcomments.py @@ -0,0 +1,44 @@ +""" +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 subprocess + +def main(): + #create a temporary_file1 contains: + #def foo(): + # pass + temporary_file1 = open('testfile_repypp_example1.repy', 'w') + temporary_file1.write('def foo():\n pass\n') + temporary_file1.close() + + #create a temporary_file2 contains: + #include testfile_repypp_example1.repy # Ensure that comments are ignored, even if preceded by whitespace + #def bar(): + # pass + temporary_file2 = open('testfile_repypp_example2.repy', 'w') + temporary_file2.write('include testfile_repypp_example1.repy # Ensure that comments are ignored, even if preceded by whitespace\ndef bar():\n pass\n') + temporary_file2.close() + + subprocess.call(['python', 'repypp.py', 'testfile_repypp_example2.repy', 'testfile_repypp_example2_preprocessed.repy',]) + + # check whether the file contents match what we expect. + correctresult1 = 'def foo():\n pass\n' + correctresult2 = 'def bar():\n pass\n' + + f = open('testfile_repypp_example2_preprocessed.repy','r') + + if not correctresult1 in f.read() and not correctresult2 in f.read(): + print "the result of repypp.py produces is not correct!" + + os.remove('testfile_repypp_example2_preprocessed.repy') + os.remove('testfile_repypp_example1.repy') + os.remove('testfile_repypp_example2.repy') + +if __name__ == "__main__": + main() From fd6fc2c09da2ca67961c5dd7af15e21e7c4528c2 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Mon, 16 Feb 2015 20:14:04 -0500 Subject: [PATCH 14/26] Added error message if repypp.py doesn't work. --- ...eattlelibv2_repypp_include_non-existingfiles.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py b/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py index 7f49219..7ec8b68 100644 --- a/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py +++ b/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py @@ -20,8 +20,18 @@ def main(): temporary_file.write('include non_exist.repy\ndef bar():\n pass') temporary_file.close() - subprocess.call(['python', 'repypp.py', 'testfile_repypp_example.repy', 'testfile_repypp_example_preprocessed.repy']) - + #subprocess.call(['python', 'repypp.py', 'testfile_repypp_example.repy', 'testfile_repypp_example_preprocessed.repy']) + + process = subprocess.Popen([sys.executable, 'repypp.py', 'testfile_repypp_example.repy', 'testfile_repypp_example_preprocessed.repy'], + stderr=subprocess.PIPE, + stdout=subprocess.PIPE) + + (out, err) = process.communicate() + if out != 'Error opening source file \'non_exist.repy\'': + print out + print "repypp.py can't check check erroneous #include statements(include non-existing files)." + + if os.path.isfile('testfile_repypp_example_preprocessed.repy'): os.remove('testfile_repypp_example_preprocessed.repy') From 087210407b56af56cb7674a1d6a58bb8bc4eddb3 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Thu, 19 Feb 2015 10:51:44 -0500 Subject: [PATCH 15/26] Added a library file for unit tests of repypp.py --- tests/test_repypp_library.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/test_repypp_library.py 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!" From 04c89e931f741d01b0deab615eadc44ea609c8d3 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Thu, 19 Feb 2015 11:08:51 -0500 Subject: [PATCH 16/26] added test_repypp_library --- ...elibv2_repypp_include_multiplearguments.py | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/tests/ut_seattlelibv2_repypp_include_multiplearguments.py b/tests/ut_seattlelibv2_repypp_include_multiplearguments.py index 405c10c..8152a48 100644 --- a/tests/ut_seattlelibv2_repypp_include_multiplearguments.py +++ b/tests/ut_seattlelibv2_repypp_include_multiplearguments.py @@ -1,40 +1,47 @@ #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 *". +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). +This script tests if repypp.py check erroneous include statements +(have multiple arguments). """ import os -import sys -import subprocess +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 - temporary_file1 = open('testfile_repypp_example1.repy', 'w') - temporary_file1.write('def foo1():\n pass\n') - temporary_file1.close() + test_repypp_library.createtempfile('testfile_repypp_example1.repy', filecontent1) #create a temporary_file2 contains: #def foo2(): # pass - temporary_file2 = open('testfile_repypp_example2.repy', 'w') - temporary_file2.write('def foo2():\n pass\n') - temporary_file2.close() + test_repypp_library.createtempfile('testfile_repypp_example2.repy', filecontent2) - #create a temporary_file2 contains: + #create a temporary_file3 contains: #include testfile_repypp_example1.repy testfile_repypp_example2.repy #def bar(): # pass - temporary_file3 = open('testfile_repypp_example3.repy', 'w') - temporary_file3.write('include testfile_repypp_example1.repy testfile_repypp_example2.repy\ndef bar():\n pass\n') - temporary_file3.close() + test_repypp_library.createtempfile('testfile_repypp_example3.repy', filecontent3) - subprocess.call(['python', 'repypp.py', 'testfile_repypp_example3.repy', 'testfile_repypp_example3_preprocessed.repy']) + test_repypp_library.preprocess('testfile_repypp_example3.repy') if os.path.isfile('testfile_repypp_example3_preprocessed.repy'): os.remove('testfile_repypp_example3_preprocessed.repy') From 6fc3f2b248559a1266caa22d57591f08a4ad788a Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Thu, 19 Feb 2015 11:11:05 -0500 Subject: [PATCH 17/26] added test_repypp_library --- ..._seattlelibv2_repypp_include_noargument.py | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/ut_seattlelibv2_repypp_include_noargument.py b/tests/ut_seattlelibv2_repypp_include_noargument.py index 7600af0..1ad4e28 100644 --- a/tests/ut_seattlelibv2_repypp_include_noargument.py +++ b/tests/ut_seattlelibv2_repypp_include_noargument.py @@ -1,25 +1,32 @@ #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 *". +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). +This script tests if repypp.py check erroneous include statements +(have no arguments at all). """ import os -import sys -import subprocess +import test_repypp_library def main(): - #create a temporary_file2 contains: + 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 - temporary_file = open('testfile_repypp_example.repy', 'w') - temporary_file.write('include \ndef bar():\n pass\n') - temporary_file.close() + test_repypp_library.createtempfile('testfile_repypp_example.repy', filecontent) - subprocess.call(['python', 'repypp.py', 'testfile_repypp_example.repy', 'testfile_repypp_example_preprocessed.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') From 021deb7b3004922b6f1578b97dd36d14b211aab2 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Thu, 19 Feb 2015 11:12:59 -0500 Subject: [PATCH 18/26] added test_repypp_library --- ...elibv2_repypp_include_non-existingfiles.py | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py b/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py index 7ec8b68..474e794 100644 --- a/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py +++ b/tests/ut_seattlelibv2_repypp_include_non-existingfiles.py @@ -1,36 +1,33 @@ #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 *". +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). +This script tests if repypp.py check erroneous include statements +(include non-existing files). """ import os -import sys -import subprocess +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 - temporary_file = open('testfile_repypp_example.repy', 'w') - temporary_file.write('include non_exist.repy\ndef bar():\n pass') - temporary_file.close() + test_repypp_library.createtempfile('testfile_repypp_example.repy', filecontent) - #subprocess.call(['python', 'repypp.py', 'testfile_repypp_example.repy', 'testfile_repypp_example_preprocessed.repy']) - - process = subprocess.Popen([sys.executable, 'repypp.py', 'testfile_repypp_example.repy', 'testfile_repypp_example_preprocessed.repy'], - stderr=subprocess.PIPE, - stdout=subprocess.PIPE) - - (out, err) = process.communicate() - if out != 'Error opening source file \'non_exist.repy\'': - print out - print "repypp.py can't check check erroneous #include statements(include non-existing files)." + 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') From e0b97ee2f072ccf4e5098c018c2bbec7125621dd Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Thu, 19 Feb 2015 11:15:01 -0500 Subject: [PATCH 19/26] added test_repypp_library --- ...t_seattlelibv2_repypp_multiplearguments.py | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/tests/ut_seattlelibv2_repypp_multiplearguments.py b/tests/ut_seattlelibv2_repypp_multiplearguments.py index e7328e3..7e168a6 100644 --- a/tests/ut_seattlelibv2_repypp_multiplearguments.py +++ b/tests/ut_seattlelibv2_repypp_multiplearguments.py @@ -5,36 +5,46 @@ #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 *". +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 arguments(have multiple arguments). +This script tests if repypp.py check command line erroneous arguments +(have multiple arguments). """ import os -import sys -import tempfile 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 - temporary_file1 = open('testfile_repypp_example1.repy', 'w') - temporary_file1.write('def foo():\n pass\n') - temporary_file1.close() + test_repypp_library.createtempfile('testfile_repypp_example1.repy', filecontent1) #create a temporary_file2 contains: #include testfile_repypp_example1.repy #def bar(): # pass - temporary_file2 = open('testfile_repypp_example2.repy', 'w') - temporary_file2.write('include testfile_repypp_example1.repy\ndef bar():\n pass\n') - temporary_file2.close() - - subprocess.call(['python', 'repypp.py', 'testfile_repypp_example2.repy', 'testfile_repypp_example2_preprocessed.repy' , 'testfile_repypp_example2.repy']) + test_repypp_library.createtempfile('testfile_repypp_example2.repy', filecontent2) + try: + subprocess.call([sys.executable, 'repypp.py', 'testfile_repypp_example2.repy', 'testfile_repypp_example2_preprocessed.repy' , 'testfile_repypp_example2.repy']) + except: + print 'Can not execute repypp.py' + if os.path.isfile('testfile_repypp_example2_preprocessed.repy'): os.remove('testfile_repypp_example2_preprocessed.repy') From 2f6b9b50a78e8d119d24e0dd5b365c8898c14a0b Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Thu, 19 Feb 2015 11:16:00 -0500 Subject: [PATCH 20/26] Update ut_seattlelibv2_repypp_multiplearguments.py --- tests/ut_seattlelibv2_repypp_multiplearguments.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ut_seattlelibv2_repypp_multiplearguments.py b/tests/ut_seattlelibv2_repypp_multiplearguments.py index 7e168a6..a902c59 100644 --- a/tests/ut_seattlelibv2_repypp_multiplearguments.py +++ b/tests/ut_seattlelibv2_repypp_multiplearguments.py @@ -41,12 +41,12 @@ def bar(): test_repypp_library.createtempfile('testfile_repypp_example2.repy', filecontent2) try: - subprocess.call([sys.executable, 'repypp.py', 'testfile_repypp_example2.repy', 'testfile_repypp_example2_preprocessed.repy' , 'testfile_repypp_example2.repy']) + 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_example2_preprocessed.repy'): - os.remove('testfile_repypp_example2_preprocessed.repy') + 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') From 696edcbfed1f50f11ccb36fea576f1199e9ecf58 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Thu, 19 Feb 2015 11:19:09 -0500 Subject: [PATCH 21/26] added try-except statement for execute repypp.py --- tests/ut_seattlelibv2_repypp_noargument.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/ut_seattlelibv2_repypp_noargument.py b/tests/ut_seattlelibv2_repypp_noargument.py index 95b0b22..67ed21c 100644 --- a/tests/ut_seattlelibv2_repypp_noargument.py +++ b/tests/ut_seattlelibv2_repypp_noargument.py @@ -5,19 +5,24 @@ #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 *". +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 arguments(have no arguments at all). +This script tests if repypp.py check command line erroneous arguments +(have no arguments at all). """ -import sys import subprocess +import sys def main(): - subprocess.call(['python', 'repypp.py']) - + try: + subprocess.call([sys.executable, 'repypp.py']) + except: + print 'Can not execute repypp.py' if __name__ == "__main__": main() From 8e26f8d4336e3e5c6c9b727c8381689a9debc4b6 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Thu, 19 Feb 2015 11:21:14 -0500 Subject: [PATCH 22/26] added test_repypp_library --- .../ut_seattlelibv2_repypp_specialcomments.py | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/tests/ut_seattlelibv2_repypp_specialcomments.py b/tests/ut_seattlelibv2_repypp_specialcomments.py index 4f1e466..e5c195e 100644 --- a/tests/ut_seattlelibv2_repypp_specialcomments.py +++ b/tests/ut_seattlelibv2_repypp_specialcomments.py @@ -1,40 +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 *". +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. +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 subprocess +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 - temporary_file1 = open('testfile_repypp_example1.repy', 'w') - temporary_file1.write('def foo():\n pass\n') - temporary_file1.close() + 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 - temporary_file2 = open('testfile_repypp_example2.repy', 'w') - temporary_file2.write('include testfile_repypp_example1.repy # Ensure that comments are ignored, even if preceded by whitespace\ndef bar():\n pass\n') - temporary_file2.close() + test_repypp_library.createtempfile('testfile_repypp_example2.repy', filecontent2) - subprocess.call(['python', 'repypp.py', 'testfile_repypp_example2.repy', 'testfile_repypp_example2_preprocessed.repy',]) + test_repypp_library.preprocess('testfile_repypp_example2.repy') # check whether the file contents match what we expect. - correctresult1 = 'def foo():\n pass\n' - correctresult2 = 'def bar():\n pass\n' - - f = open('testfile_repypp_example2_preprocessed.repy','r') - - if not correctresult1 in f.read() and not correctresult2 in f.read(): - print "the result of repypp.py produces is not correct!" + test_repypp_library.checkcontent('testfile_repypp_example2_preprocessed.repy') os.remove('testfile_repypp_example2_preprocessed.repy') os.remove('testfile_repypp_example1.repy') @@ -42,3 +42,4 @@ def main(): if __name__ == "__main__": main() + From 0321fc38e1d2d3fee85f9db184f0d2f6bc21221d Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Thu, 19 Feb 2015 11:22:26 -0500 Subject: [PATCH 23/26] Added an unit test for repypp.py --- tests/ut_seattlelibv2_repypp_samearguments.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/ut_seattlelibv2_repypp_samearguments.py 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() From 08514750cabd6279eac6a73efd95debd0b7c40b6 Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Thu, 19 Feb 2015 11:23:15 -0500 Subject: [PATCH 24/26] Split this unit test into two unit tests --- tests/ut_seattlelibv2_repypp_include.py | 43 ------------------------- 1 file changed, 43 deletions(-) delete mode 100644 tests/ut_seattlelibv2_repypp_include.py diff --git a/tests/ut_seattlelibv2_repypp_include.py b/tests/ut_seattlelibv2_repypp_include.py deleted file mode 100644 index bd7384d..0000000 --- a/tests/ut_seattlelibv2_repypp_include.py +++ /dev/null @@ -1,43 +0,0 @@ -""" -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 -""" - -import os -import subprocess - -def main(): - #create a temporary_file1 contains: - #def foo(): - # pass - temporary_file1 = open('testfile_repypp_example1.repy', 'w') - temporary_file1.write('def foo():\n pass\n') - temporary_file1.close() - - #create a temporary_file2 contains: - #include testfile_repypp_example1.repy - #def bar(): - # pass - temporary_file2 = open('testfile_repypp_example2.repy', 'w') - temporary_file2.write('include testfile_repypp_example1.repy\ndef bar():\n pass\n') - temporary_file2.close() - - subprocess.call(['python', 'repypp.py', 'testfile_repypp_example2.repy', 'testfile_repypp_example2_preprocessed.repy',]) - - # check whether the file contents match what we expect. - correctresult1 = 'def foo():\n pass\n' - correctresult2 = 'def bar():\n pass\n' - - f = open('testfile_repypp_example2_preprocessed.repy','r') - - if not correctresult1 in f.read() and not correctresult2 in f.read(): - print "the result of repypp.py produces is not correct!" - - os.remove('testfile_repypp_example2_preprocessed.repy') - os.remove('testfile_repypp_example1.repy') - os.remove('testfile_repypp_example2.repy') - -if __name__ == "__main__": - main() From e0c7f5eafa018f82d21cefb7dafe256fe0eb15da Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Thu, 19 Feb 2015 11:24:41 -0500 Subject: [PATCH 25/26] Added an unit test for repypp.py --- ...seattlelibv2_repypp_include_filecontent.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/ut_seattlelibv2_repypp_include_filecontent.py 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() From 140e732dd485474a3f7f968239b3ea2f4df7db4e Mon Sep 17 00:00:00 2001 From: Xuefeng Date: Thu, 19 Feb 2015 11:26:57 -0500 Subject: [PATCH 26/26] Added an unit test for repypp.py --- ...attlelibv2_repypp_include_specifiedfile.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/ut_seattlelibv2_repypp_include_specifiedfile.py 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()