def test_klusters_save(): """WARNING: this test should occur at the end of the module since it changes the mock data sets.""" # Open the mock data. dir = TEST_FOLDER xmlfile = os.path.join(dir, 'test.xml') l = KlustersLoader(filename=xmlfile) clusters = l.get_clusters() cluster_colors = l.get_cluster_colors() cluster_groups = l.get_cluster_groups() group_colors = l.get_group_colors() group_names = l.get_group_names() # Set clusters. indices = get_indices(clusters) l.set_cluster(indices[::2], 2) l.set_cluster(indices[1::2], 3) # Set cluster info. cluster_indices = l.get_clusters_unique() l.set_cluster_colors(cluster_indices[::2], 10) l.set_cluster_colors(cluster_indices[1::2], 20) l.set_cluster_groups(cluster_indices[::2], 1) l.set_cluster_groups(cluster_indices[1::2], 0) # Save. l.remove_empty_clusters() l.save() clusters = read_clusters(l.filename_aclu) cluster_info = read_cluster_info(l.filename_acluinfo) assert np.all(clusters[::2] == 2) assert np.all(clusters[1::2] == 3) assert np.array_equal(cluster_info.index, cluster_indices) assert np.all(cluster_info.values[::2, 0] == 10) assert np.all(cluster_info.values[1::2, 0] == 20) assert np.all(cluster_info.values[::2, 1] == 1) assert np.all(cluster_info.values[1::2, 1] == 0) l.close()
def test_klusters_save(): """WARNING: this test should occur at the end of the module since it changes the mock data sets.""" # Open the mock data. dir = TEST_FOLDER xmlfile = os.path.join(dir, 'test.xml') l = KlustersLoader(filename=xmlfile) clusters = l.get_clusters() cluster_colors = l.get_cluster_colors() cluster_groups = l.get_cluster_groups() group_colors = l.get_group_colors() group_names = l.get_group_names() # Set clusters. indices = get_indices(clusters) l.set_cluster(indices[::2], 2) l.set_cluster(indices[1::2], 3) # Set cluster info. cluster_indices = l.get_clusters_unique() l.set_cluster_colors(cluster_indices[::2], 10) l.set_cluster_colors(cluster_indices[1::2], 20) l.set_cluster_groups(cluster_indices[::2], 1) l.set_cluster_groups(cluster_indices[1::2], 0) # Save. l.remove_empty_clusters() l.save() clusters = read_clusters(l.filename_aclu) cluster_info = read_cluster_info(l.filename_acluinfo) assert np.all(clusters[::2] == 2) assert np.all(clusters[1::2] == 3) assert np.array_equal(cluster_info.index, cluster_indices) assert np.all(cluster_info.values[::2, 0] == 10) assert np.all(cluster_info.values[1::2, 0] == 20) assert np.all(cluster_info.values[::2, 1] == 1) assert np.all(cluster_info.values[1::2, 1] == 0) l.close()