Skip to content
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

Rework e2e tests to be included in coverage #73

Merged
merged 1 commit into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ environment:
install:
- SET PATH=%PYTHON%;%PYTHON%\\Scripts;%JAVA_HOME%\bin;%PATH%
- pip install --upgrade setuptools
- pip install http://sourceforge.net/projects/py2exe/files/latest/download?source=files
- pip install py2exe_py2
- pip install . pytest flake8
- choco install gradle

Expand Down
7 changes: 3 additions & 4 deletions src/sysl/core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def cmd(args):
add_modules_option(argp)


def main():
def main(input_args=sys.argv[1:]):
"""Main function."""
argp = argparse.ArgumentParser(
description='System Modelling Language Toolkit',
Expand All @@ -115,7 +115,7 @@ def main():
syslints.add_subparser(subparser)
syslseqs.add_subparser(subparser)

args = argp.parse_args()
args = argp.parse_args(input_args)

# Ensure the output directory exists.
if 'output' in args and os.path.dirname(args.output):
Expand All @@ -126,7 +126,6 @@ def main():
raise
try:
args.func(args)
sys.exit(0)
except Exception as e:
if args.trace:
raise
Expand All @@ -136,5 +135,5 @@ def main():


if __name__ == '__main__':
# debug.init()
main()
sys.exit(0)
33 changes: 22 additions & 11 deletions test/e2e/test_e2e.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sysl.core import syslloader
from sysl.core.__main__ import main
from sysl.util.file import filesAreIdentical

import pytest
Expand All @@ -16,14 +16,19 @@ def remove_file(fname):
pass


@pytest.mark.parametrize("fname", [
'001_annotations',
'002_annotations',
'003_annotations',
'004_annotations',
'005_annotations',
@pytest.mark.parametrize("fname, subprocess", [
('001_annotations', True),
('002_annotations', True),
('003_annotations', True),
('004_annotations', True),
('005_annotations', True),
('001_annotations', False),
('002_annotations', False),
('003_annotations', False),
('004_annotations', False),
('005_annotations', False)
])
def test_e2e(fname):
def test_e2e(fname, subprocess):
Copy link
Member

@sahejsingh sahejsingh Feb 14, 2018

Choose a reason for hiding this comment

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

why do you need subprocess=True calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose I want true "end-to-end" tests from an enduser perspective, who doesn't care wether the program was written in Python or anything else.
Eventually we might swap out the executables underneath but the tests should remain the same (at least the subprocess=True ones).
It also covers cases where the command line operates unexpectedly different from calling main directly.
Does any of this convince you?

Copy link
Member

Choose a reason for hiding this comment

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

Yup. thanks!

e2e_dir = path.normpath(path.dirname(__file__))
e2e_rel_dir = path.relpath(e2e_dir, start=REPO_ROOT)

Expand All @@ -33,9 +38,15 @@ def test_e2e(fname):
out_fname = path.join(out_dir, 'actual_output', fname + '.txt')
remove_file(out_fname)

cmd = ['sysl', '--root', root, 'textpb', '-o', out_fname, model]
print 'calling', ' '.join(cmd)
call(cmd)
args = ['--root', root, 'textpb', '-o', out_fname, model]

if subprocess:
cmd = ['sysl'] + args
print 'subprocess call: ', ' '.join(cmd)
call(cmd)
else:
print 'python function call: main([{}])'.format(', '.join(args))
main(args)

expected_fname = path.join(e2e_dir, 'expected_output', fname + '.txt')
assert filesAreIdentical(expected_fname, out_fname)