def test_decorating_adder_inactive(self): """ _decorating_adder() doesn't do anything when decorating not specified """ parser = MagicMock() parser.add_argument = MagicMock() args = [] arg_lib._decorating_adder(parser, *args) self.assertFalse(parser.add_argument.called)
def test_decorating_adder_active(self): """ _decorating_adder() adds proper arguments """ # set up mock parser parser = MagicMock() group = MagicMock() group.add_argument = MagicMock() parser.add_argument_group = MagicMock(return_value=group) # create a list of expected call signatures calls = [] context_list = [t for t in config_lib.CONFIG_OPTS if t[0] == 'plot_context'][0][1] theme_list = [t for t in config_lib.CONFIG_OPTS if t[0] == 'plot_theme'][0][1] palette_list = [t for t in config_lib.CONFIG_OPTS if t[0] == 'plot_palette'][0][1] msg = "Set the x-limits for the plot" calls.append(call('--xlim', nargs=2, type=float, dest='xlim', metavar=('XMIN', 'XMAX'), help=msg)) msg = "Set the y-limits for the plot" calls.append(call('--ylim', nargs=2, type=float, dest='ylim', metavar=('YMIN', 'YMAX'), help=msg)) msg = "Draw x axis with log scale" calls.append(call( '--xlog', action='store_true', dest='xlog', default=False, help=msg )) msg = "Draw y axis with log scale" calls.append(call( '--ylog', action='store_true', dest='ylog', default=False, help=msg )) msg = "Set the x-label for the plot" calls.append(call('--xlabel', nargs=1, type=str, dest='xlabel', help=msg)) msg = "Set the y-label for the plot" calls.append(call('--ylabel', nargs=1, type=str, dest='ylabel', help=msg)) msg = "Set the title for the plot" calls.append(call('--title', nargs=1, type=str, dest='title', help=msg)) msg = "Specify legend location" calls.append(call('--legend', nargs=1, type=str, dest='legend', choices=['1', '2', '3', '4', 'best'], help=msg)) msg = "Specify whether hide the grid or not" calls.append(call('--nogrid', action='store_true', dest='no_grid', default=False, help=msg)) msg = "Specify plot context. Default = '{}' ".format(context_list[0]) calls.append(call('--context', nargs=1, type=str, dest='plot_context', default=[context_list[0]], choices=context_list, help=msg)) msg = "Specify plot theme. Default = '{}' ".format(theme_list[0]) calls.append(call('--theme', nargs=1, type=str, dest='plot_theme', default=[theme_list[0]], choices=theme_list, help=msg)) msg = "Specify plot palette. Default = '{}' ".format(palette_list[0]) calls.append(call('--palette', nargs=1, type=str, dest='plot_palette', default=[palette_list[0]], choices=palette_list, help=msg)) msg = "Save the figure to this file" calls.append(call('--savefig', nargs=1, type=str, help=msg)) # run the code under test args = ['decorating'] arg_lib._decorating_adder(parser, *args) # make sure proper calls were made self.assertEqual(group.add_argument.call_args_list, calls)