def test_basic(self):
        iterable = [
            mock.Mock(key=12),
            mock.Mock(key=12),
            mock.Mock(key="red"),
            mock.Mock(key="blue"),
        ]

        expected_dict = {
            12: [iterable[0], iterable[1]],
            "red": [iterable[2]],
            "blue": [iterable[3]],
        }

        assert helpers.from_keyed_iterable(iterable, "key") == expected_dict
Esempio n. 2
0
    def test_basic(self):
        iterable = [
            mock.Mock(key=12),
            mock.Mock(key=12),
            mock.Mock(key="red"),
            mock.Mock(key="blue"),
        ]

        expected_dict = {
            12: [iterable[0], iterable[1]],
            "red": [iterable[2]],
            "blue": [iterable[3]],
        }

        assert helpers.from_keyed_iterable(iterable, "key") == expected_dict
Esempio n. 3
0
    def test_filter_func(self):
        iterable = [
            mock.Mock(key=12, keep=False),
            mock.Mock(key=12, keep=True),
            mock.Mock(key="red", keep=False),
            mock.Mock(key="blue", keep=True),
        ]

        filter_func = lambda e: e.keep

        expected_dict = {
            12: [iterable[1]],
            "blue": [iterable[3]],
        }

        assert helpers.from_keyed_iterable(iterable, "key", filter_func) == expected_dict
    def test_filter_func(self):
        iterable = [
            mock.Mock(key=12, keep=False),
            mock.Mock(key=12, keep=True),
            mock.Mock(key="red", keep=False),
            mock.Mock(key="blue", keep=True),
        ]

        filter_func = lambda e: e.keep

        expected_dict = {
            12: [iterable[1]],
            "blue": [iterable[3]],
        }

        assert helpers.from_keyed_iterable(iterable, "key",
                                           filter_func) == expected_dict