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 read_parameter( para: Parameter, scanner: Scanner, files: Optional[Tuple[str, str, str]] = None ) -> Any: """Read value for a given template parameter declaration. Prompts the user to enter a value for the given parameter and returns the converted value that was entered by the user. Parameters ---------- para: flowserv.model.parameter.base.Parameter Workflow template parameter declaration scanner: flowserv.scanner.Scanner Input scanner. files: list, default=None List of tuples representing uploaded files. Each tuple has three elements: file_id, name, timestamp. Returns ------- bool or float or int or string or tuple(string, string) """ while True: if not para.is_file(): print(para.prompt(), end='') try: if para.is_bool(): return scanner.next_bool(default_value=para.default) elif para.is_file(): return read_file(para=para, scanner=scanner, files=files) elif para.is_float(): return scanner.next_float(default_value=para.default) elif para.is_int(): return scanner.next_int(default_value=para.default) return scanner.next_string(default_value=para.default) except ValueError as ex: print(ex)