Skip to content

Commit

Permalink
Merge pull request #30 from ocefpaf/refactor_tests
Browse files Browse the repository at this point in the history
Refactor tests
  • Loading branch information
rsignell-usgs authored Dec 15, 2016
2 parents 58537c2 + 2f39afa commit 4e8b3f4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.cache
*.pyc
*.pyo
yaml2ncml.egg-info
File renamed without changes.
27 changes: 27 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -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]
38 changes: 6 additions & 32 deletions tests/test_yaml2ncml.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4e8b3f4

Please sign in to comment.