Esempio n. 1
0
 def test_valid_false_strings(self):
     for x in [
             'f',
             'F',
             'False',
             'false',
             'fAlSe',
             '0',
             'no',
             'not',
             '',
     ]:
         assert bd.str2bool(x) is False
Esempio n. 2
0
 def test_none_is_false(self):
     assert not bd.str2bool(None)
Esempio n. 3
0
 def test_valid_true_strings(self):
     for x in ['t', 'T', 'True', 'true', '1', 'bonk', 'foo']:
         assert bd.str2bool(x) is True
Esempio n. 4
0
 def test_raises_typeerror_for_non_string_or_none(self):
     with pytest.raises(TypeError) as e:
         bd.str2bool(42)
         assert 'str2bool function' in str(e)
Esempio n. 5
0
def _get_opts(use_args=None):
    parser = argparse.ArgumentParser(description='Easily plot from csvs.')
    arg = parser.add_argument
    arg(
        '-f',
        '--file',
        required=True,
        nargs='+',
        help=
        'File followed by columns (names or indices). If no column, defaults to first one (0).',
        action='append',
    )

    # Plot arguments
    arg(
        '-t',
        '--title',
        nargs='+',
        help='Title(s) for (sub)plot',
        default=None,
        action=CustomAction,
    )
    arg(
        '-x',
        '--xlabel',
        nargs='+',
        help='x label(s).',
        default=None,
        action=CustomAction,
    )
    arg(
        '-y',
        '--ylabel',
        nargs='+',
        help='y label(s).',
        default=None,
        action=CustomAction,
    )
    arg(
        '--logx',
        type=bd.str2bool,
        help='Logarithmic x.',
        default=False,
        action=CustomAction,
    )
    arg(
        '--logy',
        type=bd.str2bool,
        help='Logarithmic y.',
        default=False,
        action=CustomAction,
    )
    arg(
        '--loglog',
        type=bd.str2bool,
        help='Use log scaling on both x and y axes.',
        default=False,
        action=CustomAction,
    )
    arg(
        '--kind',
        choices=[
            'line',
            'bar',
            'barh',
            'hist',
            'box',
            'kde',
            'density',
            'area',
            'pie',
            'scatter',
            'hexbin',
        ],
        default='line',
        action=CustomAction,
    )
    arg(
        '--subplots',
        type=bd.str2bool,
        help='Make separate subplots for each column.',
        default=False,
        action=CustomAction,
    )
    arg(
        '--layout',
        nargs=2,
        help='rows columns for the layout of subplots.',
        default=None,
        action=CustomAction,
    )
    arg(
        '--use_index',
        type=bd.str2bool,
        help='Use index as ticks for x axis.',
        default=False,
        action=CustomAction,
    )
    arg(
        '--sharex',
        type=bd.str2bool,
        help='In case subplots=True, share x axis.',
        default=False,
        action=CustomAction,
    )
    arg(
        '--sharey',
        type=bd.str2bool,
        help='In case subplots=True, share y axis.',
        default=False,
        action=CustomAction,
    )
    arg(
        '--figsize',
        nargs=2,
        help='Figure size (width and height) in inches.',
        default=None,
        action=CustomAction,
    )
    arg(
        '--grid',
        type=bd.str2bool,
        help='Axis grid lines.',
        default=None,
        action=CustomAction,
    )
    arg(
        '--legend',
        type=lambda x: x if x == 'reverse' else bd.str2bool(x),
        help='Place legend on axis subplots.',
        default=True,
        action=CustomAction,
    )
    arg(
        '--names',
        nargs='+',
        help='Names for each plotted series.',
        default=None,
        action=CustomAction,
    )
    arg(
        '--style',
        nargs='+',
        help='matplotlib line style per column.',
        action=CustomAction,
    )
    arg(
        '--rot',
        type=int,
        help='Rotation for ticks.',
        default=None,
        action=CustomAction,
    )
    arg(
        '--xlim',
        type=int,
        nargs=2,
        help='X axis limits.',
        default=None,
        action=CustomAction,
    )
    arg(
        '--ylim',
        type=int,
        nargs=2,
        help='Y axis limits.',
        default=None,
        action=CustomAction,
    )
    arg(
        '--fontsize',
        type=int,
        help='Font size for xticks and yticks.',
        default=None,
        action=CustomAction,
    )
    arg(
        '--colormap',
        help='Colormap to select colors from.',
        default=None,
        action=CustomAction,
    )
    arg(
        '--position',
        type=float,
        help='Specify relative alignments for bar plot layout. [0-1]',
        default=0.5,
        action=CustomAction,
    )
    arg(
        '--table',
        type=bd.str2bool,
        help='If True, draw a table.',
        default=False,
        action=CustomAction,
    )
    # Transformations
    arg(
        '-a',
        '-sa',
        '--sub_avg',
        nargs='+',
        type=int,
        help='Plot in averages',
        default=None,
        action=CustomAction,
    )
    arg(
        '-ma',
        '--mov_avg',
        nargs='+',
        type=int,
        help='Plot moving average',
        default=None,
        action=CustomAction,
    )
    arg(
        '-v',
        '-sv',
        '--sub_var',
        nargs='+',
        type=int,
        help='Plot in variances',
        default=None,
        action=CustomAction,
    )
    arg(
        '-mv',
        '--mov_var',
        nargs='+',
        type=int,
        help='Plot moving variances',
        default=None,
        action=CustomAction,
    )
    arg(
        '-sh',
        '--head',
        nargs='+',
        type=int,
        help='Select head',
        default=None,
        action=CustomAction,
    )
    arg(
        '-st',
        '--tail',
        nargs='+',
        type=int,
        help='Select tail',
        default=None,
        action=CustomAction,
    )
    arg(
        '-rh',
        '--rhead',
        nargs='+',
        type=int,
        help='Remove head',
        default=None,
        action=CustomAction,
    )
    arg(
        '-rt',
        '--rtail',
        nargs='+',
        type=int,
        help='Remove tail',
        default=None,
        action=CustomAction,
    )
    arg(
        '-lv',
        '--logarithm',
        type=bd.str2bool,
        help='Natural logarithm',
        default=None,
        action=CustomAction,
    )
    # Misc
    arg(
        '--display',
        type=bd.str2bool,
        help='Display plot.',
        default=True,
        action=CustomAction,
    )
    arg(
        '--header',
        type=bd.str2bool,
        help='CSV has header.',
        default=True,
        action=CustomAction,
    )
    arg(
        '--ignore_duplicates',
        type=bd.str2bool,
        help='Use only one of columns with the same name.',
        default=False,
        action=CustomAction,
    )
    arg(
        '-s',
        '--save',
        help='Filename to save figure (Only if --refresh is not set).',
        default='none',
        action=CustomAction,
    )
    arg(
        '-r',
        '--refresh',
        type=float,
        help='Time interval (ms) to refresh figure data from csv.',
        default=None,
        action=CustomAction,
    )

    if use_args is not None:
        opt = parser.parse_args(use_args)
    else:
        opt = parser.parse_args()

    return opt