Exemplo n.º 1
0
def test_read_bool():
    """Test reading Boolean values."""
    # Test reading True values.
    scanner = Scanner(reader=ListReader(tokens=['true', 'yes', 'y', 't', 1]))
    for i in range(5):
        assert scanner.next_bool()
    # Test reading False values.
    scanner = Scanner(reader=ListReader(tokens=['false', 'no', 'n', 'f', 0]))
    for i in range(5):
        assert not scanner.next_bool()
    # Test default value.
    scanner = Scanner(reader=ListReader(tokens=['', '']))
    assert scanner.next_bool(default_value=True)
    assert not scanner.next_bool(default_value=False)
Exemplo n.º 2
0
def test_read_file_parameter_with_uploads(tmpdir):
    """Test reading a file parameter with a given list of upload files."""
    parameters = [File(name='A', index=0, target='target1')]
    sc = Scanner(reader=ListReader(['f1']))
    arguments = cli.read(parameters, sc, files=[('f1', 'F', '123')])
    assert len(arguments) == 1
    assert arguments['A'] == serialize_fh('f1', target='target1')
Exemplo n.º 3
0
def test_read_file_parameters(tmpdir):
    """Test reading lists of file parameters."""
    parameters = [
        File(name='A', index=0, target='target1'),
        File(name='B', index=1, default='target2'),
        File(name='C', index=2),
    ]
    sc = Scanner(reader=ListReader([tmpdir, tmpdir, '', tmpdir, 'target3']))
    arguments = cli.read(parameters, sc)
    assert len(arguments) == 3
Exemplo n.º 4
0
def test_read_string_parameters():
    """Test reading lists of string parameters."""
    parameters = [
        String(name='A', index=0),
        String(name='B', index=1, default='ABC')
    ]
    sc = Scanner(reader=ListReader(['true', '']))
    arguments = cli.read(parameters, sc)
    assert len(arguments) == 2
    assert arguments['A'] == 'true'
    assert arguments['B'] == 'ABC'
Exemplo n.º 5
0
def test_read_boolean_parameters():
    """Test reading lists of boolean parameters."""
    parameters = [
        Bool(name='A', index=0),
        Bool(name='B', index=1, default=False),
        Bool(name='C', index=2, default=False),
    ]
    sc = Scanner(reader=ListReader(['true', 'xyz', '', 'True']))
    arguments = cli.read(parameters, sc)
    assert len(arguments) == 3
    assert arguments['A']
    assert not arguments['B']
    assert arguments['C']
Exemplo n.º 6
0
def test_read_numeric_parameters():
    """Test reading lists of numeric parameters."""
    parameters = [
        Int(name='A', index=0),
        Int(name='B', index=1, default=10),
        Float(name='C', index=2),
        Float(name='D', index=3, default=1.23)
    ]
    sc = Scanner(reader=ListReader(['1', 'xyz', '', 'True', '3.4', '']))
    arguments = cli.read(parameters, sc)
    assert len(arguments) == 4
    assert arguments['A'] == 1
    assert arguments['B'] == 10
    assert arguments['C'] == 3.4
    assert arguments['D'] == 1.23
Exemplo n.º 7
0
def test_read_string():
    """Test reading the next file token."""
    scanner = Scanner(reader=ListReader(tokens=['a', '']))
    assert scanner.next_string(default_value='b') == 'a'
    assert scanner.next_string(default_value='b') == 'b'
    assert scanner.next_string(default_value='b') == 'b'
Exemplo n.º 8
0
def test_read_file():
    """Test reading the next file token."""
    scanner = Scanner(reader=ListReader(tokens=['out.txt', '']))
    assert scanner.next_file(default_value='a.out') == 'out.txt'
    assert scanner.next_file(default_value='a.out') == 'a.out'