def parse_size(size):
    """Parse a size specification, i.e. an int with a K, M, G suffix.

    >>> parse_size("1000")
    1000
    >>> parse_size("100K")
    102400
    >>> parse_size("1M")
    1048576
    >>> parse_size("5 g")
    5368709120
    >>> parse_size("")
    Traceback (most recent call last):
    ...
    ValueError
    >>> parse_size("test M")
    Traceback (most recent call last):
    ...
    ValueError: test M
    """
    SUFFIXES = {'K': 1024, 'M': 1024 * 1024, 'G': 1024 * 1024 * 1024}
    if not size:
        raise ValueError(size)
    s = size.strip()
    suffix = s[-1]
    try:
        mult = SUFFIXES[suffix.upper()]
        s = s[:-1]
    except KeyError:
        mult = 1
    try:
        return int(s.strip()) * mult
    except ValueError:
        raise ValueError(size)
