def size(device="all", mode="free", host_os=detect_host_os()): """ Returns free and total swap size converted according to mode :param mode: one of free, total, used, pfree, pused :raises: WrongArgument if unsupported mode is supplied :depends on: [host_os.swap_size] """ validate_mode(mode, SIZE_CONVERSION_MODES) free, total = host_os.swap_size(device) return convert_size(free, total, mode)
def size(device='all', mode='free', host_os=detect_host_os()): """ Returns free and total swap size converted according to mode :param mode: one of free, total, used, pfree, pused :raises: WrongArgument if unsupported mode is supplied :depends on: [host_os.swap_size] """ validate_mode(mode, SIZE_CONVERSION_MODES) free, total = host_os.swap_size(device) return convert_size(free, total, mode)
def size(filesystem, mode="total", host_os=detect_host_os()): """ Returns free and total fs size converted according to mode :param filesystem: what filesystem to check :type filesystem: str :param mode: one of free, total, used, pfree, pused :raises: WrongArgument if unsupported mode is supplied :depends on: [host_os.fs_size] """ validate_mode(mode, SIZE_CONVERSION_MODES) free, total = host_os.fs_size(filesystem) return convert_size(free, total, mode)
def test_convert_size_returns_zero_if_total_size_is_zero(): assert_equal(0, convert_size(1, 0, SIZE_CONVERSION_MODES[0]))
def test_convert_size_returns_integers_or_floats(): free, total = 50, 100 for conversion_mode in SIZE_CONVERSION_MODES: converted_size = convert_size(free, total, conversion_mode) assert_is_instance(converted_size, (float, integer_types))