def main(files=None): """Validate DPX files in paths given as arguments to the program. Informative details are written to standard output stream and errors are written to standard error stream.""" paths = None if files: paths = list(files) else: paths = sys.argv[1:] if not paths: raise MissingFiles('USAGE: dpxv FILENAME ...') for dpx_file in paths: valid = True for msg_type, msg in validate_file(dpx_file): if msg_type == MSG["info"]: print("File {}: {}".format(dpx_file, msg)) elif msg_type == MSG["error"]: valid = False print("File {}: {}".format(dpx_file, msg), file=sys.stderr) else: raise UndefinedMessage( "Undefined message type {}".format(msg_type)) if valid: print("File {} is valid".format(dpx_file))
def test_invalid_files(testfile): """Test that validation summary has info and errors.""" messages = {MSG["info"]: [], MSG["error"]: []} for msg_type, info in validate_file(testfile): assert msg_type in MSG.values() assert info messages[msg_type].append(info) assert len(messages[MSG["error"]]) > 0, testfile
def test_validate_truncated_file(testfile): """Truncated file stop validation of the file.""" validate = validate_file(testfile) msg_type, info = next(validate) assert msg_type == MSG["error"] assert info with pytest.raises(StopIteration): next(validate)
def test_valid_files(testfile): """Test that validation summary has info and errors.""" for msg_type, info in validate_file(testfile): assert msg_type == MSG["info"] assert info
def test_validate_file(testfile): """Test that validation summary has info and errors.""" for msg_type, info in validate_file(testfile): assert msg_type in MSG.values() assert info