diff --git a/.gitignore b/.gitignore index 79304fa..a340a91 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.cache *.pyc *.pyo yaml2ncml.egg-info diff --git a/tests/test6.ncml b/tests/base_roms_test.ncml similarity index 100% rename from tests/test6.ncml rename to tests/base_roms_test.ncml diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..4c7588d --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,27 @@ +from __future__ import (absolute_import, division, print_function) + +import pytest +from docopt import DocoptExit +from docopt import docopt + +from yaml2ncml import yaml2ncml + +__doc__ = yaml2ncml.__doc__ + + +def test_noarg_call(): + with pytest.raises(DocoptExit): + yaml2ncml.main() + + +def test_mandatory_arg(): + fin = 'roms.yaml' + args = docopt(__doc__, [fin]) + assert args['INFILE'] == fin + + +def test_optional_arg(): + fin = 'test6.ncml' + fout = '--output=test6.ncml' + args = docopt(__doc__, [fin, fout]) + assert args['--output'] == fout.split('=')[1] diff --git a/tests/test_yaml2ncml.py b/tests/test_yaml2ncml.py index 642543f..55587cc 100644 --- a/tests/test_yaml2ncml.py +++ b/tests/test_yaml2ncml.py @@ -1,49 +1,23 @@ from __future__ import (absolute_import, division, print_function) import subprocess +import tempfile -import pytest -from docopt import DocoptExit -from docopt import docopt -from yaml2ncml import yaml2ncml - -__doc__ = yaml2ncml.__doc__ - - -# CLI. -def test_noarg_call(): - with pytest.raises(DocoptExit): - yaml2ncml.main() - - -def test_mandatory_arg(): - fin = 'roms.yaml' - args = docopt(__doc__, [fin]) - assert args['INFILE'] == fin - - -def test_optional_arg(): - fin = 'test6.ncml' - fout = '--output=test6.ncml' - args = docopt(__doc__, [fin, fout]) - assert args['--output'] == fout.split('=')[1] - - -# ncml. def test_call(): output = subprocess.check_output(['yaml2ncml', 'roms.yaml']) - with open('test6.ncml') as f: + with open('base_roms_test.ncml') as f: expected = f.read() assert output.decode() == expected def test_save_file(): + outfile = tempfile.mktemp(suffix='.ncml') subprocess.call(['yaml2ncml', 'roms.yaml', - '--output=temp.ncml']) - with open('test6.ncml') as f: + '--output={}'.format(outfile)]) + with open('base_roms_test.ncml') as f: expected = f.read() - with open('temp.ncml') as f: + with open(outfile) as f: output = f.read() assert output == expected