Skip to content

Commit

Permalink
Make command line arguments more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
GDYendell committed Mar 21, 2017
1 parent 60f51ad commit d5802a0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 56 deletions.
56 changes: 28 additions & 28 deletions tests/app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,40 @@ class ParseArgsTest(unittest.TestCase):
return_value=MagicMock(empty=False, files=None))
def test_parser(self, parse_mock, add_mock, add_group_mock,
add_exclusive_group_mock):
group_mock = add_group_mock.return_value
empty_mock = MagicMock()
other_mock = MagicMock()
add_group_mock.side_effect = [None, None, empty_mock, other_mock]
exclusive_group_mock = add_exclusive_group_mock.return_value

args = app.parse_args()

add_mock.assert_has_calls(
[call("path", type=str,
help="Root folder to create VDS in. Also where source "
"files are searched for if --prefix given."),
call("-o", "--output", type=str, default=None, dest="output",
add_exclusive_group_mock.assert_called_with(required=True)
exclusive_group_mock.add_argument.assert_has_calls(
[call("-p", "--prefix", type=str, default=None, dest="prefix",
help="Prefix of files to search <path> for - e.g 'stripe_' "
"to combine 'stripe_1.hdf5' and 'stripe_2.hdf5'."),
call("-f", "--files", nargs="*", type=str, default=None,
dest="files",
help="Explicit names of raw files in <path>.")])

add_mock.assert_called_with(
"path", type=str, help="Root folder of source files and VDS.")

add_group_mock.assert_has_calls([call()] * 2)
empty_mock.add_argument.assert_has_calls(
[call("-e", "--empty", action="store_true", dest="empty",
help="Make empty VDS pointing to datasets "
"that don't exist yet."),
call("--shape", type=int, nargs="*", default=[1, 256, 2048],
dest="shape",
help="Shape of dataset - 'frames height width', where "
"frames is N dimensional."),
call("--data_type", type=str, default="uint16", dest="data_type",
help="Data type of raw datasets.")])
other_mock.add_argument.assert_has_calls(
[call("-o", "--output", type=str, default=None, dest="output",
help="Output file name. Default is input file prefix with "
"vds suffix."),
call("-e", "--empty", action="store_true", dest="empty",
help="Make empty VDS pointing to datasets "
"that don't exist, yet."),
call("-s", "--stripe_spacing", nargs="?", type=int, default=None,
dest="stripe_spacing",
help="Spacing between two stripes in a module."),
Expand All @@ -48,25 +67,6 @@ def test_parser(self, parse_mock, add_mock, add_group_mock,
dest="target_node",
help="Data node in VDS file.")])

add_group_mock.assert_called_with()
group_mock.add_argument.assert_has_calls(
[call("--shape", type=int, nargs="*", default=[1, 256, 2048],
dest="shape",
help="Shape of dataset - 'frames height width', where "
"frames is N dimensional."),
call("--data_type", type=str, default="uint16", dest="data_type",
help="Data type of raw datasets.")])

add_exclusive_group_mock.assert_called_with(required=True)
exclusive_group_mock.add_argument.assert_has_calls(
[call("-p", "--prefix", type=str, default=None, dest="prefix",
help="Prefix of files - e.g 'stripe_' to combine the images "
"'stripe_1.hdf5', 'stripe_2.hdf5' and 'stripe_3.hdf5' "
"located at <path>."),
call("-f", "--files", nargs="*", type=str, default=None,
dest="files",
help="Manually define files to combine.")])

parse_mock.assert_called_once_with()
self.assertEqual(parse_mock.return_value, args)

Expand Down
55 changes: 27 additions & 28 deletions vdsgen/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,49 @@
def parse_args():
"""Parse command line arguments."""
parser = ArgumentParser()
parser.add_argument("path", type=str,
help="Root folder to create VDS in. Also where source "
"files are searched for if --prefix given.")
parser.add_argument(
"path", type=str, help="Root folder of source files and VDS.")

# Definition of file names in <path> - Common prefix or explicit list
file_definition = parser.add_mutually_exclusive_group(required=True)
file_definition.add_argument(
"-p", "--prefix", type=str, default=None, dest="prefix",
help="Prefix of files - e.g 'stripe_' to combine the images "
"'stripe_1.hdf5', 'stripe_2.hdf5' and 'stripe_3.hdf5' located "
"at <path>.")
help="Prefix of files to search <path> for - e.g 'stripe_' to combine "
"'stripe_1.hdf5' and 'stripe_2.hdf5'.")
file_definition.add_argument(
"-f", "--files", nargs="*", type=str, default=None, dest="files",
help="Manually define files to combine.")
parser.add_argument(
"-o", "--output", type=str, default=None, dest="output",
help="Output file name. Default is input file prefix with vds suffix.")
help="Explicit names of raw files in <path>.")

# Arguments required to allow VDS to be created before raw files exist
parser.add_argument(
empty_vds = parser.add_argument_group()
empty_vds.add_argument(
"-e", "--empty", action="store_true", dest="empty",
help="Make empty VDS pointing to datasets that don't exist, yet.")
source_metadata = parser.add_argument_group()
source_metadata.add_argument(
help="Make empty VDS pointing to datasets that don't exist yet.")
empty_vds.add_argument(
"--shape", type=int, nargs="*", default=[1, 256, 2048], dest="shape",
help="Shape of dataset - 'frames height width', where frames is N "
"dimensional.")
source_metadata.add_argument(
empty_vds.add_argument(
"--data_type", type=str, default="uint16", dest="data_type",
help="Data type of raw datasets.")

# Arguments to override defaults
parser.add_argument("-s", "--stripe_spacing", nargs="?", type=int,
default=None, dest="stripe_spacing",
help="Spacing between two stripes in a module.")
parser.add_argument("-m", "--module_spacing", nargs="?", type=int,
default=None, dest="module_spacing",
help="Spacing between two modules.")
parser.add_argument("--source_node", nargs="?", type=str, default=None,
dest="source_node",
help="Data node in source HDF5 files.")
parser.add_argument("--target_node", nargs="?", type=str, default=None,
dest="target_node",
help="Data node in VDS file.")
# Arguments to override defaults - each is atomic
other_args = parser.add_argument_group()
other_args.add_argument(
"-o", "--output", type=str, default=None, dest="output",
help="Output file name. Default is input file prefix with vds suffix.")
other_args.add_argument(
"-s", "--stripe_spacing", nargs="?", type=int, default=None,
dest="stripe_spacing", help="Spacing between two stripes in a module.")
other_args.add_argument(
"-m", "--module_spacing", nargs="?", type=int, default=None,
dest="module_spacing", help="Spacing between two modules.")
other_args.add_argument(
"--source_node", nargs="?", type=str, default=None, dest="source_node",
help="Data node in source HDF5 files.")
other_args.add_argument(
"--target_node", nargs="?", type=str, default=None, dest="target_node",
help="Data node in VDS file.")

args = parser.parse_args()
args.shape = tuple(args.shape)
Expand Down

0 comments on commit d5802a0

Please sign in to comment.