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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/ut_seattlelibv2_repypp_include.py
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's a very terse description. We should mention the Repy preprocessor (as some other tests do), and what the expected correct outcome is.

"""

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'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Potential gotcha: The filenames in Repy are restricted to a subset of possible filenames on any OS. Check tempfile and RepyV1's emulfile.py to see if this could cause problems --- think whitespace, capitalization, etc.


subprocess.call(['python', 'repypp.py',temporary_file2.name, 'unittest.py'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about naming the resulting file temporary_file2.name + "_preprocessed.py"?

(Also, watch out for spaces after commas.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So the check sums up to calling repypp. If it raises no error, then you assume the test passed.

Can we check that the file contents match what we expect? I know repypp adds a few things as comments dynamically (file path IIRC), but we should have that the processed file contains everything from the included file, and everything from the including file except for the lines stating include ....

os.remove('unittest.py')

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

temporary_file1 isn't used in this test.

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'):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How could this file exist if repypp worked correctly? There should be an else clause printing an error message (if that is how repypp works).

os.remove('unittest.py')

if __name__ == "__main__":
main()
38 changes: 38 additions & 0 deletions tests/ut_seattlelibv2_repypp_multiplearguments.py
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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The docstring makes me think something else is tested here. We are actually testing supplying an unexpected number of arguments to repypp on the command line (not to the include statement). That's a valid test, but please change this docstring, and add the other test too.


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

"""

import os
import 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()
38 changes: 38 additions & 0 deletions tests/ut_seattlelibv2_repypp_noargument.py
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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See above, docstring and test case (here: calling repypp with no arguments) don't match. Please resolve similarly.


"""

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()