Skip to content

Commit

Permalink
fix test fail
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaehashi committed Oct 13, 2016
1 parent 54fc7c0 commit 4fe9b6c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
7 changes: 4 additions & 3 deletions jubakit/model.py
Expand Up @@ -450,10 +450,10 @@ def start(cls, args):
USAGE = '''
jubamodel [--in-format IN_FORMAT] [--out-format OUT_FORMAT]
[--output OUTPUT] [--output-config OUTPUT_CONFIG]
[--no-validate] [--fix-header] input_file
[--no-validate] [--fix-header] model_file
jubamodel --help'''

EPILOG = ' input_file model file in format specified by --in-format'
EPILOG = ' model_file input model file in format specified by --in-format'

# TODO: migrate to argparse (which must be added into dependency to support Python 2.6)
parser = _JubaModelOptionParser(add_help_option=False, usage=USAGE, epilog=EPILOG)
Expand Down Expand Up @@ -483,7 +483,7 @@ def print_usage():
print(' IN_FORMAT: auto | binary | json')
print(' OUT_FORMAT: text | binary | json')

(args, files) = parser.parse_args()
(args, files) = parser.parse_args(args)

# Failed to parse options.
if parser._error:
Expand Down Expand Up @@ -520,6 +520,7 @@ def print_usage():
no_validate=args.no_validate,
fix_header=args.fix_header,
)
success = True
except JubaModelError as e:
print(e)

Expand Down
19 changes: 13 additions & 6 deletions jubakit/test/test_model.py
Expand Up @@ -154,20 +154,27 @@ def test_convert_matrix(self):
self.assertEqual(v1, v2)

class JubaModelCommandTest(TestCase):
def _assert_exit(self, args, status):
self.assertEqual(_JubaModelCommand.start(args), status)
def _exit(self, args, status):
return _JubaModelCommand.start(args)

def test_help(self):
args = ['--help']
self._assert_exit(args, 2)
self.assertEqual(_JubaModelCommand.start(args), 0)

def test_valid_param(self):
with TempFile() as f:
f.write(_get_binary_file().read())
f.flush()
args = ['--in-format', 'binary', '--out-format', 'json', f.name]
self.assertEqual(_JubaModelCommand.start(args), 0)

def test_invalid_param(self):
with TempFile() as f:
args = ['--in-format', 'none', f.name]
self._assert_exit(args, 2)
self.assertNotEqual(_JubaModelCommand.start(args), 0)

args = ['--out-format', 'none', f.name]
self._assert_exit(args, 2)
self.assertNotEqual(_JubaModelCommand.start(args), 0)

args = ['--no-such-option']
self._assert_exit(args, 2)
self.assertNotEqual(_JubaModelCommand.start(args), 0)

0 comments on commit 4fe9b6c

Please sign in to comment.