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)
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')
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
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'
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']
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
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'
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'