'Test for memory leaks in the C module'

@unittest.skipUnless((iswindows or islinux), u'Can    only    test    for    leaks    on    windows    and    linux')
def test_memory_leaks(self):

    self.check_setup()
    used_by_one = self.measure_memory_usage(1, self.dev.detect_managed_devices, self.scanner.devices, force_refresh=True)
    used_by_many = self.measure_memory_usage(100, self.dev.detect_managed_devices, self.scanner.devices, force_refresh=True)
    self.check_memory(used_by_one, used_by_many, u'Memory    consumption    during    device    scan')
    size = (1024 * 100)
    raw = io.BytesIO(('a' * size))
    raw.seek(0)
    name = u'zzz-test-file.txt'
    def send_file(storage, name, raw, size):
        raw.seek(0)
        pc = ProgressCallback()
        f = self.dev.put_file(storage, name, raw, size, callback=pc)
        self.cleanup.append(f)
        del pc
    used_once = self.measure_memory_usage(1, send_file, self.storage, name, raw, size)
    used_many = self.measure_memory_usage(20, send_file, self.storage, name, raw, size)
    self.check_memory(used_once, used_many, u'Memory    consumption    during    put_file:')
    def get_file(f):
        raw = io.BytesIO()
        pc = ProgressCallback()
        self.dev.get_mtp_file(f, raw, callback=pc)
        raw.truncate(0)
        del raw
        del pc
    f = self.storage.file_named(name)
    used_once = self.measure_memory_usage(1, get_file, f)
    used_many = self.measure_memory_usage(20, get_file, f)
    self.check_memory(used_once, used_many, u'Memory    consumption    during    get_file:')
    used_by_one = self.measure_memory_usage(1, self.dev.dev.get_filesystem, self.storage.object_id, (lambda x, l: True))
    used_by_many = self.measure_memory_usage(5, self.dev.dev.get_filesystem, self.storage.object_id, (lambda x, l: True))
    self.check_memory(used_by_one, used_by_many, u'Memory    consumption    during    get_filesystem')
