Ejemplo n.º 1
0
def test_parser_adding_choice_and_arg_with_choice():
    """Test adding a choice and an argument relying on the choice.

    """
    parser = ArgParser()
    parser.add_choice('workspaces', 'ecpy.measure.workspace', 'measure')
    parser.add_argument("-w",
                        "--workspace",
                        help='Select start-up workspace',
                        default='measure',
                        choices='workspaces')
    parser.add_choice('workspaces', 'ecpy.measure.dummy', 'measure')

    vals = parser.parse_args('-w measure'.split(' '))
    assert vals.workspace == 'ecpy.measure.workspace'

    vals = parser.parse_args('-w ecpy.measure.dummy'.split(' '))
    assert vals.workspace == 'ecpy.measure.dummy'
Ejemplo n.º 2
0
def test_parser_adding_choice_and_arg_with_choice():
    """Test adding a choice and an argument relying on the choice.

    """
    parser = ArgParser()
    parser.add_choice('workspaces', 'ecpy.measure.workspace', 'measure')
    parser.add_argument("-w", "--workspace",
                        help='Select start-up workspace',
                        default='measure', choices='workspaces')
    parser.add_choice('workspaces', 'ecpy.measure.dummy', 'measure')

    vals = parser.parse_args('-w measure'.split(' '))
    assert vals.workspace == 'ecpy.measure.workspace'

    vals = parser.parse_args('-w ecpy.measure.dummy'.split(' '))
    assert vals.workspace == 'ecpy.measure.dummy'
Ejemplo n.º 3
0
def test_parser_add_argument():
    """Test adding an argument to the parser.

    """
    parser = ArgParser()
    parser.add_argument("--nocapture",
                        help="Don't capture stdout/stderr",
                        action='store_true')
    vals = parser.parse_args('--nocapture'.split(' '))
    assert vals.nocapture

    with pytest.raises(ValueError):
        parser.add_argument('dummy')
Ejemplo n.º 4
0
def test_parser_add_argument():
    """Test adding an argument to the parser.

    """
    parser = ArgParser()
    parser.add_argument("--nocapture",
                        help="Don't capture stdout/stderr",
                        action='store_true')
    vals = parser.parse_args('--nocapture'.split(' '))
    assert vals.nocapture

    with pytest.raises(ValueError):
        parser.add_argument('dummy')