def test_genomehash_update_from_dict(self): # """Test addition to a `GenomeHash` from a dictionary without loss of features # # 1. Add features to an empty dictionary # # 2. Add features to a non-empty dictionary # """ tuple_sort = lambda x: _name_sort(x[1]) gh = GenomeHash({},do_copy=True) tx_items = sorted(list(self.tx_dict.items()),key=tuple_sort) tx_values = [X[1] for X in tx_items] dict1 = dict(tx_items[:50]) dict2 = dict(tx_items[50:]) self.assertEqual(len(dict1),50) self.assertEqual(len(dict2),50) # check values, as opposed to items, because keys of feature_dict # are unique numerical IDs as opposed to ames gh.update(dict1) self.assertEquals(sorted(list(gh.feature_dict.values()),key=_name_sort), tx_values[:50], "Features lost in first update of empty GenomeHash from dict") gh.update(dict2) self.assertEquals(sorted(list(gh.feature_dict.values()),key=_name_sort), tx_values, "Features lost in second update of non-empty GenomeHash from dict")
def test_genomehash_update_from_list(self): # """Test addition to a `GenomeHash` from a list without loss of features # # 1. Add features to an empty dictionary # # 2. Add features to a non-empty dictionary # """ gh = GenomeHash({},do_copy=True) tx_list = sorted(list(self.tx_dict.values()),key=_name_sort) self.assertGreater(len(tx_list),0) gh.update(tx_list[:50]) self.assertEquals(sorted(list(gh.feature_dict.values()),key=_name_sort), tx_list[:50], "Features lost in update of empty GenomeHash from list") gh.update(tx_list[50:]) self.assertEquals(sorted(list(gh.feature_dict.values()),key=_name_sort), tx_list, "Features lost in update of non-empty GenomeHash from list")