-
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
3c1cb13
6c4d9d3
786df6a
023e15a
5ae6d69
ea005d9
e5bf5da
d2c698a
44d7785
b31e10d
7c3da40
9a48ae8
d0ef53f
fd6fc2c
0872104
04c89e9
6fc3f2b
021deb7
e0b97ee
2f6b9b5
696edcb
8e26f8d
0321fc3
0851475
e0c7f5e
140e732
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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']) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential gotcha: The filenames in Repy are restricted to a subset of possible filenames on any OS. Check |
||
|
|
||
| subprocess.call(['python', 'repypp.py',temporary_file2.name, 'unittest.py']) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about naming the resulting file (Also, watch out for spaces after commas.)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the check sums up to calling Can we check that the file contents match what we expect? I know |
||
| os.remove('unittest.py') | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #pragma out Error opening source file 'nonexit.py' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small typo: We want to refer to a non-existing file rather than a non-exiting (note "s"). |
||
|
|
||
| """ | ||
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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'): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How could this file exist if |
||
| os.remove('unittest.py') | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docstring makes me think something else is tested here. We are actually testing supplying an unexpected number of arguments to |
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above, docstring and test case (here: calling |
||
|
|
||
| """ | ||
|
|
||
| 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() | ||
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.
That's a very terse description. We should mention the Repy preprocessor (as some other tests do), and what the expected correct outcome is.