-
Notifications
You must be signed in to change notification settings - Fork 20
Add unit tests for repypp.py #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
XuefengHuang
wants to merge
26
commits into
SeattleTestbed:master
Choose a base branch
from
XuefengHuang:repypp.py-unittests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 6c4d9d3
Test #include statements(have multiple arguments).
XuefengHuang 786df6a
Test #include statements(have no arguments).
XuefengHuang 023e15a
Test #include statements(non-existing files).
XuefengHuang 5ae6d69
discard tempfile module and give more explanations
XuefengHuang ea005d9
Discard tempfile module and give more explanations
XuefengHuang e5bf5da
Fixed comment error
XuefengHuang d2c698a
Discard tempfile module and give more explanations
XuefengHuang 44d7785
Update ut_seattlelibv2_repypp_noargument.py
XuefengHuang b31e10d
Added an unit test for repypp.py
XuefengHuang 7c3da40
Added an unit test for repypp.py
XuefengHuang 9a48ae8
Update ut_seattlelibv2_repypp_include_non-existingfiles.py
XuefengHuang d0ef53f
Added an unit test for repypp.py
XuefengHuang fd6fc2c
Added error message if repypp.py doesn't work.
XuefengHuang 0872104
Added a library file for unit tests of repypp.py
XuefengHuang 04c89e9
added test_repypp_library
XuefengHuang 6fc3f2b
added test_repypp_library
XuefengHuang 021deb7
added test_repypp_library
XuefengHuang e0b97ee
added test_repypp_library
XuefengHuang 2f6b9b5
Update ut_seattlelibv2_repypp_multiplearguments.py
XuefengHuang 696edcb
added try-except statement for execute repypp.py
XuefengHuang 8e26f8d
added test_repypp_library
XuefengHuang 0321fc3
Added an unit test for repypp.py
XuefengHuang 0851475
Split this unit test into two unit tests
XuefengHuang e0c7f5e
Added an unit test for repypp.py
XuefengHuang 140e732
Added an unit test for repypp.py
XuefengHuang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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). | ||
|
|
||
| """ | ||
|
|
||
| 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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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"