Exemplo n.º 1
0
    def test_to_unique_item_list(self):
        self.assertListEqual([1, 2, 3],
                             common.to_unique_items_list([1, 1, 2, 2, 3]))
        self.assertListEqual(["a"], common.to_unique_items_list(["a"]))
        self.assertListEqual(["a", "b"],
                             common.to_unique_items_list(["a", "b", "a"]))
        self.assertListEqual(["a", "b"], common.to_unique_items_list("aba"))
        self.assertListEqual([], common.to_unique_items_list([]))

        def comparator_lower(first, second):
            return first.lower() == second.lower()

        self.assertListEqual(["a", "A"],
                             common.to_unique_items_list(["a", "A", "a"]))
        self.assertListEqual(["a"],
                             common.to_unique_items_list(["a", "A", "a"],
                                                         comparator_lower))
        self.assertListEqual(["a"],
                             common.to_unique_items_list(["a", "A", "a"],
                                                         comparator_lower))

        def comparator_str_int(first, second):
            return int(first) - int(second)

        self.assertListEqual(["1", "2"],
                             common.to_unique_items_list(["1", "2", "1", "2"],
                                                         comparator_str_int))
Exemplo n.º 2
0
 def get_all_metrics(self, *args, **kwargs):
     # Filter results to return only unique combinations of (Namespace, MetricName, Dimensions)
     # TODO: This is hugely inefficient (!), especially as the number of metric data is growing.
     #       Should be fixed upstream, or we should roll our own implementation!
     def comparator(i1, i2):
         i1 = (i1.namespace, i1.name, set((d.name, d.value) for d in i1.dimensions))
         i2 = (i2.namespace, i2.name, set((d.name, d.value) for d in i2.dimensions))
         return i1 == i2
     result = get_all_metrics_orig(self, *args, **kwargs)
     result = to_unique_items_list(result, comparator=comparator)
     return result
Exemplo n.º 3
0
    def test_to_unique_item_list(self):
        assert common.to_unique_items_list([1, 1, 2, 2, 3]) == [1, 2, 3]
        assert common.to_unique_items_list(["a"]) == ["a"]
        assert common.to_unique_items_list(["a", "b", "a"]) == ["a", "b"]
        assert common.to_unique_items_list("aba") == ["a", "b"]
        assert common.to_unique_items_list([]) == []

        def comparator_lower(first, second):
            return first.lower() == second.lower()

        assert common.to_unique_items_list(["a", "A", "a"]) == ["a", "A"]
        assert common.to_unique_items_list(["a", "A", "a"], comparator_lower) == ["a"]
        assert common.to_unique_items_list(["a", "A", "a"], comparator_lower) == ["a"]

        def comparator_str_int(first, second):
            return int(first) - int(second)

        assert common.to_unique_items_list(["1", "2", "1", "2"], comparator_str_int) == ["1", "2"]