Ejemplo n.º 1
0
    def add(self, entry):
        self.entries.append(entry)

        if entry["family"] not in self.families:
            self.families[entry["family"]] = {
                "family": entry["family"],
            }
            self.order.append(entry["family"])
        family = self.families[entry["family"]]

        for key, value in entry.items():
            if key in self.skip or not value:
                continue
            key = self.mapping.get(key, key)
            if key in self.keywords1:
                if family.get(key) and family[key] != value:
                    log.error(
                        "Duplicate value for %s => %r vs %r",
                        key, family[key], value
                    )
                    continue
                family[key] = value
            elif key in self.keywords2:
                if key not in family:
                    family[key] = []
                for value in make_list(value):
                    if value and value not in family[key]:
                        family[key].append(value)
            elif key in self.keywords3:
                if "key" not in family:
                    family["key"] = {}
                if key not in family["key"]:
                    family["key"][key] = []
                if value not in family["key"][key]:
                    family["key"][key].append(value)
            elif key not in family.get("extra", {}):
                if "extra" not in family:
                    family["extra"] = {}
                family["extra"][key] = [value]
            elif value not in family["extra"][key]:
                family["extra"][key].append(value)
Ejemplo n.º 2
0
    def add(self, entry):
        self.entries.append(entry)

        if entry["family"] not in self.families:
            self.families[entry["family"]] = {
                "family": entry["family"],
            }
            self.order.append(entry["family"])
        family = self.families[entry["family"]]

        for key, value in entry.items():
            if key in self.skip or not value:
                continue
            key = self.mapping.get(key, key)
            if key in self.keywords1:
                if family.get(key) and family[key] != value:
                    log.error(
                        "Duplicate value for %s => %r vs %r",
                        key, family[key], value
                    )
                    continue
                family[key] = value
            elif key in self.keywords2:
                if key not in family:
                    family[key] = []
                for value in make_list(value):
                    if value and value not in family[key]:
                        family[key].append(value)
            elif key in self.keywords3:
                if "key" not in family:
                    family["key"] = {}
                if key not in family["key"]:
                    family["key"][key] = []
                if value not in family["key"][key]:
                    family["key"][key].append(value)
            elif key not in family.get("extra", {}):
                if "extra" not in family:
                    family["extra"] = {}
                family["extra"][key] = [value]
            elif value not in family["extra"][key]:
                family["extra"][key].append(value)
Ejemplo n.º 3
0
def test_make_list():
    assert make_list("hello") == ["hello"]
    assert make_list(1) == [1]
    assert make_list((1, 2)) == [1, 2]
    assert make_list([3, 4]) == [3, 4]
Ejemplo n.º 4
0
def test_make_list():
    assert make_list("hello") == ["hello"]
    assert make_list(1) == [1]
    assert make_list((1, 2)) == [1, 2]
    assert make_list([3, 4]) == [3, 4]