-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from ocefpaf/refactor_tests
Refactor tests
- Loading branch information
Showing
4 changed files
with
34 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.cache | ||
*.pyc | ||
*.pyo | ||
yaml2ncml.egg-info |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |